Skip to content

fix(react): focus the dialog on open instead of the hidden trigger - #546

Closed
DonOmalVindula wants to merge 1 commit into
asgardeo:mainfrom
DonOmalVindula:fix/dialog-initial-focus
Closed

fix(react): focus the dialog on open instead of the hidden trigger#546
DonOmalVindula wants to merge 1 commit into
asgardeo:mainfrom
DonOmalVindula:fix/dialog-initial-focus

Conversation

@DonOmalVindula

Copy link
Copy Markdown
Contributor

Purpose

Opening the profile popup from the user dropdown logged a browser accessibility error: "Blocked aria-hidden on an element because its descendant retained focus".

Cause

The dialog's FloatingFocusManager marks everything outside the dialog aria-hidden, but initialFocus={-1} left focus on the trigger button inside the now-hidden page header.

Change

Focus the dialog container itself when it opens (initialFocus={context.refs.floating} plus tabIndex={-1} on the content). The first input is still not auto-focused.

Testing

  • React unit tests pass.
  • Verified in the reporter's Next.js app: with the released 0.25.9 the focused element after opening the profile popup is the dropdown trigger outside the dialog; with this change it is the dialog content.

…n the hidden trigger

FloatingFocusManager marks everything outside an open dialog aria-hidden. With
initialFocus={-1} the focus stayed on the element that opened the dialog, e.g.
the user dropdown trigger in a page header, so a focused element was hidden
from assistive technology and Chrome logged "Blocked aria-hidden on an element
because its descendant retained focus" whenever the profile popup opened.

Focus the dialog container itself on open. This keeps the previous behaviour of
not auto-focusing the first input.
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 924deda4-dd24-4b77-8eff-66b86eea7363

📥 Commits

Reviewing files that changed from the base of the PR and between 9dda2c7 and 87e00ca.

📒 Files selected for processing (2)
  • .changeset/dialog-initial-focus.md
  • packages/react/src/components/primitives/Dialog/Dialog.tsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@asgardeo-github-bot

Copy link
Copy Markdown

🦋 Changeset detected

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

@DonOmalVindula

Copy link
Copy Markdown
Contributor Author

Folded into #545 so both fixes ship with a single changeset.

@DonOmalVindula
DonOmalVindula deleted the fix/dialog-initial-focus branch September 5, 2026 17:29
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.

2 participants