Repository navigation
Description
What happens
Dismissing a non-modal Radix menu by PRESSING outside it leaves document.activeElement on
<body>. Focus is not returned to the trigger, so a keyboard or screen-reader user who
dismisses a menu this way loses their place and the next Tab restarts from the top of the
document.
Escape is unaffected and returns focus to the trigger correctly. Only the outside-press path
is affected.
This is on main today, on the sidebar's overflow "More" menu, which is already
modal={false} and already carries MenuDismissGuard.
Measurement
Three production frontend builds on one backend, three engines, three repeats, 3/3 in every
cell and identical on chromium, firefox and webkit.
| menu | tree | focus after an outside press dismisses it |
|---|---|---|
| sidebar overflow "More" (already non-modal on main) | main |
BODY |
| a still-modal sidebar menu, for contrast | main |
trigger BUTTON |
focus_detached and focus_in_menu_subtree are both false: it is a clean drop to <body>,
not focus stranded on an unmounted node.
Mechanism
Sampling document.activeElement at every event of the gesture:
modal menu pointerdown -> menu content ... blur -> BODY ... click -> BODY
+50ms -> BODY then focusin -> BUTTON[trigger] <- Radix restores, late
non-modal pointerdown -> menu content ... focusin -> BUTTON{the pressed control}
+ guard click(capture) -> that control ... blur -> BODY
+1000ms -> BODY <- Radix never restores
Two things combine:
- The press focuses the control it lands on. Under a modal layer it cannot, because
pointer-events: nonesends the press toHTML. So with the layer gone, Radix sees focus
already outside the menu and declines to restore it to the trigger. releaseFocusTakenByTheSwallowedPressinmenu-dismiss.tsthen callsactive.blur()to
remove the pending Space activation on that control, and nothing puts focus back.
Suggested fix
Not to remove the blur. It is load-bearing: it is what stops a later Space from activating the
control the swallowed press focused. Redirect it instead, focusing the menu's trigger rather
than blurring to nothing. That removes the pending activation AND restores the recovery point,
and makes the non-modal path match the modal one.
The trigger reference would need capturing when the guard arms, while the menu is still open.
A comment that should be corrected with it
menu-dismiss.ts justifies blur-over-restore with "measured on the pre-PR shape,
document.activeElement stays BODY throughout" and "Body is where the modal shape left
focus anyway." The timeline above shows the observation was taken mid-gesture: under a modal
layer focus IS BODY through pointerdown, click and +50 ms, and then Radix's restore lands and
it ends on the trigger. The end state is the opposite of the premise, so the comment will
otherwise lead the next person to the same conclusion.
Relationship to #9229
#9229 takes three more sidebar menus off the modal layer and so extends this behaviour to them.
It does not introduce it: the control above is on main and untouched by that PR. Fixing it
here in the guard would correct all four menus at once.
Where this should land
Recommended home: #9051, not a standalone PR. #9051 owns src/lib/menu-dismiss.ts and
src/lib/menu-dismiss-guard.tsx (they exist only on its branch), and #9229 is stacked on it.
A third PR touching the same file would collide with both.
Checked at the time of writing rather than assumed: #9051 is open and still under review
(REVIEW_REQUIRED), so routing this into it does not disturb anything already converged.
If it has landed by the time someone picks this up, the fix belongs in a follow-up against
main that owns those two files, and #9229 needs no change either way.
Why it was not fixed in #9229
#9229 extends this behaviour to three more menus but does not introduce it, and it does not
own the file. Fixing it there would put a cross-PR edit into an already-stacked change and
would require re-validating dismiss_then_space_did_not_navigate (which the blur exists to
satisfy) on three engines. It is handled the same way as the guard's double-click
over-swallow: disclosed there, fixed in the guard.
What any fix must not break
dismiss_then_space_did_not_navigate, 3/3 on the guarded tree and 0/3 without the guard on
the two "Chat options" menus. That check is the reason active.blur() is there at all, so it
is the regression a focus-restoring fix is most likely to cause. Re-run it on chromium,
firefox and webkit.
Activity
yzxcj797 commentedon Aug 19, 2026
Confirmed the mechanism against the gesture timeline — the blur in
releaseFocusTakenByTheSwallowedPressis doing exactly what you describe (dropping the pending Space activation) and the restore never lands because Radix already saw focus leave the tree. Redirecting the blur to the trigger (captured when the guard arms) is the right shape: it keeps the activation guard and restores the recovery point in one move.One flag on placement:
menu-dismiss.ts/menu-dismiss-guard.tsxonly exist on #9051's branch (unslothai:perf-radix-modal), with #9229 stacked on it — a standalone PR against main would collide with both, as your "where this should land" section already concludes. So this needs to land on top of #9051 (or as a commit there). I can prepare the patch against that branch so it's ready to apply the moment #9051 merges — want me to?