-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
AutocompleteInput resets input when useChoicesContext is called #9876
Comments
Thanks for submitting this report. There may be a bug in As a workaround, you can simply memoize the component: function AutocompleteLoading(props) {
// This call prevents the user from typing. If commented out
// you will be able to enter input.
const { isFetching } = useChoicesContext(props);
const memoizedAutocompleteInput = React.useMemo(
() => (
<AutocompleteInput
create={<CreatePost />}
matchSuggestion={(filterValue, suggestion) => {
const title = `${suggestion.title} - ${suggestion.id}`;
return title.includes(filterValue);
}}
optionText={<OptionRenderer />}
inputText={inputText}
// fullWidth
sx={{ minWidth: 380 }}
/>
),
[]
);
return (
<Stack direction="row">
{memoizedAutocompleteInput}
{isFetching ? <CircularProgress /> : null}
</Stack>
);
} Note: you should use Demo stackblitz: https://stackblitz.com/edit/github-guchrk-pdjjdp?file=src%2Fcomments%2FCommentEdit.tsx |
Thanks that worked |
It's actually not related to the call to This means the workaround should be to make those props values referentially stable, either by extracting them outside the component as in the stackblitz above or by applying classic react memoization. However, we should make it easier. |
What you were expecting:
useChoiceContext can be called in the scope of a ReferenceInput wrapped AutocompleteInput .
What happened instead:
When trying to use the useChoicesContext inside a nested AutocompleteInput calling useChoicesContext causes the input to reset when the user enters values.
Related code:
On the stackblitz link navigate to the comments app and select a comment to edit. On the first Post input try search a new value. The input will be cleared every time you finish typing.
On the second posts input the isLoading value has be set to true. However, no loading indicator or text is displayed.
https://stackblitz.com/edit/github-guchrk?file=src%2Fcomments%2FCommentEdit.tsx
Other information:
Our users have complained that the autocomplete (in this use case) does not indicate that it is loading. When trying to use a isLoading flag we noticed that we could no longer enter input when we got the isLoading from the useChoicesContext. Separately even if you put the isLoading flag set to
true
the spinning wheel that is on the SelectInput is not shown.Environment
The text was updated successfully, but these errors were encountered: