LearnNewsExamplesConnect
Frontmatter
assigneesneo-opus-vega
createdAtNov 19, 2026, 3:11 AM
updatedAtNov 19, 2026, 4:37 AM
githubUrlhttps://github.com/neomjs/neo/issues/21415
authorneo-opus-vega
commentsCount0
parentIssue21367
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtNov 19, 2026, 4:37 AM

A closing dialog takes its modal mask along and returns focus to its opener

Closed v14.0.0/archive-v14-0-0-chunk-4 bugaicoreaccessibility
neo-opus-vega
neo-opus-vega commented on Nov 19, 2026, 3:11 AM

Parent: #21367 (Dialogs & Overlays: the dialog's defect is fixed before its card is renewed). Promotes defect-note ed66cef6.

Context

examples/dialog promises: "Hide it by pressing the ESCAPE key. The button will be refocused". It breaks that promise on every close path, and on its default path it leaves the page unusable. Measured on dev 267eb2336f (the dialog files last changed in ccf172411c), headless Chromium, a fresh page per run:

Path (Animated and Modal checked, the defaults) Focus after the close Modal mask Create Dialog
Click Create Dialog, Escape BODY stays, display: block enabled
Focus Create Dialog, Enter, Escape BODY stays enabled
Click Create Dialog, the header's close button BODY stays enabled
Animated unchecked: click, Escape BODY removed stays disabled

With no dialog left, the grey mask still covers the whole page and takes every click (the next mousedown lands on .neo-dialog-modal-mask) until a reload. Focus trace of the first row, from main-thread capture listeners: focusin #neo-button-1 on mousedown, focusout to BODY 24 ms later, focusin on the dialog's maximize action with relatedTarget: null, Escape, focusout to BODY.

The Problem

  1. The mask outlives the dialog. Every animated close ends in animateHide() → closeOrHide(false) → close(false) → destroy(true). closeOrHide() then awaits me.timeout(30) before it syncs the mask (src/dialog/Base.mjs:534-540). The dialog is destroyed by then, and core.Base#timeout rejects for a destroyed instance (since 07b6933fd0), so the sync never runs. The sync in unmount() (#20448) skips a destroyed dialog too (:896). A non-animated Escape only hides the dialog, and that path does sync: hence the fourth row.
  2. Focus has nothing to return to. revertFocus() and revertFocusOnDeparture() hand focus back only to focusEnterData.relatedTarget (src/component/Base.mjs:1950-1974). The example disables Create Dialog in its handler (examples/dialog/MainContainer.mjs:99); the browser blurs the disabled button, and the dialog takes focus from BODY with relatedTarget: null. A browser that does not focus a clicked button gets the same null without any disabling. Yet the dialog knows its opener: animateTargetId names the button it grows out of.
  3. Escape depends on the animation. onKeyDownEscape() writes hidden = true (:809). An animated hide ends in closeOrHide(false) (:424), so a closeAction: 'close' dialog is destroyed and fires close; a non-animated hide keeps it alive and fires nothing. The example re-enables its button on close, so with Animated unchecked, Escape leaves it disabled for good.

The Architectural Reality

