Skip to content

[combobox][autocomplete] Add loopFocus prop - #3592

Merged
atomiks merged 8 commits into
mui:masterfrom
atomiks:fix/combobox-focus-loop
Dec 28, 2025
Merged

atomiks merged 8 commits into
mui:masterfrom
atomiks:fix/combobox-focus-loop

Conversation

@atomiks

@atomiks atomiks commented Dec 21, 2025 •

Copy link
Copy Markdown
Contributor

Closes #3456

Adds loopFocus prop (default: true) to Combobox + Autocomplete. The input is always included in the focus loop (per ARIA guidelines), but you can disable it optionally (and the input can't be / isn't part of the focus loop in that case).

NB: A data-highlighted state attribute (for when the input part has virtual focus) will be added in a separate PR

@atomiks atomiks added type: bug It doesn't behave as expected. component: combobox Changes related to the combobox component. labels Dec 21, 2025
@pkg-pr-new

pkg-pr-new Bot commented Dec 21, 2025 •

Copy link
Copy Markdown
  • vite-css-base-ui-example

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

commit: 15f151b

@mui-bot

mui-bot commented Dec 21, 2025 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+21B(+0.01%) 🔺+11B(+0.01%)

Details of bundle changes


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

@netlify

netlify Bot commented Dec 21, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 15f151b
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6950d4d55ffb410008149f22
😎 Deploy Preview https://deploy-preview-3592--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@atomiks
atomiks marked this pull request as ready for review December 21, 2025 22:24
@oliviertassinari

Copy link
Copy Markdown
Member

@atomiks
atomiks force-pushed the fix/combobox-focus-loop branch from 6468650 to ee09365 Compare December 22, 2025 09:45

@mnajdova mnajdova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After looking back into this, we decided not to this. The ARIA spec indicates:

Down Arrow: Moves focus to and selects the next option. If focus is on the last option, either returns focus to the combobox or does nothing.

We decided to add a loopFocus option to optionally not move the focus, and keep the behaviour where arrow down on the last element focused the combobox.

@atomiks
atomiks force-pushed the fix/combobox-focus-loop branch from 88c4531 to cf7dde2 Compare December 23, 2025 01:33
@atomiks
atomiks force-pushed the fix/combobox-focus-loop branch from cf7dde2 to 3bb4daa Compare December 23, 2025 01:34
@atomiks atomiks changed the title [combobox] Always remove input from focus loop [combobox][autocomplete] Add loopFocus prop and data-item-highlighted style attribute to Input Dec 23, 2025
@atomiks atomiks added type: new feature Expand the scope of the product to solve a new problem. component: autocomplete Changes related to the autocomplete component. and removed type: bug It doesn't behave as expected. labels Dec 23, 2025
@atomiks
atomiks force-pushed the fix/combobox-focus-loop branch from 3bb4daa to 04cd18a Compare December 23, 2025 01:40
loopFocus: true,
allowEscape: !autoHighlightMode,
loopFocus,
allowEscape: loopFocus,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why was this changed? How does escape gets effected whether the focus is looping or not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

allowEscape (poor term from Floating UI) means focus can escape the list (aka return to the input) but this requires loopFocus to be true - just a limitation of the implementation. I noticed we should keep the !autoHighlightMode check as well to avoid breaking previous behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keeping the previous behaviour makes sense 👌 . For some reason initially I thought this is related to the Escape key press, but now reading the code more carefully is related for allowing the focus to move outside of the list, maybe we should rename it to be more explicit, but we can do this outside of this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Btw, we were anyway throwing a warning here https://github.com/mui/base-ui/blob/master/packages/react/src/floating-ui-react/hooks/useListNavigation.ts#L283 if loopFocus was false, so this doesn't change the behaviour in any way 👌

@atomiks
atomiks force-pushed the fix/combobox-focus-loop branch from 6c0af7e to 59eb850 Compare December 24, 2025 08:19

@mnajdova mnajdova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good 👌

@atomiks atomiks changed the title [combobox][autocomplete] Add loopFocus prop and data-item-highlighted style attribute to Input [combobox][autocomplete] Add loopFocus prop Dec 28, 2025
@atomiks
atomiks force-pushed the fix/combobox-focus-loop branch from b2862c1 to b29e55e Compare December 28, 2025 06:54
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: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[combobox] Focus does not loop correctly — requires two Down Arrow presses for focus to wrap from last item to first

5 participants