Skip to content

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

Merged
atomiks merged 5 commits into
mui:masterfrom
spokodev:fix/autocomplete-input-grid-arrow-navigation
Jun 11, 2026
Merged

atomiks merged 5 commits into
mui:masterfrom
spokodev:fix/autocomplete-input-grid-arrow-navigation

Conversation

@spokodev

@spokodev spokodev commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4947.

Preview: https://deploy-preview-4948--base-ui.netlify.app/react/components/autocomplete#grid-layout

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 adds a guard props object to the input's mergeProps chain, placed right after listNavigation.reference: while activeIndex == null in grid mode, ArrowLeft/ArrowRight call event.preventBaseUIHandler() so the navigation handler is skipped and the input keeps its native caret behavior. Once an item is highlighted (via ArrowDown, autoHighlight, or earlier grid navigation) the event reaches the navigation hook as before and grid traversal continues unchanged. The guard reads store.state.activeIndex non-reactively at event time, so no extra reactive dependencies are introduced.

This matches the ARIA APG "Editable Combobox with Grid Popup" pattern: Left/Right operate on the caret while no suggestion is focused, and move between cells once one is.

Tests

Added three cases under prop: grid in ComboboxRoot.test.tsx, two RED on master, one 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 grid navigation when autoHighlight surfaces an item before typing arrow keys (pins the only path where an item becomes highlighted without arrow keys)

Horizontal navigation with a highlighted item is already covered by the existing arrow keys navigate across rows and columns in grid mode test. 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 and the Autocomplete suite.

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

pkg-pr-new Bot commented May 30, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4948
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4948
    

commit: bab0851

@code-infra-dashboard

code-infra-dashboard Bot commented May 30, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+122B(+0.03%) 🔺+38B(+0.03%)

Details of bundle changes

Performance

Total duration: 1,183.93 ms +56.78 ms(+5.0%) | Renders: 50 (+0) | Paint: 1,779.18 ms +75.63 ms(+4.4%)

Test Duration Renders
Checkbox mount (500 instances) 79.02 ms 🔺+18.76 ms(+31.1%) 1 (+0)

11 tests within noise — details


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

@netlify

netlify Bot commented May 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit bab0851
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a2a3f83bc661e00088a4bbd
😎 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.

@zannager zannager added the component: combobox Changes related to the combobox component. label Jun 1, 2026
Comment on lines +1099 to +1100
store.state.activeIndex == null &&
(event.key === 'ArrowLeft' || event.key === 'ArrowRight')

@atomiks atomiks Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches macOS' emoji picker, where ArrowLeft and ArrowRight do not work even if the text caret is at the end/boundary of the textbox (e.g. when it's empty). You need to press ArrowDown/ArrowUp. I guess that is fine.

@atomiks
atomiks marked this pull request as ready for review June 11, 2026 05:00
@atomiks
atomiks merged commit 1bce6e1 into mui:master Jun 11, 2026
6 checks passed
@atomiks atomiks added type: bug It doesn't behave as expected. component: autocomplete Changes related to the autocomplete component. labels Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: autocomplete Changes related to the autocomplete component. component: combobox Changes related to the combobox component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[autocomplete] AutocompleteInput cursor navigation when using grid layout

3 participants