[combobox] Keep ArrowLeft/ArrowRight on the input caret in grid mode#4948
Draft
spokodev wants to merge 1 commit into
Draft
[combobox] Keep ArrowLeft/ArrowRight on the input caret in grid mode#4948spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
In grid mode the navigation hook treats ArrowLeft/ArrowRight as horizontal grid movement, even before any item is highlighted. When focus is in the input that hijacks the user's caret editing. Wrap the list-navigation reference so those keys fall through to the input's native handler while no item is highlighted. Once an item is highlighted (via ArrowDown, autoHighlight, or earlier grid navigation) the existing behavior is preserved. Fixes mui#4947
commit: |
Bundle size
PerformanceTotal duration: 1,161.42 ms -226.28 ms(-16.3%) | Renders: 50 (+0) | Paint: 1,769.75 ms -328.09 ms(-15.6%)
7 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
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 #4947.
In grid mode
useListNavigationis configured withcols: 2andorientation: 'horizontal', so it reacts to ArrowLeft/ArrowRight on the reference element. The reference element is the input. When the input has focus and no item is highlighted yet, the user is still editing the query, and the arrow keys silently jump the highlight into the list (typically looping into the last cell) instead of moving the caret.The fix wraps
listNavigation.referenceso ArrowLeft/ArrowRight short-circuit whileactiveIndex == null. Once an item is highlighted (via ArrowDown,autoHighlight, or earlier grid navigation) the wrapper hands the event back to the navigation hook and grid traversal continues unchanged.Tests
Added four cases under
prop: gridinComboboxRoot.test.tsx, two RED on master, two regression-preserve:moves the input caret on ArrowLeft when no item is highlighted in grid mode(RED on master)moves the input caret on ArrowRight when no item is highlighted in grid mode(RED on master)keeps horizontal grid navigation once an item is highlighted(was already passing; pins the boundary)keeps grid navigation when autoHighlight surfaces an item before typing arrow keys(was already passing; pins the autoHighlight path)Existing grid tests (
arrow keys navigate across rows and columns in grid mode,mirrors horizontal grid navigation in RTL mode,supports uneven rows navigation) still pass, along with the rest of the Combobox suite (678 tests) and the Autocomplete suite (65 tests).