Skip to content

Allow activation element in shadow DOM to be auto-focused after trap is deactivated #1485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025

Conversation

marioliu-block
Copy link
Contributor

Kind of related to #1072 / #1068

I noticed that support for shadow DOM focusing was added for custom elements within focus traps, but not for custom activation elements outside of focus traps.

This PR adds support for focusing on custom activation elements within the default deactivation behavior of the focus trap.

I tried writing Cypress tests for this change, but it doesn't seem to like custom elements and can't seem to focus on them.

PR Checklist

Please leave this checklist in your PR.

  • Issue being fixed is referenced.
  • Source changes maintain stated browser compatibility.
  • Web APIs introduced have deep browser coverage, including Safari (often very late to adopt new APIs).
  • Includes updated docs demo bundle if source/docs code was changed (run npm run demo-bundle in your branch and include the /docs/demo-bundle.js file that gets generated in your PR).
  • Unit test coverage added/updated.
  • E2E (i.e. demos) test coverage added/updated.
    • ⚠️ Non-covered demos (look for // TEST MANUALLY comments here) that can't be fully tested in Cypress have been manually verified.
  • Typings added/updated.
  • Changes do not break SSR:
    • Careful to test typeof document/window !== 'undefined' before using it in code that gets executed on load.
  • README updated (API changes, instructions, etc.).
  • Changes to dependencies explained.
  • Changeset added (run npm run changeset locally to add one, and follow the prompts).
    • EXCEPTION: A Changeset is not required if the change does not affect any of the source files that produce the package bundle. For example, demo changes, tooling changes, test updates, or a new dev-only dependency to run tests more efficiently should not have a Changeset since it will not affect package consumers.

Copy link

changeset-bot bot commented May 27, 2025

🦋 Changeset detected

Latest commit: 7530b41

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

This PR includes changesets to release 1 package
Name Type
focus-trap 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

Copy link
Member

@stefcameron stefcameron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marioliu-block Thank you for this great PR! You followed existing patterns really well which made reviewing it a breeze. 😄 I just have one tiny request if you don't mind, and then I'll happily merge this and get it published.

@stefcameron
Copy link
Member

@all-contributors add @marioliu-block for code, bug

Copy link
Contributor

@stefcameron

I've put up a pull request to add @marioliu-block! 🎉

@stefcameron
Copy link
Member

@marioliu-block Thank you for the update! Merging.

@stefcameron stefcameron merged commit d51ad78 into focus-trap:master May 27, 2025
3 checks passed
@stefcameron stefcameron mentioned this pull request May 27, 2025
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