Skip to content

[combobox] Clear highlight on inline blur when inline - #3973

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/combobox-inline-blur-highlight
Feb 6, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/combobox-inline-blur-highlight

Conversation

@atomiks

@atomiks atomiks commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #3967

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

pkg-pr-new Bot commented Feb 4, 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@3973
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3973
    

commit: bdd073d

@mui-bot

mui-bot commented Feb 4, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+260B(+0.06%) 🔺+35B(+0.03%)

Details of bundle changes


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

@netlify

netlify Bot commented Feb 4, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit bdd073d
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6985ccf598f1d60008e9be03
😎 Deploy Preview https://deploy-preview-3973--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.

@sarthakmalik0810 sarthakmalik0810 left a comment

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.

@atomiks Thank you for the quick draft fix!

Do you think we could also store a lastActiveIndex, to restore highlight of the previously highlighted item before tabbing out of the Combobox?

I found this behavior to work in the ListBox component from react-aria-components.

@atomiks

atomiks commented Feb 5, 2026

Copy link
Copy Markdown
Contributor Author

Yeah I think that makes sense.

We were going to build a separate Listbox component at some point, but an inline combobox gets most of the way there already

@atomiks
atomiks force-pushed the codex/combobox-inline-blur-highlight branch from b88c844 to 2d18c58 Compare February 5, 2026 21:28
@atomiks
atomiks marked this pull request as ready for review February 5, 2026 21:31
@greptile-apps

greptile-apps Bot commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR fixes the highlight behavior in inline combobox mode when the input loses and regains focus. Previously, when a user highlighted an item using keyboard navigation and then moved focus away (e.g., to a "Done" button in a dialog), the highlight would be lost permanently. This change preserves the activeIndex when the input is blurred and restores it when focus returns.

The implementation:

  • Stores the last activeIndex in lastActiveIndexRef when blur occurs in inline mode
  • Sets a flag shouldRestoreActiveIndexRef to indicate restoration is needed
  • Clears the activeIndex on blur (removing visual highlight)
  • Restores the activeIndex on focus if the flag is set and the index is still valid
  • Guards against restoring indices for removed items using Object.hasOwn check on valuesRef

The test verifies this behavior works correctly in a dialog scenario where focus moves between the input and a button.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is focused and well-tested, using refs appropriately to track state across blur/focus cycles. The guard against restoring removed items prevents edge case bugs. The test coverage validates the expected behavior thoroughly.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/combobox/input/ComboboxInput.tsx Implements highlight restoration for inline combobox on focus/blur using refs to track activeIndex state
packages/react/src/combobox/root/ComboboxRoot.test.tsx Adds test case verifying highlight restoration behavior when input regains focus in inline mode

@atomiks
atomiks merged commit 6c6f376 into mui:master Feb 6, 2026
7 checks passed
@atomiks
atomiks deleted the codex/combobox-inline-blur-highlight branch February 6, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[combobox] data-highlighted from items should be removed when inline and focused out

4 participants