-
-
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
[Autocomplete] - resetInput when value reference changes #35533
Comments
Could you please provide a codesandbox so we can reproduce the problem? |
Sure. on it |
So if I understand you correctly, your Autocomplete component resets its value, yes? Could you provide the steps I should take to reproduce the issue on the sandbox you provided? |
the It happens because the |
It seems like the input breaks when the
-export function Tags({initialIds}) {
- const [films, setFilms] = React.useState(top100Films.filter(film=>initialIds.includes(film.year)));
- ...
- value={map(ids, (id) => find(top100Films, { year: id }))}
- onChange={(e, next) => {
- setIds(map(next, (x) => x.year));
- }}
+ export default function Tags() {
+ const [ids, setIds] = React.useState([]);
+ ...
+ value={films}
+ onChange={(e, next) => {
+ setFilms(next);
+ }}
const [ids, setIds] = React.useState([]);
const cachedIds = React.useMemo(
()=>map(ids, (id) => find(top100Films, { year: id })),
[ids]
);
...
value={cachedIds}
onChange={(e, next) => {
setIds(map(next, (x) => x.year));
}} @michaldudak To fix this, the line referenced in the question should be changed to use shallowEquals or deepEquals. The easiest would probably be to add this requirement to the docs, optionally with a fix using |
Thanks for investigating the issue, @Zikoat. We will have this fixed when we refactor the useAutocomplete implementation to use Base UI building blocks, but we don't have an ETA for this. |
material-ui/packages/mui-base/src/AutocompleteUnstyled/useAutocomplete.js
Line 199 in 3f8c1a4
Sometimes the value is an array (When autocomplete is multiple), So if after render the value does not referentially the same, the autocomplete will fire reset event.
For example
The Bug/question is, shouldn't we check if the reference is the same for each item in case of multiple?
Thanks
The text was updated successfully, but these errors were encountered: