-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
good first issueGreat for first contributions. Enable to learn the contribution process.Great for first contributions. Enable to learn the contribution process.scope: autocompleteChanges related to the autocomplete. This includes ComboBox.Changes related to the autocomplete. This includes ComboBox.type: bugIt doesn't behave as expected.It doesn't behave as expected.
Description
Current Behavior 😯
When filterSelectedOptions is enabled, selecting the last item means it disappears from the list, yet the highlight is not updated.
Expected Behavior 🤔
Not entirely sure, I can imagine one of the following:
- clear highlight (i.e. set highlighted index to
-1) - highlight the previous item (edge case: when the list has only 1 element, then the index should be set to
-1)
Steps to Reproduce 🕹
Steps:
- Open this demo (taken directly from the documentation).
- Select the last item and hit enter.
- Hit arrow down (to open the popup) and then hit enter again (the highlighted index is still the old end-of-list and thus the selected value is
undefined).
| Tech | Version |
|---|---|
| Material-UI | v4.9.2 |
Notes
One simple solution is to reset the highlighted index when a new value is selected and filterSelectedOptions is used. Adding the following code
if (filterSelectedOptions) {
setHighlightedIndex(-1);
}below this: https://github.com/mui-org/material-ui/blob/f567b384f509d36b7e10f691e6b58538e7db8869/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js#L453-L456
does the job, although as mentioned above, it's not necessarily the expected behavior.
Metadata
Metadata
Assignees
Labels
good first issueGreat for first contributions. Enable to learn the contribution process.Great for first contributions. Enable to learn the contribution process.scope: autocompleteChanges related to the autocomplete. This includes ComboBox.Changes related to the autocomplete. This includes ComboBox.type: bugIt doesn't behave as expected.It doesn't behave as expected.