Repository navigation
focusTrap: the first-launch wizard holds keyboard focus; overlays tolerate a body pointer lock - #3855
Conversation
mstomar125
left a comment
There was a problem hiding this comment.
Review (initial) - #3855
Verdict: REQUEST CHANGES
Reviewed at head, against #3837. Ran bun x vitest run src/tests/actions/focus-trap.test.ts src/tests/components/onboarding-wizard.test.ts in a throwaway worktree: 20 passed. No real-browser run (as the PR itself says).
Summary
The keyboard-focus half (focusTrap reclaims focus from the journal editor) is a sound fix with one targeting problem. The pointer-events: auto half, which is what the issue's headline symptom depends on, most likely does not fix it, and the PR is marked Closes #3837 without a browser check.
Findings
-
Blocking
onboarding-wizard.svelte:675-677(and the same indelete-confirmation-modal.svelte:45-47,subtree-access-denied-modal.svelte:39-41):pointer-events: autodoes not change what the user hits in the reported scenario. The issue measuredelementFromPointat the wizard's Next =[data-slot=dialog-overlay]. That is a stacking result as well as an inheritance one: the wizard lives inside.theme-provider { position: relative; z-index: 0 }(its own stacking context) while the bits-ui overlay is portalled to<body>atz-50and covers the viewport. The PR body states the z-index/stacking difference is unchanged, so the overlay still paints above the wizard and still receives the click, which bits-ui treats as an outside click and dismisses the extension dialog.pointer-events: autoonly matters where nothing opaque is above the wizard. Either (a) verify in a real browser (the issue names the harness: wizard +ThemeProvider+ open bits-uiDialog; checkelementFromPointat Next and that one click advances) and, if it still fails, fix the stacking (e.g. portal the hand-rolled modals to<body>with a z-index above the dialog, or raise the theme provider), or (b) changeCloses #3837toRefs #3837and state plainly which symptoms remain. The tests only assert the CSS rule text (onboarding-wizard.test.ts"backdrop keeps pointer-events: auto"), so they prove nothing about the click.- Related, for completeness:
autoon a full-viewport backdrop does not expose content behind it (the backdrop itself is the hit target, and clicks on it just runonClose), so I see no click-through risk from the change itself. Where a bits-ui dialog is open and the wizard is on top, a click on the wizard counts as an outside click for bits-ui and dismisses the extension dialog; acceptable, but note it.
- Related, for completeness:
-
Non-blocking (should fix)
packages/desktop-app/src/lib/actions/focus-trap.ts:80: the reclaim target isfocusable()[0], which in the wizard is the Close button (first control in the DOM,onboarding-wizard.svelte:~391), not the step's primary action that the wizard's own effect anchors on (onboarding-wizard.svelte:373). In the real timeline (editor autofocus lands 0.3-2 s after mount) focus ends on Close, so a stray Enter/Space dismisses the first-launch wizard. Prefer returning focus to the last-focused element inside the trap (track it onfocusinwherenode.contains(target)), falling back to first focusable/node. -
Non-blocking (should fix)
focus-trap.ts:73-82andsrc/lib/extension-api/ui.ts:25:focusTrapis exported to extensions, and the newdocumentfocusinlistener now makes every trap contest focus. The only guard against two traps fighting is that the other element carriesaria-modal="true". Two traps on dialogs without that attribute (an extension's hand-rolled modal,role="alertdialog", etc.) will ping-pong: eachfocus()fires the other'sfocusinsynchronously, which can recurse until the stack overflows. All core callers do havearia-modal, and bits-ui's content sets it (bits-uidialog.svelte.js:206), andbase-node.svelte:973's date picker has it, so core-vs-core and core-vs-bits-ui are fine today. Add a re-entrancy guard (ignorefocusinwhile the trap is itself moving focus) and/or a module-level stack so only the topmost trap reclaims; document thearia-modalrequirement in the action's doc comment and the extension guide. -
Non-blocking
focus-trap.ts:78-80: focus moving into content portalled out of the dialog (a bits-ui select/popover/tooltip content inside a future wizard step, which usually is notaria-modal) would be pulled back and close the popover. No such control exists in the three current callers; worth a comment since the action is exported. -
Non-blocking cleanup: the listener is removed in
destroy()(verified, and tested by "stops reclaiming focus once destroyed").previouslyFocused?.focus?.()runs after removal, so no re-trigger. Good. -
Non-blocking a11y:
aria-modalexception correctly usesclosest()and excludes the trap's own subtree (!node.contains(otherModal)), so a trap whose own node isaria-modalis not mistaken for "another modal". Tab/Escape wiring is unchanged and now actually receives events. Good. -
Non-blocking (test) the new focus tests only cover a plain
textareastealing focus; add a case for focus going todocument.body/null target (no-op expected) and one for two traps to pin the loop behaviour above. -
Informational suggested fixes 2 and 3 from the issue (extension-api modal signal, docs note) are not done; fine as scoped, but then the issue should not auto-close.
Requirements (#3837)
- [~] Wizard holds keyboard focus / Escape works: addressed (see focus target comment).
- Wizard takes clicks beside an open extension dialog: not demonstrated, likely not fixed (blocking finding).
- Extension signal / docs: not in scope of this PR.
mstomar125
left a comment
There was a problem hiding this comment.
Review (re-review of 91af378 / 50a6ff3) - #3855
Verdict: APPROVE WITH NITS
Reviewed against #3837, covering the commits since the earlier REQUEST CHANGES. Ran bun x vitest run src/tests/actions/focus-trap.test.ts src/tests/components/onboarding-wizard.test.ts in a throwaway worktree: 25 passed (16 + 9). No real-browser run.
Earlier findings
- Blocking (
Closeswith an unproven pointer-events fix): resolved. The text isRefs #3837and "What it does not fix" states the extension-dialog click-lock (z-50 portal over the wizard's z-index 0 context) is still open. The comment in the three modals ("overlay inherits it and takes no click") is accurate only for the body-inherits case. Nothing more is needed. - Reclaim target was the Close button: resolved.
focus-trap.ts:82-109reclaims to the last-focused element inside the trap, else the container (giventabindex=-1), andfocus-trap.ts:117-120registers the listener after the initial focus move so that move is not remembered. The wizard test pins the primary action. - Two traps ping-pong: resolved. Module-level stack (
:35, push:119, splice:129-130) plus thereclaimingguard (:80,:92,:98-108). Destroy removes byindexOf, so out-of-order destruction is safe and the next-topmost trap becomes active. Nothing holds a node afterdestroy(), so no leak. All DOM access is inside the action, so SSR import is safe. - body/document focusin: resolved (
:90), tested.
New / remaining findings
- Non-blocking
focus-trap.ts:100-105: iflastFocusedInsideis still connected but now disabled or hidden (the wizard's Next/primary after a step change),.focus()is a silent no-op and the editor keeps focus; the container fallback is only reached when it is disconnected. After the call, checknode.contains(document.activeElement)and fall back to the container. - Non-blocking
focus-trap.ts:95-96: onlyaria-modal="true"content is exempt. Portalled non-modal content (bits-ui select/popover/menu, tooltips) opened from a future step would be pulled back and close. No current caller has one; add one sentence to the doc comment (:15-17) since the action is exported to extensions (extension-api/ui.ts). - Non-blocking
focus-trap.ts:103: settingtabindex=-1on the container mutates the DOM and can show a focus ring on the dialog on reclaim; confirm in a real browser. - Non-blocking (test) no case for destroying a lower trap while a higher one stays open, or for a disabled last-focused element. The stack code handles the first by inspection.
- Informational the
pointer-events: autochange (onboarding-wizard.svelte,delete-confirmation-modal.svelte,subtree-access-denied-modal.svelte) is only asserted as rule text and not shown to change a click in a browser. Fine underRefs.
No blocking issues.
…cusTrap reclaim focus The onboarding wizard, delete-confirmation and subtree-access-denied overlays set pointer-events: auto so an open bits-ui dialog's body pointer lock is not inherited. focusTrap now listens for focusin and returns focus into the dialog when an outside element (the journal editor's autofocus) takes it, except when the target sits in another aria-modal element. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The focusin reclaim returned focus to the first focusable element (the wizard's Close button). It now returns to the element that last held focus inside the dialog, or the dialog container, ignores document/body targets, and only the topmost open trap reclaims. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…efuses focus Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1836398 to
a5b8b9a
Compare
What this fixes
The second finding of #3837: the first-launch wizard now holds keyboard focus. When another element (the daily-journal editor's autofocus) takes focus after the wizard opens,
focusTrapreturns it to the dialog, so Escape, Tab and typing no longer go to the journal behind the wizard. It also makes the hand-rolled modals (onboarding-wizard,delete-confirmation-modal,subtree-access-denied-modal) tolerate a bodypointer-events: noneby settingpointer-events: autoon their overlays.What it does not fix
<body>at z-50, above the wizard'sz-index: 0stacking context, so it still renders over the wizard and receives the click.pointer-events: autodoes not change that. The Sync extension ships a turn-taking workaround for this.focusTrap behaviour
tabindex="-1"if it has none). The initial focus move is not remembered, so a reclaim never defaults to the Close button.focusinondocument/bodyis ignored; a target inside anotheraria-modal="true"element is left alone.reclaimingflag guards re-entry, so two traps cannot ping-pong focus.Testing
vitestonsrc/tests/actions/focus-trap.test.ts, all ofsrc/tests/componentsandsrc/tests/extension-api: 1133 passed. New cases: reclaim target is the last-focused inner element and not the first control; container fallback; document/body targets; two nested traps do not loop; the trap beneath reclaims once the top one is destroyed; the wizard reclaims to its primary action, not Close. The overlaypointer-eventsrule is asserted on the rule text (jsdom does not apply component CSS).svelte-check: clean. Not verified in a real browser with an extension dialog open.Refs #3837
🤖 Generated with Claude Code