fix(combobox): ensure CommandInput autofocus works inside DropdownMenu (#8942) #8949
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: #8942
Problem
When a Combobox is placed inside a DropdownMenu, the CommandInput does not autofocus when the submenu opens.
This forces users to manually click the input before typing, which breaks expected Combobox behavior.
The root cause is Radix’s focus trapping inside DropdownMenu, which blocks the input’s built-in autoFocus from running.
Solution
This PR updates all Combobox template variants so that the input reliably receives focus, even inside focus-trapped components such as DropdownMenu and Popover.
The fix uses a small, consistent pattern across templates:
Add a controlled open state
Create an inputRef
Attach ref={inputRef} to
Use useEffect to focus the input after the menu opens:
This ensures the input autofocuses correctly when:
Opening a Combobox inside a DropdownMenu submenu
Using a Combobox inside a Popover
Using the form-based Combobox example
Using either the Default or New York theme templates
Files Updated
ComboboxDropdownMenu (NY v4)
ComboboxForm (NY v4)
ComboboxDropdownMenu (default)
ComboboxForm (default)
Verification
Tested on:
macOS Chrome
macOS Safari
All variations now autofocus correctly, without breaking any existing behavior.