Repository navigation
fix(DialogHeader): a header that mounts in an open dialog does not take focus from a control inside it - #11204
nynexman4464 wants to merge 1 commit into
Conversation
…ke focus from a control inside it
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report
Generated by PR Enrichment workflow | View current CI run |
There was a problem hiding this comment.
Needs an engineering owner's decision before approval. No current Dialog clause covers a DialogHeader that mounts after its dialog opened (component:Dialog FR2 covers only the title's initial focus), so the new focus rule needs an owner to approve it.
- To settle: should a header that mounts in an open dialog take focus only when no element inside the dialog holds it? Under this rule a field being typed in keeps focus (the reported bug, confirmed fixed in Chromium), and a footer Next button that swaps a keyed header also keeps focus, so the new step title is no longer focused or announced as it is on
main. - Non-blocking: the new comment at
DialogHeader.tsxlines 195-197 is one 41-word sentence; the inline suggestion shortens it.
An engineering owner records the decision by commenting /approve-spec with this pull request's full head SHA (the author may do so as an engineering owner), or by adding the rule to the Dialog record. CI has not run on this draft head yet.
| // A header that mounts in a dialog already open (content that loads late, a | ||
| // step that swaps its header) takes focus only when nothing inside the | ||
| // dialog holds it yet: it never takes focus from a field the person is in. |
There was a problem hiding this comment.
Non-blocking: this is one 41-word sentence, and its second clause restates the first; it also says "a field" where the check keeps focus on any element inside the dialog. A shorter version that keeps the rule and its reason:
// In an open dialog, a new header takes focus only when focus is on the
// dialog itself or outside it. Content that loads late still gets a target.| active != null && | ||
| active !== nativeDialog && | ||
| nativeDialog.contains(active); | ||
| if (!isFocusInside) { |
There was a problem hiding this comment.
This keeps focus on any element inside the dialog, not only a field. When a footer Next button swaps a keyed header, focus now stays on Next and the new step title is not focused or announced; on main it moves to the title. No Dialog clause covers a header that mounts after the dialog opened, so this rule needs an engineering owner's decision (see the review comment).
User impact
In a Dialog whose header changes while it is open (a wizard whose step swaps its
DialogHeader, or a header keyed on content), the new header pulls focus to its title, even while the person is typing in a field. The caret jumps out mid-word, and screen readers announce the heading again.Problem and solution fit
DialogHeaderfocuses its title in a mount effect whenever its native dialog is already open. That is right for a dialog that opens with nothing focusable yet (content that loads late), and wrong when the person is already in a control inside the dialog.Expected behavior and authority
component:DialogFR2 and its representative state "native modal with DialogHeader — modal is visible before focus; title receives default focus": the title is the default initial focus at open. Nothing in the record makes a later header mount an initial-focus moment. Focus at open is still done by Dialog aftershowModal()and is unchanged.Smallest restoration
Inside
DialogHeader's existing mount effect, the open-dialog branch now checks whether a control inside the dialog already has focus. A header outside any<dialog>and a header in a closed dialog behave as before.Evidence
H2 "Step two".INPUT#namein both engines.DialogHeaderfocus test, the opening-commit title-focus test and every other Dialog suite pass unchanged.Dialog.test.tsx"does not take focus from a field when a header mounts in an open dialog" fails without the fix and passes with it.Scope
Components: DialogHeader
Testing
pnpm exec vitest run --project ui packages/core/src/Dialog packages/core/src/Drawer packages/core/src/BottomSheet packages/core/src/AlertDialog packages/core/src/MobileNav packages/core/src/Lightbox packages/core/src/TextInput: 48 files, 1,357 tests passed