Design authority:

  • "If we are hidden, or unmounted while we still contain focus, we have to revert focus to where it came from if possible" — component.Base#onFocusEnter (src/component/Base.mjs:1858).

  • "Otherwise, the mask needs to be below the next topmost modal dialog if possible, or hidden" — Neo.main.DomAccess#syncModalMask (src/main/DomAccess.mjs:1672).

  • "the close button, Escape and an animated hide all hide the dialog, where a stock dialog would destroy itself" — Neo.desktop.WindowManager (src/desktop/WindowManager.mjs:13).

  • The mask is one main-thread node. DomAccess#syncModalMask({id, modal}) puts it under id when that node is in the DOM, displayed and modal; else under the last .neo-modal in the DOM; else it removes the mask (:1664-1683). A departing dialog still in the DOM is that last .neo-modal, so a sync that arrives before the removal keeps the mask under it.

  • component.Abstract#destroy removes a body-rooted component with Neo.applyDeltas(windowId, {action: 'removeNode'}) (src/component/Abstract.mjs:369). As #18850 measured, removals and later calls do not land in a fixed order: the reason for the 30 ms.

  • DomAccess#focus with restoreFrom (:390) already waits for a departure and focuses only a lost focus.

  • The three engine dialogs (Neo.desktop.WindowManager's windows, Neo.board.CardEditor, Neo.timeline.EventEditor) use closeAction: 'hide'.

The Fix

  1. DomAccess#syncModalMask: a sync for an id that does not hold the mask (gone, hidden, or modal: false) leaves id out of the topmost-modal search, so the result no longer depends on whether its removal has landed.
  2. dialog.Base#close: sync the mask with modal: false before destroy(true). closeOrHide() loses its timer and its sync; close() and hide() each own theirs.
  3. A departing dialog.Base hands focus back to its opener: the component focus came from, else animateTarget, through the existing restoreFrom hand-back, so a focus the user has moved elsewhere stays.
  4. Escape runs closeOrHide(), the close button's path, so it honors closeAction with or without the animation.
  5. examples/dialog: Create Dialog stays enabled, since a disabled opener cannot take focus back. A click while its dialog is open does nothing.

Acceptance Criteria

  • Closing a modal dialog takes the mask along: after Escape or the close button, animated or not, the mask is gone, or sits under the next open modal dialog when there is one, and the page takes clicks again. A unit arm on DomAccess#syncModalMask skips a departing modal still in the DOM.
  • A departing dialog hands focus back to its opener (the component focus came from, else its animateTarget); a focus the user moved elsewhere meanwhile stays. Unit arms on dialog.Base.
  • Escape honors closeAction with and without the animation: a 'close' dialog fires close and is destroyed, a 'hide' dialog hides. Unit arm.
  • examples/dialog keeps its promise in all four rows of the Context table: focus is on Create Dialog after the close, the mask is gone, and Create Dialog opens a dialog again. A new e2e spec under test/playwright/e2e/dialog/.
  • The desktop windows, the board's card editor and the timeline's event editor behave as before (their e2e specs pass), and the whole unit suite is green.

Out of Scope

  • The dialog card's cover and the Dialogs & Overlays renewal: #21367's renewal leaf.
  • The popover's placement: its own leaf under #21367.
  • A menu that opens behind its dialog: #21066.

Avoided Traps

  • A longer timer in closeOrHide(): removal and call order is not fixed (#18850), so the sync must be right whichever lands first.
  • Re-enabling the opener from inside the engine before handing focus back: the opener's state is the app's. The example stops disabling it instead.
  • Focusing animateTarget unconditionally: a focus the user moved during the close must stay where it is.

Related

#21367 · defect-note ed66cef6 · #20448 (the hide path's mask sync) · #18850 (removal and call order) · 07b6933fd0 (a destroyed instance's timeout() rejects) · #21066.

Live latest-open + closed sweep: checked the latest 20 open plus open and closed search ("dialog mask", "dialog focus", "modal mask", "dialog Escape") at 2026-11-19T02:10Z; #4547, #4548 and #18850 read, none governs the close path's mask or the opener. 74 open, red band: folds under #21367. A2A in-flight sweep: latest 30 messages in all read-states, newest 02:07:15Z; no claim on the dialog or the popover. MC sweep: "dialog close Escape restores focus to the opening button", "modal mask stays on the page after the dialog closes": 10 results; the one prior decision is #20448's sync for the hide path. Own-assignment sweep: 7 open, none overlapping.

Retrieval Hint: "dialog close leaves the modal mask up and focus on body; closeOrHide timeout after destroy; opener animateTarget focus return"

tobiu referenced in commit 5a3cb4d - "feat(dialog): a closing dialog takes its modal mask along and hands focus back to its opener (#21415) (#21417) on Nov 19, 2026, 4:37 AM
tobiu closed this issue on Nov 19, 2026, 4:37 AM