From 0798a674b672e0b054118f95543893c2b704039b Mon Sep 17 00:00:00 2001 From: jiunshinn Date: Wed, 28 Oct 2026 07:00:48 +0900 Subject: [PATCH 1/5] fix(Dialog): an explicit autofocus request wins over a header's title, and Lab reads the Dialog context through an internal entry --- ...e-opening-dialog-s-first-data-auto-wr66.md | 6 ++++ ...-dialogheroheader-reads-the-dialog-ctse.md | 6 ++++ packages/core/package.json | 5 ++++ packages/core/src/Dialog/Dialog.tsx | 28 +++++++++++++++---- packages/core/src/Dialog/DialogContext.ts | 3 +- .../core/src/internal/dialog-context.test.ts | 25 +++++++++++++++++ packages/core/src/internal/dialog-context.ts | 19 +++++++++++++ scripts/sync-exports.js | 1 + 8 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 .changeset/dialog-when-the-opening-dialog-s-first-data-auto-wr66.md create mode 100644 .changeset/internal-lab-s-dialogheroheader-reads-the-dialog-ctse.md create mode 100644 packages/core/src/internal/dialog-context.test.ts create mode 100644 packages/core/src/internal/dialog-context.ts diff --git a/.changeset/dialog-when-the-opening-dialog-s-first-data-auto-wr66.md b/.changeset/dialog-when-the-opening-dialog-s-first-data-auto-wr66.md new file mode 100644 index 0000000000000..115b0fc049f3e --- /dev/null +++ b/.changeset/dialog-when-the-opening-dialog-s-first-data-auto-wr66.md @@ -0,0 +1,6 @@ +--- +'@astryxdesign/core': patch +--- + +[fix] Dialog: when the opening Dialog's first data-autofocus request is hidden, inert, or cannot take focus, the next request takes it; a header's default title request comes after every explicit request (#4182) +@jiunshinn diff --git a/.changeset/internal-lab-s-dialogheroheader-reads-the-dialog-ctse.md b/.changeset/internal-lab-s-dialogheroheader-reads-the-dialog-ctse.md new file mode 100644 index 0000000000000..cb437fc0b86e5 --- /dev/null +++ b/.changeset/internal-lab-s-dialogheroheader-reads-the-dialog-ctse.md @@ -0,0 +1,6 @@ +--- +'@astryxdesign/core': patch +--- + +[chore] Internal: Lab's DialogHeroHeader reads the Dialog's title id and inline state through an internal entry reserved for Astryx's own packages; nothing a consumer sees changes (#4182) +@jiunshinn diff --git a/packages/core/package.json b/packages/core/package.json index 295c3d98433c4..dd119a33b384c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -828,6 +828,11 @@ "source": "./src/internal/tokenizer-presentation.ts", "types": "./dist/internal/tokenizer-presentation.d.ts", "default": "./dist/internal/tokenizer-presentation.js" + }, + "./internal/dialog-context": { + "source": "./src/internal/dialog-context.ts", + "types": "./dist/internal/dialog-context.d.ts", + "default": "./dist/internal/dialog-context.js" } }, "files": [ diff --git a/packages/core/src/Dialog/Dialog.tsx b/packages/core/src/Dialog/Dialog.tsx index 2f1e5806bddb0..f5c43018d2c7f 100644 --- a/packages/core/src/Dialog/Dialog.tsx +++ b/packages/core/src/Dialog/Dialog.tsx @@ -15,6 +15,8 @@ * Fullscreen dialogs add safe-area protection to the default padding fallback * while preserving explicit prop/theme padding overrides, and fade in without * the centered-dialog translate/scale motion. + * Initial focus is applied after showModal; an explicit descendant request + * takes priority over a header's default title request. * * Under reduced motion the entrance never travels or scales * (docs/design/reduced-motion.md): on a touch screen the dialog fades in @@ -580,11 +582,27 @@ export function Dialog({ dialog.showModal(); // React's autoFocus calls .focus() during commit, before showModal() // makes the dialog visible, so the focus silently fails. - // Focus the first element with data-autofocus inside the dialog. - const autofocusTarget = - dialog.querySelector('[data-autofocus]'); - if (autofocusTarget) { - focusForLastInput(autofocusTarget); + // Explicit descendant intent takes priority over a header's default + // title. Keep the marker private to the focus-owning components. + const autofocusTargets = [ + ...dialog.querySelectorAll( + '[data-autofocus]:not([data-autofocus="dialog-title"])', + ), + ...dialog.querySelectorAll( + '[data-autofocus="dialog-title"]', + ), + ]; + for (const target of autofocusTargets) { + if (target.closest('[hidden], [inert], [aria-hidden="true"]')) { + continue; + } + // Disabled and CSS-hidden targets cannot receive focus in the + // browser. If a request cannot land, try the next eligible request + // and finally the title; otherwise preserve native initial focus. + focusForLastInput(target); + if (document.activeElement === target) { + break; + } } } } else { diff --git a/packages/core/src/Dialog/DialogContext.ts b/packages/core/src/Dialog/DialogContext.ts index 9872e43d5fe59..9ad8403b9a09b 100644 --- a/packages/core/src/Dialog/DialogContext.ts +++ b/packages/core/src/Dialog/DialogContext.ts @@ -6,7 +6,8 @@ * @file DialogContext.ts * @input React context * @output Internal dialog context for child focus behavior and default labelling - * @position Dialog internals; consumed by focus-managing children and DialogHeader + * @position Dialog internals; consumed by focus-managing children and DialogHeader, + * and by Lab's DialogHeroHeader through the internal/dialog-context entry */ import {createContext, use} from 'react'; diff --git a/packages/core/src/internal/dialog-context.test.ts b/packages/core/src/internal/dialog-context.test.ts new file mode 100644 index 0000000000000..976496f876b24 --- /dev/null +++ b/packages/core/src/internal/dialog-context.test.ts @@ -0,0 +1,25 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. +/** + * @file dialog-context.test.ts + * @input The internal `internal/dialog-context` entry and the Dialog module + * @output Proof that the entry re-exports the same hook Dialog provides, by + * name, and that the public Dialog barrel names no context + * @position Unit tests of packages/core/src/internal/dialog-context.ts + */ +import {describe, expect, it} from 'vitest'; + +describe('internal/dialog-context', () => { + it('re-exports the one Dialog context hook, the same value Dialog reads', async () => { + const entry: Record = await import('./dialog-context'); + const context = await import('../Dialog/DialogContext'); + expect(entry.useDialogContext).toBe(context.useDialogContext); + // Named re-exports only, nothing else. + expect(Object.keys(entry).sort()).toEqual(['useDialogContext']); + }); + + it('the public Dialog barrel exports no context surface', async () => { + const pub: Record = await import('../Dialog'); + expect(pub).not.toHaveProperty('DialogContext'); + expect(pub).not.toHaveProperty('useDialogContext'); + }); +}); diff --git a/packages/core/src/internal/dialog-context.ts b/packages/core/src/internal/dialog-context.ts new file mode 100644 index 0000000000000..aaf9ca18b4b55 --- /dev/null +++ b/packages/core/src/internal/dialog-context.ts @@ -0,0 +1,19 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. + +/** + * @file dialog-context.ts + * @input Dialog's internal context hook + * @output `@astryxdesign/core/internal/dialog-context`: `useDialogContext`, + * for Astryx's own packages + * @position An internal entry reserved for Astryx's own packages: + * undocumented, outside the public API and its compatibility promise + * (spec:AST-017 FR21), versioned in lockstep with Core, and allowed only in + * Core and Lab by the `@astryx/no-core-internal-import` lint rule + * (architecture:react-component-runtime INV13). Lab's DialogHeroHeader reads + * the Dialog's title id and inline state through it, so it names the dialog + * and requests title focus the way DialogHeader does. Named re-exports only. + * + * SYNC: When modified, update dialog-context.test.ts and + * scripts/sync-exports.js. + */ +export {useDialogContext} from '../Dialog/DialogContext'; diff --git a/scripts/sync-exports.js b/scripts/sync-exports.js index ee5316c7916a1..ec61b3c86cb0a 100644 --- a/scripts/sync-exports.js +++ b/scripts/sync-exports.js @@ -239,6 +239,7 @@ const FILE_MODULE_SUBPATH_EXPORTS = [ // (architecture:react-component-runtime INV13). 'internal/touch', 'internal/tokenizer-presentation', + 'internal/dialog-context', ]; /** From 16c360666b950571783feb670edfbf555b15fd66 Mon Sep 17 00:00:00 2001 From: jiunshinn Date: Wed, 28 Oct 2026 07:01:10 +0900 Subject: [PATCH 2/5] feat(lab): DialogHeroHeader --- .github/scripts/story-play-guard.js | 7 + .../stories/DialogHeroHeader.stories.tsx | 518 ++++++++++++++++++ internal/shadcn-registry/routes.lock.json | 10 + .../blocks/DialogHeroHeaderShowcase.doc.mjs | 29 + .../lab/blocks/DialogHeroHeaderShowcase.tsx | 86 +++ .../DialogHeroHeader/DialogHeroHeader.doc.mjs | 229 ++++++++ .../DialogHeroHeader.test.tsx | 502 +++++++++++++++++ .../src/DialogHeroHeader/DialogHeroHeader.tsx | 348 ++++++++++++ packages/lab/src/DialogHeroHeader/index.ts | 14 + packages/lab/src/index.ts | 7 + 10 files changed, 1750 insertions(+) create mode 100644 apps/storybook/stories/DialogHeroHeader.stories.tsx create mode 100644 packages/lab/blocks/DialogHeroHeaderShowcase.doc.mjs create mode 100644 packages/lab/blocks/DialogHeroHeaderShowcase.tsx create mode 100644 packages/lab/src/DialogHeroHeader/DialogHeroHeader.doc.mjs create mode 100644 packages/lab/src/DialogHeroHeader/DialogHeroHeader.test.tsx create mode 100644 packages/lab/src/DialogHeroHeader/DialogHeroHeader.tsx create mode 100644 packages/lab/src/DialogHeroHeader/index.ts diff --git a/.github/scripts/story-play-guard.js b/.github/scripts/story-play-guard.js index db34b39b9cfb8..532f7eec48f25 100644 --- a/.github/scripts/story-play-guard.js +++ b/.github/scripts/story-play-guard.js @@ -347,6 +347,13 @@ const TARGETS = [ guards: 'the rendered RTL wrapper mirrors fixed-track item order while responsive and span geometry remain bounded', }, + { + component: 'DialogHeroHeader', + story: 'lab-dialogheroheader--media-bleed-geometry', + guards: + 'media reaches the dialog edges at theme-default, 0/2/8 padding, a ' + + 'theme override, and RTL while the title keeps the cancelled inset', + }, { component: 'TabList', story: 'core-tablist--full-bleed-geometry', diff --git a/apps/storybook/stories/DialogHeroHeader.stories.tsx b/apps/storybook/stories/DialogHeroHeader.stories.tsx new file mode 100644 index 0000000000000..ba0664b6e0fd9 --- /dev/null +++ b/apps/storybook/stories/DialogHeroHeader.stories.tsx @@ -0,0 +1,518 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. + +/** + * @file DialogHeroHeader.stories.tsx + * @input DialogHeroHeader and its Dialog, Layout, Heading, and media composition + * @output Inline visual states, an interactive modal example, and a media + * bleed geometry guard across Dialog paddings and RTL + * @position Storybook coverage for the experimental hero header; the geometry + * story's play function is required CI via story-play-guard.js + */ + +import {useId, useState, type ComponentProps, type CSSProperties} from 'react'; +import type {Meta, StoryObj} from '@storybook/react'; +import {DialogHeroHeader} from '@astryxdesign/lab'; +import {Dialog} from '@astryxdesign/core/Dialog'; +import { + Layout, + LayoutContent, + LayoutFooter, + HStack, +} from '@astryxdesign/core/Layout'; +import {Button} from '@astryxdesign/core/Button'; +import {Heading} from '@astryxdesign/core/Heading'; +import {Icon} from '@astryxdesign/core/Icon'; +import {Text} from '@astryxdesign/core/Text'; +import DialogHeroHeaderShowcase from '../../../packages/lab/blocks/DialogHeroHeaderShowcase'; +import * as stylex from '@stylexjs/stylex'; + +const styles = stylex.create({ + heroSvg: { + display: 'block', + }, +}); + +// Self-contained stand-in for a hero image / illustration. A real app would +// pass an ,