base-ui
base-ui copied to clipboard
[Autocomplete] Fix type for multiple values to use readonly arrays
Steps to reproduce 🕹
The following should work
// values accepts const and value has correct type
useAutocomplete({
options: ['1', '2', '3'] as const,
multiple: true,
value: ['1', '3'] as const,
onChange(event, value) {
expectType<ReadonlyArray<'1' | '2' | '3'>, typeof value>(value);
},
});
Current behavior 😯
Typescript complains that the value is an immutable array.
Expected behavior 🤔
accept it.
Context 🔦
A fix was proposed in mui/material-ui#38253 and got merged, it got reverted in mui/material-ui#38253 because of mui/material-ui#38817.
The steps proposed by @mnajdova were to
- move the current useAutocomplete in Material UI
- iterate on the useAutocomplete in Base UI - test the changes in Joy UI
- in v6, migrate Material UI's Autocomplete to use the Base UI's useAutocomplete
Your environment 🌎
No response
@mnajdova I'm not sure what you mean by moving the "current" useAutocomplete in Material UI:
- is Material UI, the package in the folder
mui-material? - are you suggesting that we copy the current version of useAutocomplete to
mui-materialfor instance without exporting it and just using it the Autocomplete component?
Thanks for creating the issue @pcorpet. To give some clarification, at this moment Material UI uses the useAutocomplete from Base UI. If we want to make breaking changes to this hook at this point, we can't do it because a stable package depends on it. This is why I said that we should copy the current version to Material UI: /packages/mui-material/ and then we can safely iterate on the Base UI's version of the useAutocomplete. We can replace the useAutocomplete in Material UI in the next major, together with the other planned breaking changes.
@mnajdova is mui/material-ui#39738 what you had in mind for the first steps?