[autocomplete] Fix item removal when it receives focus from VoiceOver before using Backspace by silviuaavram · Pull Request #48572 · mui/material-ui (original) (raw)

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:

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