Skip to content

fix(FocusScope): keep focus on inputs in a nested open shadow root - #2223

Merged
huntabyte merged 1 commit into
mainfrom
fix/2203-focus-scope-shadow-root
Oct 20, 2026
Merged

huntabyte merged 1 commit into
mainfrom
fix/2203-focus-scope-shadow-root

Conversation

@huntabyte

Copy link
Copy Markdown
Owner

Summary

  • Fixes FocusScope (2.19.5): focus on an input inside an open shadow root is treated as escaping the trap #2203: focusing an element inside an open shadow root nested within a FocusScope (e.g. a web component's <input>) was treated as focus escaping the trap, so focus was pulled back out.
  • Adds retargetToScopeTree, which climbs shadow hosts so a node in a nested shadow root resolves to its host in the scope's tree before the container.contains check.
  • Uses it in the focusin handler and in the deferred open auto-focus check, so an onOpenAutoFocus that focuses a shadow input is no longer overridden.
  • Nodes from an unrelated tree resolve to null and are still treated as outside the scope.
  • Adds a patch changeset for bits-ui.

Testing

  • Added browser test: focus stays on an input inside an open shadow root within Dialog.Content, and typing reaches it.
  • Added browser test: onOpenAutoFocus focusing a shadow input isn't stolen by the deferred auto-focus frame.
  • Test runs: Not run.

- retarget focus targets to the scope's tree so shadow hosts resolve inside the container
- stop treating focus in a nested web component as escaping the trap
- add Dialog tests and a changeset
@changeset-bot

changeset-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c8bc7b1

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

This PR includes changesets to release 1 package
Name Type
bits-ui Patch

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

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview c8bc7b1

@huntabyte
huntabyte merged commit 17501f9 into main Oct 20, 2026
7 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026

This branch was successfully deployed

1 active deployment
Preview — c8bc7b1c Deployed Oct 20, 2026 by github-actions[bot]
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.

FocusScope (2.19.5): focus on an input inside an open shadow root is treated as escaping the trap

1 participant