[autocomplete] Improve highlight tracking and selection state#48219
Draft
mj12albert wants to merge 3 commits intomui:masterfrom
Draft
[autocomplete] Improve highlight tracking and selection state#48219mj12albert wants to merge 3 commits intomui:masterfrom
mj12albert wants to merge 3 commits intomui:masterfrom
Conversation
Netlify deploy previewhttps://deploy-preview-48219--material-ui.netlify.app/ Bundle size report
|
mj12albert
commented
Apr 7, 2026
Comment on lines
+978
to
+985
| if ( | ||
| highlightedIndexRef.current !== -1 && | ||
| popupOpen && | ||
| shouldSelectHighlighted && | ||
| // After a touch-scroll the highlight is stale (the user scrolled | ||
| // past it), so skip selection until the next deliberate interaction. | ||
| !touchScrolledRef.current | ||
| ) { |
Member
Author
5a474fe to
c4c814d
Compare
c4c814d to
587749d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20602
Fixes #27137
Fixes #46718
Adds
highlightReasonRefinternally to better handle edge cases created by the item highlight and other interactions.Codex suggests using pointer events as a better touch/mouse detection strategy to what is currently being used, which is more robust for hybrid devices (iPad with a bluetooth keyboard) but we could do that separately.
Manual testing steps:
1.
autoSelectshould not select mouse-hovered options on blur: #20602autoSelectvia the code editorExpected: No option selected — input stays empty
Current: The hovered option IS selected — its value appears in the input after blur
Variation with
autoHighlight:autoSelectandautoHighlightExpected: No option selected (the hover overrides the programmatic highlight reason)
Current: The first option is selected on blur, even though the user only hovered over it.
2.
freeSoloEnter should prefer typed text over auto-highlighted match #27137Expected: "The Godf" is accepted as free text, NOT "The Godfather"
Current (master): "The Godfather" is re-selected (the full original value), not "The Godf". The programmatic highlight from syncHighlightedIndex (which matches the old value) wins over the typed text.
3. Touch-scroll + Enter selects wrong item #46718
This requires a touch device + software keyboard
Expected: Popup closes with no option selected
Current (master): The option that was under the initial touch point (before scrolling) is selected. The stale highlight from touchstart is persisted through the scroll, and Enter commits it.