-
-
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] Passing slotProps
to the TextField
in renderInput
throws an error
#43573
Comments
slotProps
to the TextField
in renderInput
throws an errorslotProps
to the TextField
in renderInput
throws an error
@DiegoAndai do you think this issue should be added to Material-UI v6 issues board? |
@sai6855 I just added it to the v6 issues board. |
@ClementDreptin - I am definitely experiencing some odd behaviors since upgrading to v6. In general, I feel like what is being passed as However, I've had some luck by spreading the
|
for what its worth, this seems to fail on all TextField input adornment props. Autocomplete uses TextField so that's why there's an issue here. See the problem here - https://codesandbox.io/p/sandbox/broken-text-field-adornment-8zhlqc?file=%2Fsrc%2FApp.tsx%3A53%2C72&workspaceId=bdebcbbe-982a-40d5-9c2e-b543cf24c982 |
I had same problem with autocomplete throwing, and @mjkstudios solution worked. DatePickers also broke silently, and were also fixed by the same change, I think they also pass old |
Hey everyone, sorry for the late reply. About the bugIt's important to note that when overriding
So the issues should be fixed by correctly spreading About slots pattern consistencyI agree that "Autocomplete component needs to be updated to reflect the v6 changes with regards to slotProps", as mentioned above. This should be possible: <Autocomplete
disablePortal
options={options}
sx={{ width: 300 }}
renderInput={(params) => (
<TextField
{...params}
label="Correct override slotProps"
placeholder="Correct override slotProps"
slotProps={{
...params.slotProps,
input: {
...params.slotProps.input,
endAdornment: (
<>
<div>icon</div>
{params.slotProps?.input?.endAdornment}
</>
),
},
}}
/>
)}
/> Which is currently not the case. SummaryI don't think there's a bug besides the consistency issue. If you can confirm that the bug you're experiencing is fixed by spreading Please confirm if this fixes the issue, or correct me if I'm wrong or missed something in my demos. |
@DiegoAndai I confirm that spreading Thank you for pointing the missing spreads in the original examples, I don't know how we never ran into any issues in our app. |
Closing since it's not a bug and we already have an issue to standardize the slots API across components: #41281 |
Steps to reproduce
Link to live example: https://stackblitz.com/edit/react-1qmjam?file=Demo.tsx
Steps:
Autocomplete
to see the errorCurrent behavior
I found 2 strange behaviors
{ htmlInput: { ... } }
more padding is added and clicking in the input throws an error.{ input: { ... } }
theendAdornment
disappears and clicking in input doesn't open the list of options.Expected behavior
I expect to be able to use
slotProps.input
the same way I was usingInputProps
andslotProps.htmlInput
the same way I was usinginputProps
.Context
In our app we have an
Autocomplete
with a customendAdornment
. We are adding another adornment before the existing one to be exact. I was trying to migrate fromInputProps
andinputProps
toslotProps
since they became deprecated in MUI v6.Before migrating the code looked like this (which is still working in v6 but won't in v7):
After the migration the code looks like this:
Both adornments disappeared and the list of options isn't displaying on focus anymore.
Your environment
npx @mui/envinfo
Search keywords: Autocomplete slotProps
The text was updated successfully, but these errors were encountered: