Skip to content

[combobox] Keep ArrowLeft/ArrowRight on the input caret in grid mode#4948

Draft
spokodev wants to merge 1 commit into
mui:masterfrom
spokodev:fix/autocomplete-input-grid-arrow-navigation
Draft

[combobox] Keep ArrowLeft/ArrowRight on the input caret in grid mode#4948
spokodev wants to merge 1 commit into
mui:masterfrom
spokodev:fix/autocomplete-input-grid-arrow-navigation

Conversation

@spokodev
Copy link
Copy Markdown

Fixes #4947.

In grid mode useListNavigation is configured with cols: 2 and orientation: '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.reference so ArrowLeft/ArrowRight short-circuit while activeIndex == 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: grid in ComboboxRoot.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).

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
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 30, 2026

commit: 9792fe5

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented May 30, 2026

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+165B(+0.04%) 🔺+52B(+0.03%)

Details of bundle changes

Performance

Total duration: 1,161.42 ms -226.28 ms(-16.3%) | Renders: 50 (+0) | Paint: 1,769.75 ms -328.09 ms(-15.6%)

Test Duration Renders
Slider mount (300 instances) 154.67 ms ▼-40.99 ms(-20.9%) 3 (+0)
Select mount (200 instances) 128.96 ms ▼-34.31 ms(-21.0%) 3 (+0)
Menu open (500 items) 73.51 ms ▼-26.08 ms(-26.2%) 12 (+0)
Scroll Area mount (300 instances) 82.55 ms ▼-25.78 ms(-23.8%) 3 (+0)
Checkbox mount (500 instances) 70.57 ms ▼-21.11 ms(-23.0%) 1 (+0)

7 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 30, 2026

Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9792fe5
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a1a2f89a1d7a60008b4d054
😎 Deploy Preview https://deploy-preview-4948--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[autocomplete] AutocompleteInput cursor navigation when using grid layout

1 participant