-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[material-ui][Autocomplete] Fix ownerState is undefined in styleOverrides for Autocomplete #43994
Conversation
Netlify deploy previewhttps://deploy-preview-43994--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
@@ -682,7 +682,7 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) { | |||
let autocompletePopper = null; | |||
if (groupedOptions.length > 0) { | |||
autocompletePopper = renderAutocompletePopperChildren( | |||
<AutocompleteListbox as={ListboxSlot} {...listboxProps}> | |||
<AutocompleteListbox as={ListboxSlot} ownerState={ownerState} {...listboxProps}> |
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.
Reason for value of ownerState
is undefined in styleOverrides is, absence of ownerState
key in listBoxprops
useSlot
hook doesn't attach ownerState if elementType
is an html element , since elementType of ListBoxSlot is 'ul' not a React component (check here ), ownerState was missing in listBoxprops
.
if (elementType === undefined || isHostComponent(elementType)) { | |
return otherProps as AppendOwnerStateReturnType<ElementType, OtherProps, OwnerState>; | |
} | |
Attaching ownerState explicity seems to fix the issue
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.
The issue is a bit different here. We define the ListboxSlot
as slots, but then we don't use it as a slot, but rather as a value inside the as
prop. Slots by definition should replace the element that is rendered by default, not just used as an as
prop.
The better fix would be to use the AutocompleteListbox
on this line instead, at least based on the implementation.
@DiegoAndai we may want to revise the implementation of slots, we need to be consistent into what slots represents (they are replacement for the default parts of the component, they shouldn't behave as an alias to the as
/component
prop.
Yeah, that is another solution that may work. Let's hold off the merging tough, as the slots inconsistency implementation is what worries me the most. |
I agree with @mnajdova. This was an oversight in #41875. @sai6855's latest changes seem to follow this. However, this is a breaking change for the (deprecated)
(And remove it from What do you think, @mnajdova? I know this makes the |
Let's keep the deprecation and add a TODO comment to remember to change it in the next major (or just remove the prop if that's the case). |
@sai6855 let's implement what I described in this comment #43994 (comment) Let me know if you have any questions about it 😊 |
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.
Looks good, sorry for the delay. Let's merge this to fix the regression 👌
closes #43992
before: https://codesandbox.io/p/sandbox/silent-star-dfld6y?from-embed=&workspaceId=e3af0474-6cb1-4121-8a53-58b7b0668e3e
Not able to create sandbox from preview, please copy code from before sandbox and paste it this preview to see the effect.
https://deploy-preview-43994--material-ui.netlify.app/material-ui/react-autocomplete/#combo-box