Skip to content

feat(a11y): put the remaining ten dialogs on the focus contract - #710

Merged
EVWorth merged 1 commit into
mainfrom
fix/dialog-focus-contract-rest
Sep 17, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/dialog-focus-contract-rest

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Finishes wave 2. Closes #701 — all seventeen dialogs are now on the shared
Modal, so every dialog in the app traps focus, takes focus when it opens,
closes on Escape, returns focus to whatever opened it, and announces itself as
a modal dialog.

Before this work: 0 of 17 trapped focus, 1 took focus, 4 handled Escape, 0 had
role="dialog".

Why these ten were left for a second pass

They each had logic of their own.

Four had their own Escape handler on window or document. Those are
gone. Escape now arrives through the Modal, which works because the dialog
holds focus — the old listeners fired from anywhere on the page, including
while focus sat behind the dialog they were meant to close.

ApprovalDialog and ProposedEditDialog use Escape to reject, not to
dismiss, because an agent is blocked waiting on the answer. That routes through
onClose and keeps its meaning. Both also set closeOnBackdrop={false} — a
stray click shouldn't answer a question on the user's behalf, and the proposal
dialog holds a diff someone is in the middle of reading.

SaveFavoriteDialog bound Enter-to-save and Escape in one handler. Escape
went to the Modal; Enter stayed, because a favourite is one field and a button
and Enter saving it is worth keeping.

SQLPreviewDialog had a bespoke overlay-click check against a ref. Both it
and the ref are gone.

Three have no isOpen prop at all — SetVariableDialog, ApprovalDialog,
ProposedEditDialog are open when their subject is non-null, and an early
return already says so.

Test changes, and why they're not weakening

  • Tests that fired Escape at window/document now fire at the dialog. That
    is where a real keypress lands once the dialog has focus — which it didn't
    before, which was the bug.
  • Tests that clicked the backdrop now press it, matching the mousedown
    behaviour introduced with the Modal.

On doing this by hand

Worth recording: I tried a bulk transform twice. The first broke six files. The
second silently dropped the backdrop dimming on the two dialogs that used a
separate backdrop element — a purely visual regression that typechecking and
most of the test suite would have waved straight through. Both were caught, but
only by looking.

Verification

  • 2,928 unit tests, 340 browser tests, lint, dprint, tsc all pass
  • Confirmed by grep that no *Dialog.tsx remains off the Modal

🤖 Generated with Claude Code

All seventeen are now on the shared Modal, so every dialog in the app traps
focus, takes focus when it opens, closes on Escape, returns focus to whatever
opened it, and announces itself as a modal dialog.

These ten were the ones with logic of their own, which is why they were left
out of the first pass:

- Four had their own Escape handler on `window` or `document`. Those are gone;
  Escape now comes through the Modal, which works because the dialog holds
  focus — the old listeners fired from anywhere on the page, including while
  focus sat behind the dialog they were meant to close.
- `ApprovalDialog` and `ProposedEditDialog` use Escape to *reject*, not to
  dismiss, because an agent is blocked waiting on the answer. That routes
  through `onClose` and keeps its meaning. Both also set
  `closeOnBackdrop={false}`: a stray click should not answer a question on the
  user's behalf, and the proposal dialog holds a diff someone is reading.
- `SaveFavoriteDialog` bound Enter-to-save and Escape in one handler. Escape
  went to the Modal; Enter stayed, because a favourite is one field and a
  button and Enter saving it is worth keeping.
- `SQLPreviewDialog` had a bespoke overlay-click check against a ref. Both it
  and the ref are gone.
- `SetVariableDialog`, `ApprovalDialog` and `ProposedEditDialog` have no
  `isOpen` prop at all — they are open when their subject is non-null, and an
  early return already says so.

Tests that fired Escape at `window` or `document` now fire at the dialog,
which is where a real keypress lands once the dialog has focus. Tests that
clicked the backdrop now press it, matching the mousedown behaviour introduced
with the Modal.

Doing this by hand was the right call twice over: a bulk transform broke six
files in the first attempt, and a second one silently dropped the backdrop
dimming on the two dialogs that used a separate backdrop element. Both were
caught, but neither would have been by typechecking alone.

Closes #701.
@EVWorth
EVWorth merged commit 92dff89 into main Sep 17, 2026
12 checks passed
@EVWorth
EVWorth deleted the fix/dialog-focus-contract-rest branch September 17, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1][a11y] Dialogs don't trap focus, don't take focus when opened, and mostly ignore Escape

1 participant