Skip to content

Conversation

@taufiqelrahman
Copy link

@taufiqelrahman taufiqelrahman commented Dec 3, 2025

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 requestAnimationFrame wrapper 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

const inputRef = React.useRef<HTMLInputElement>(null)

React.useEffect(() => {
  if (props.autoFocus && inputRef.current) {
    requestAnimationFrame(() => {
      inputRef.current?.focus()
    })
  }
}, [props.autoFocus])

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.

@vercel
Copy link
Contributor

vercel bot commented Dec 3, 2025

@taufiqelrahman is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Combobox input doesn't autofocus inside a dropdown menu

1 participant