Skip to content
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

Trap focus in AnchoredOverlay as soon as it opens #1222

Merged
merged 2 commits into from
May 12, 2021

Conversation

dgreif
Copy link
Member

@dgreif dgreif commented May 12, 2021

In the current implementation of AnchoredOverlay, the behavior for when to activate focus trapping is fairly complicated. If the user clicks or presses space/Enter to open the overlay, focus stays on the anchor. They can then use up/down arrow, enter, or tab to move focus into the overlay. If, however, they press up/down on the anchor initially, focus immediately moves into the overlay. In initial development, this felt like a good approach. However, real use has uncovered some corner cases which indicate the complex initial state might not be worth it. In particular, some new ActionMenus that also include a text input, as well as the SelectPanel, need focus to be trapped as soon as the overlay is opened. The easiest solution is to simply always move focus into the overlay, rather than conditionally starting focus on the anchor.

Closes #1210

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

@changeset-bot
Copy link

changeset-bot bot commented May 12, 2021

🦋 Changeset detected

Latest commit: 637495a

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

This PR includes changesets to release 1 package
Name Type
@primer/components 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

@vercel
Copy link

vercel bot commented May 12, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/primer/primer-components/95wfsuuBm2tQysPs3BPQdd8NqqFw
✅ Preview: https://primer-components-git-anchored-overlay-always-trap-primer.vercel.app

@vercel vercel bot temporarily deployed to Preview May 12, 2021 16:56 Inactive
@dgreif dgreif force-pushed the anchored-overlay-always-trap branch from a71315c to 637495a Compare May 12, 2021 16:58
Copy link
Contributor

@VanAnderson VanAnderson left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

🚀

@dgreif dgreif merged commit 4ab3d17 into main May 12, 2021
@dgreif dgreif deleted the anchored-overlay-always-trap branch May 12, 2021 18:25
@github-actions github-actions bot mentioned this pull request May 12, 2021
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.

Activate focus trap when clicking inside AnchoredOverlay
3 participants