-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Autocomplete] can't change option highlight color #23297
Conversation
}, | ||
'&[data-focus="true"]': { | ||
|
||
'&$focused': { | ||
backgroundColor: theme.palette.action.hover, | ||
}, | ||
'&:active': { | ||
'&$selected': { | ||
backgroundColor: theme.palette.action.selected, | ||
'&$focused': { | ||
backgroundColor: alpha( | ||
theme.palette.action.selected, | ||
theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity, | ||
), | ||
}, | ||
}, | ||
'&[aria-disabled="true"]': { | ||
'&$disabled': { | ||
opacity: theme.palette.action.disabledOpacity, | ||
pointerEvents: 'none', | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure hover/select styling convention atm. This follows ListItem component's styling.
@@ -129,6 +129,7 @@ export default function useAutocomplete(props) { | |||
const [focusedTag, setFocusedTag] = React.useState(-1); | |||
const defaultHighlighted = autoHighlight ? 0 : -1; | |||
const highlightedIndexRef = React.useRef(defaultHighlighted); | |||
const [focusedIndex, setFocusedIndex] = React.useState(defaultHighlighted); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's too slow to rerender for this state. Try https://deploy-preview-23297--material-ui.netlify.app/components/autocomplete/#virtualization
const [focusedIndex, setFocusedIndex] = React.useState(defaultHighlighted); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we improve performance for large options using React.useMemo()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, virtualization is one case, we also need to consider when people use the render option API with "heavy" components, like the MenuItem
.
backgroundColor: theme.palette.action.selected, | ||
'&$focused': { | ||
backgroundColor: alpha( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! However, this change is related to #18136. I think that we should have a different pull request for it. It would deliver value, on its own :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliviertassinari I changed the above classes names to unique names optionFocused, optionSelected, optionDisabled
because official doc says focused is Pseudo-class applied to the root element if focused
. Thanks for your review. 🙇♀️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of #18136, I will send a different PR. 🍀
8679214
to
2d64982
Compare
2d64982
to
4228408
Compare
4228408
to
81aaa6f
Compare
c46f5a1
to
645d58d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I think that we could indeed add the .Mui-disabled
, .Mui-focused
class names even if we keep using the aria attributes for styling just for consistency. Regarding the original issue, I think that it was about replacing the data attribute with .Mui-focused
for consistency with the other component. I think that we should focus on this change, solve one problem at the time.
…nd delete data-focus attribute
5a13217
to
3bd5c6c
Compare
@sujinleeme Thanks for keeping iterating on it. However, I don't think that we can move in this direction. How about we try to get a step back with this plan:
What do you think? |
Thanks, @oliviertassinari. |
Fixed: #19692