Skip to content

fix(DialogHeader): a header that mounts in an open dialog does not take focus from a control inside it - #11204

Draft
nynexman4464 wants to merge 1 commit into
mainfrom
nynexman4464/fix/dialog-header-remount-focus
Draft

nynexman4464 wants to merge 1 commit into
mainfrom
nynexman4464/fix/dialog-header-remount-focus

Conversation

@nynexman4464

Copy link
Copy Markdown
Contributor

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

  • Why it happens: DialogHeader focuses 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.
  • Why it matters: focus that jumps without user action fails WCAG 3.2.1/3.2.2 expectations and loses typed input.
  • Fix: a header that mounts in an open dialog takes focus only when nothing inside the dialog holds it, meaning focus is on the dialog element itself, on the body, or outside the dialog.

Expected behavior and authority

component:Dialog FR2 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 after showModal() 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

  • Reproduction before the change: a real browser (Chromium 149, Firefox 151) with a wizard Dialog whose header swaps from "Step one" to "Step two" when the Name field's value changes. Typing in Name moved focus to H2 "Step two".
  • Result after the change: focus stays in INPUT#name in both engines.
  • Representative unchanged path: a header that mounts after the dialog opened, with nothing focused inside, still takes focus (new test). The standalone DialogHeader focus test, the opening-commit title-focus test and every other Dialog suite pass unchanged.
  • Regression test: 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

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • 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

  • 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
  • Real browser: Chromium 149 and Firefox 151, the wizard page above, before and after

@vercel

vercel Bot commented Nov 11, 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 11, 2026 9:37am UTC

Request Review

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

astracat-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 11, 2026, 9:50 AM UTC

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded skipped. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@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.

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.tsx lines 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.

Automated review (maintainer link)

Comment on lines +195 to +197
// 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.

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.

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) {

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.

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).

This branch was successfully deployed

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

Labels

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