Skip to content

Activate focus trap when clicking inside AnchoredOverlay #1210

Closed
@dgreif

Description

@dgreif

Describe the bug
AnchoredOverlay currently only activates the internal focus trap if the user interacts with the anchor element in specific ways. New uses of the AnchoredOverlay include behaviors where a user can click inside the overlay multiple times, which removes focus from the anchor without activating the focus trap. In these scenarios, the user is able to tab to other parts of the DOM without restriction. We should handle this scenario and activate the focus trap if the anchor loses focus in some unexpected way.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://primer.style/components/DropdownMenu
  2. Open the menu in the example
  3. Click on the edge of the menu (small margin on left or right side, but not in an item)
  4. Note that focus has left the anchor button. You can now press Tab to focus on other parts of the page

Expected behavior
If focus leaves the anchor without the overlay closing, focus trap should activate immediately

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions