Skip to content

fix(webkit): restore focus to the popover trigger's focusable child - #882

Open
gabriel-lisboa-azion wants to merge 2 commits into
mainfrom
fix/popover-focus-restore
Open

fix(webkit): restore focus to the popover trigger's focusable child#882
gabriel-lisboa-azion wants to merge 2 commits into
mainfrom
fix/popover-focus-restore

Conversation

@gabriel-lisboa-azion

Copy link
Copy Markdown
Collaborator

The bug

focusTrigger() called .focus() on the passthrough <span> that wraps a Popover.Trigger. A bare <span> is not focusable, so the call was a no-op and focus fell to <body> every time a popover closed.

The cost is paid by keyboard users: after closing a popover, Tab restarts from the top of the document instead of continuing from the control that opened it.

The fix

Focus the wrapper when the wrapper itself is focusable, and its first focusable descendant otherwise. FOCUSABLE_SELECTOR is hoisted to module scope so the close path and getFocusable share one definition rather than keeping two that can drift.

Verification

packages/webkit/src/components/overlay/popover/popover.test.ts passes, along with the rest of the browser suite (93 files, 2036 tests). The behaviour is a real-browser one — document.activeElement after a close — which is exactly the class of thing jsdom returns a no-op for, so it is checked in Playwright Chromium.

focusTrigger() called .focus() on the passthrough <span> wrapper, which is
not focusable, so focus fell to <body> on every close. It now focuses the
wrapper when the wrapper itself is focusable and its first focusable
descendant otherwise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants