fix(combobox): ensure CommandInput autofocus works inside DropdownMenu #8948
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
This PR fixes an issue where a Combobox rendered inside a DropdownMenu fails to autofocus its CommandInput.
The root cause is Radix's focus trapping behavior, which prevents the internal input from receiving focus during the opening transition.
What’s fixed
When autoFocus is enabled, the CommandInput now reliably receives focus even when nested inside a DropdownMenu.
How it works
Added a
requestAnimationFramewrapper around the focus call to delay it until after Radix has finished its focus-trap initialization.Focus is applied only when autoFocus is truthy.
Change
Actual behavior
CommandInput does not receive focus when Combobox is placed inside a DropdownMenu.
Expected behavior
CommandInput should automatically receive focus when autoFocus is enabled, regardless of DropdownMenu context.
Notes
No breaking changes.
Behavior outside DropdownMenu remains the same.