Repository navigation
fix(Dialog): a header that mounts with the opening commit takes focus only after the dialog is modal - #10408
Conversation
…s only after the dialog is modal (red)
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
/approve-spec 8f4e78f |
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| 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
There was a problem hiding this comment.
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
hasAutoFocusfield 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]
|
/approve-spec 3c0a21e |
…ry browser; a shorter Effect comment
|
/approve-spec 9adae5f |
There was a problem hiding this comment.
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]
Refs #5637
User impact
A keyboard or screen-reader user opens a modal
Dialogwhose content, including aDialogHeader, 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.hasAutoFocusin 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
DialogHeaderfocused its title in its own mount effect. When the header mounts in the commit that opens the dialog, that child effect runs beforeDialog's parent effect that callsshowModal().Dialogalready applies initial focus aftershowModal(), preferring a descendant request and falling back to the title markeddata-autofocus="dialog-title", butDialogHeadernever 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:DialogFR1: 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 expectationmodal-dialog.focus.enters-after-modalfor theconditional-content-focus-restorationstate recorded this as a known failure.Smallest restoration
DialogHeader.tsx: the title getsdata-autofocus="dialog-title"(not on inline previews); the mount effect focuses the title only when the header's nativedialogis already open, or when the header is not inside a native dialog.Dialog.a11y.known-failures.ts: theenters-after-modalknown failure is removed, so the real-browser contract now requires it.Evidence
Dialog.test.tsx"focuses the title of a header that mounts with the opening commit only after the dialog is modal" records the order ofshowModal()and the title's focus; on the red commit the title is focused first, while the dialog is closed.showModal()runs first and the title is then focused in the open dialog. The real-browserDialog.a11y.chromium.spec.tsbinding runs without the known failure.TextInputwithhasAutoFocus) 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.Scope
Testing
vitestforDialog,AlertDialog,CommandPalette,Drawer,BottomSheet,Lightbox: 39 of 41 files pass in the parallel run;CommandPalette.test.tsxandAlertDialog.a11y.test.tsxtime out under that load and pass on their own (41 of 41 tests).tsc --noEmitforpackages/core: clean. Strict lint on the changed files: clean.