Repository navigation
Description
- Open this link to live example: https://stackblitz.com/edit/github-tqn73qz2?file=src%2FApp.tsx
- Focus the input and press ArrowDown twice to highlight "John Smith (id 9)".
- Wait for the next refetch (the options reorder every 3 s; the order is shown below the input). Same records, same length, different order.
- Press Enter.
Current behavior
After the refetch the row "John Smith (id 9)" still looks highlighted, but Enter selects "John Smith (id 7)". aria-activedescendant also points at id 7. The visible highlight, the announced option and the committed value disagree.
Related symptoms with the same cause:
- With
isOptionEqualToValuecomparing ids, a refetch that changes the highlighted option's label (for example "Apricot (3 in stock)" to "Apricot (2 in stock)") drops the highlight. - A same-length reorder keeps the highlight on the old index, which now holds a different option.
Expected behavior
When the user highlighted an option (keyboard, mouse or touch) and options change, the same option stays highlighted at its new index, and Enter selects that option. "Same option" would be decided by getOptionKey when provided, otherwise by isOptionEqualToValue (against getOptionValue(other) when getOptionValue is set), otherwise by label as today. If the option is gone, the existing reset applies, and highlights set by autoHighlight keep moving to the new first option (#46489).
Context
Async search and polling over records where display names repeat (people, patients, products) is common. Today getPreviousHighlightedOptionIndex in useAutocomplete.js matches the previously highlighted option by getOptionLabel (from #41306), and syncHighlightedIndex is memoised on filteredOptions.length, so a same-length update runs with stale options. With duplicate labels that makes Enter commit a different record than the one shown.
I have a fix ready (identity comparison through the existing getOptionKey / isOptionEqualToValue / getOptionValue handling, plus the JSDoc of those three props) and can open a PR if this direction sounds right.
Your environment
npx @mui/envinfo
System:
OS: macOS 26.7.1
Binaries:
Node: 24.22.1
npm: 11.19.1
Browsers:
Chrome: 149.0.7827.201
Firefox: 152.0.3
Safari: 27.0
npmPackages (live example):
@mui/material: 10.0.0-alpha.0 (next), StackBlitz template material-ui-vite-ts
Reproduced in: Brave (Chromium)
Search keywords:
Activity