Skip to content

fix(core): focus the content when initialFocus can't take focus - #923

Open
shadcn wants to merge 2 commits into
mainfrom
shadcn/fix-initial-focus-fallback
Open

shadcn wants to merge 2 commits into
mainfrom
shadcn/fix-initial-focus-fallback

Conversation

@shadcn

@shadcn shadcn commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #922

When a popup's initialFocus resolved to something that can't take focus, like a disabled button or a plain paragraph, focus stayed on the trigger. For a modal Dialog or Drawer that leaves focus behind the backdrop. The docs already say focus falls back to the content.

After moving focus to the target, the popup now checks that focus landed in the target or the content. If it didn't, the content (which has tabindex="-1") takes it. A target outside the popup that does take focus is left alone.

Tests: initial-focus-fallback.test.ts covers a disabled button and a non-focusable element, for Dialog and Popover. All 4 fail on main. The core suite passes.

@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ui Ready Ready Preview, v0 Nov 19, 2026 11:59pm UTC

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.

Dialog: an initialFocus target that can't take focus leaves focus behind the dialog, because the open never checks that focus moved

1 participant