Skip to content

fix(Dialog): a header that mounts with the opening commit takes focus only after the dialog is modal - #10408

Merged
cixzhang merged 4 commits into
mainfrom
fix/dialog-focus-after-modal
Nov 8, 2026
Merged

cixzhang merged 4 commits into
mainfrom
fix/dialog-focus-after-modal

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Refs #5637

User impact

A keyboard or screen-reader user opens a modal Dialog whose content, including a DialogHeader, renders only while the dialog is open (a common pattern: {isOpen ? <DialogHeader … /> : null}). Focus moved onto the header's title before the browser made the dialog modal, so for that moment focus sat in content the page behind it could still compete with. After this change, the title takes focus only once the dialog is modal, also when the header mounts in the render that opens the dialog.

  • Also changes: when no other control asks for focus, initial focus now starts on the title in every browser. Before, a header with a start control (a Back button), and any header in Firefox, started focus on the first control.
  • Not covered: a field with hasAutoFocus in the same conditional content still takes focus before the dialog is modal; that is the field's own request and is outside this change.

Problem and solution fit

  • Why does it fail? DialogHeader focused its title in its own mount effect. When the header mounts in the commit that opens the dialog, that child effect runs before Dialog's parent effect that calls showModal().
  • Why does it hurt? Focus enters the task before the modal boundary blocks the page, against the order the dialog promises.
  • Why does it matter? Dialog already applies initial focus after showModal(), preferring a descendant request and falling back to the title marked data-autofocus="dialog-title", but DialogHeader never set that marker. The title now carries it, and the header focuses itself only when its native dialog is already open (a header that mounts into an open dialog).

Expected behavior and authority

component:Dialog FR1: a native Dialog MUST become visibly modal before Dialog applies its component-owned initial-focus request. FR2: DialogHeader supplies its title as the default when no non-default eligible request is rendered. The modal-dialog contract expectation modal-dialog.focus.enters-after-modal for the conditional-content-focus-restoration state recorded this as a known failure.

Smallest restoration

  • DialogHeader.tsx: the title gets data-autofocus="dialog-title" (not on inline previews); the mount effect focuses the title only when the header's native dialog is already open, or when the header is not inside a native dialog.
  • Dialog.a11y.known-failures.ts: the enters-after-modal known failure is removed, so the real-browser contract now requires it.
  • No new public API, prop, default or visual change.

Evidence

  • Reproduction before the change: Dialog.test.tsx "focuses the title of a header that mounts with the opening commit only after the dialog is modal" records the order of showModal() and the title's focus; on the red commit the title is focused first, while the dialog is closed.
  • Result after the change: showModal() runs first and the title is then focused in the open dialog. The real-browser Dialog.a11y.chromium.spec.ts binding runs without the known failure.
  • Representative unchanged path: an explicit descendant request (a TextInput with hasAutoFocus) still wins over the title; focus still returns to the opener on close (fix(Dialog): capture the opener before descendant autofocus effects #6607's test passes); inline previews still take no focus.
  • Regression test or other mutation-sensitive proof: the red commit holds only the test and the known-failure removal.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split. The StrictMode opener gap in fix(Dialog): capture the opener only on the closed-to-open edge #5642 is separate and untouched.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • vitest for Dialog, AlertDialog, CommandPalette, Drawer, BottomSheet, Lightbox: 39 of 41 files pass in the parallel run; CommandPalette.test.tsx and AlertDialog.a11y.test.tsx time out under that load and pass on their own (41 of 41 tests).
  • tsc --noEmit for packages/core: clean. Strict lint on the changed files: clean.

…title's focus to the modal dialog

DialogHeader focused its title in its own mount effect. When the header mounted in the commit that opens the dialog, that effect ran before Dialog's showModal(), so focus entered the dialog before it was modal. The title now carries the dialog-title focus marker, which Dialog already focuses after showModal() when no other request is eligible, and the header focuses itself only when its native dialog is already open.
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 8, 2026 3:36am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 6, 2026
@cixzhang

cixzhang commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 8f4e78f

@astracat-bot

astracat-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 8, 2026, 3:48 AM UTC

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 9adae5f

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
richtext/RichTextEditorToolbar 249.3 kB (+42 B) · 454 B CSS (0) — — · — · —
DialogHeader 61.4 kB (+36 B) · 11.4 kB CSS (0) — ✓ · ✓ · ✓
lab/Comments 322.7 kB (+36 B) · 2.5 kB CSS (0) — — · — · —
2 more components
Component Size LoC Visual · A11y · RTL
lab/CommentThread 317.7 kB (+33 B) · 2.4 kB CSS (0) — — · — · —
Dialog 23.5 kB (0) · 6.7 kB CSS (0) — ✓ · ✓ · —

Package size: @astryxdesign/core 6.90 MB packed (+139 B); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 21 rows, core 25 rows; run pnpm api:report.

Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested. The fix works: a DialogHeader that mounts in the render that opens the Dialog now has its title focused only after the dialog is modal; only the release note needs to change.

  • The changeset and the description's user impact say focus "never reaches the dialog's content before the page behind it is blocked" and that the title is "still" the default target, but on this branch a hasAutoFocus field in the same conditional content still takes focus before the dialog is modal, and initial focus now moves to the title for headers with a start control (Chromium and Firefox) and for every header in Firefox, so please reword both to match (suggested wording is in the inline comment).

Non-blocking: the new comment above the header's mount Effect is one 35-word sentence (see the inline suggestion), and CI did not finish on this commit because the run stopped with "CI is full", so it needs a re-run after the update.

[Automated review]

@cixzhang

cixzhang commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 3c0a21e

@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 9adae5f

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI. A DialogHeader title now takes focus only after the Dialog is modal, also when the header mounts in the render that opens the dialog, and the release note now says what changes, including the title becoming the initial target for headers with a start control and in Firefox. Both points from the earlier review, the changeset wording and the Effect comment, are addressed. The test and docsite-test suites were deferred on this push and run before merge; this approval assumes they pass.

[Automated review]

@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 8, 2026
@cixzhang cixzhang closed this Nov 8, 2026
@cixzhang cixzhang reopened this Nov 8, 2026
@cixzhang
cixzhang merged commit e072916 into main Nov 8, 2026
128 of 131 checks passed
@github-actions
github-actions Bot deleted the fix/dialog-focus-after-modal branch November 9, 2026 06:03

This branch was successfully deployed

1 active deployment
Preview — 9adae5f7 Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant