Nested popovers: keyboard order and two light-dismiss boundaries

Nested popovers: keyboard order and two light-dismiss boundaries

●1 ●39
calendar_today • schedule2 min read
— Originally published at chriseugenerodriguez.com

Reproduce the two click boundaries

Open the parent, then use More options to open its sibling child. First click Parent action: only the child closes. Reopen the child and click Background action: both close. The difference is the click target's relationship to the stack, not whether a panel looks modal.

Test the boundary, not an assumed focus trap

Nested popovers have two different light-dismiss boundaries: a click inside the parent closes the child; a click outside the entire stack closes both. Popovers remain non-modal. Use showPopover({ source }) for the invocation relationship, and test application-owned selection focus separately from native dismissal.

A small browser fixture

The panels are labeled groups of buttons, not a complete ARIA menu. The child is a DOM sibling opened from a source inside the parent. Tab enters the child after that source. Clicking an option explicitly restores source focus.

Save as main.mjs:

// Two sibling auto popovers. The source establishes their logical nesting.
export const fixture = `<!doctype html>
<html lang="en"><head><meta charset="utf-8"><title>Nested popover checks</title>
<style>
body { font: 16px system-ui; padding: 24px; }
[popover] { position: fixed; inset: 120px auto auto 40px; margin: 0; width: 220px; padding: 16px; border: 1px solid; background: white; color: black; }
#subMenu { left: 320px; }
[popover] button { display: block; margin: 8px 0; }
</style></head><body>
<button id="menuToggle" popovertarget="parentMenu">Open options</button>
<button id="afterControl">Background action</button>
<div id="parentMenu" popover="auto" role="group" aria-label="Options">
  <button id="openSubProg" aria-expanded="false" aria-controls="subMenu" aria-details="subMenu">More options</button>
  <button id="parentOption2">Parent action</button>
</div>
<div id="subMenu" popover="auto" role="group" aria-label="More options">
  <button id="subItem1">Choose first option</button>
  <button id="subItem2">Choose second option</button>
</div>
<script>
const trigger = document.getElementById('openSubProg');
const sub = document.getElementById('subMenu');
function openSub() { sub.showPopover({ source: trigger }); }
trigger.addEventListener('click', openSub);
trigger.addEventListener('keydown', event => {
  if (event.key === 'ArrowRight') { event.preventDefault(); openSub(); }
});
sub.addEventListener('toggle', () => {
  trigger.setAttribute('aria-expanded', String(sub.matches(':popover-open')));
});
for (const button of sub.querySelectorAll('button')) {
  button.addEventListener('click', () => {
    sub.hidePopover();
    // Selection is an application action: explicitly return to its source.
    trigger.focus();
  });
}
</script></body></html>`;

Run and interpret the checks

With Node 22, run npm init -y, npm install --save-dev playwright@1.63.0, and npx playwright install chromium. Save the article's main.test.mjs beside the fixture and run node --test main.test.mjs.

The seven cases cover keyboard order, both click boundaries, sequential Escape, selection focus, non-modal background focus, and parent closure. waitForFunction receives one serialized argument, not multiple positional selectors.

Do not infer a focus trap or universal Escape focus restoration from the source option. The selection handler owns its explicit focus move. There is no generic microtask workaround for arbitrary toggle reentrancy. These Chromium checks do not replace cross-browser or screen-reader testing.

Full test file and explanation: https://chriseugenerodriguez.com/blog/accessible-nested-popovers-showpopover-focus-light-dismiss

Regression checklist

Keep the parent-area click, outside-stack click, and Escape cases separate. Assert concrete focus targets after selection. Include a positive check that a background control can receive programmatic focus while the popovers are open. Do not use role=menu until the widget implements the associated menu keyboard behavior.

1 Comment

0 votes
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

What Should a Health Awareness Page Help a Reader Do Next?

WAQAS AHMAD - Nov 13

Should Exact Search Matches Always Come First?

WAQAS AHMAD - Oct 30

# One Config Key Was Enough: What the Meta Muse Zero-Day Teaches About Agent Trust Boundaries

alessandro_pignati - Nov 2

Can a Keyboard-Only User Finish Your App’s Main Task?

WAQAS AHMAD - Oct 19

Motivational Light: What Stage Lighting Teaches UX Designers

Alex - Jun 24
chevron_left
849 Points • 40 Badges
Santa Monica, CA • chriseugenerodriguez.com
32Posts
0Comments
7Connections
10 years fe

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!