[autocomplete] Fix item removal when it receives focus from VoiceOver before using Backspace by silviuaavram · Pull Request #48572 · mui/material-ui (original) (raw)
- I have followed (at least) the PR section of the contributing guide.
When focus on the selected items, in a multiple selection autocomplete, comes from a non native keyboard event, we are not updating the state with the focused item. In the issue case, the focus comes from VoiceOver navigation. Also, VoiceOver is sending another Backspace event on the input immediately after it sent one to the Chip.
Consequently, instead of deleting the one focused item, we were deleting 3 items: focused one (actually a Chip delete handler), and 2 from the end, one because focusedItem was -1 (not updating according to VoiceOver focus) and one because of the extra input backspace event.
Fixes:
- on item focus, sync the focusedItem state.
- when we delete a chip with backspace, keep the deletion information in ref, and when the second Backspace event on the
inputhappens, exit and restore the ref info. This is not ideal, but I can't figure anything better.
Added tests for the focusedItem sync only. The second case, related to VoiceOver sending another Backspace event on top of the Chip one, is impossible to unit test.
Fixes #44936