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..23103c514ad46
--- /dev/null
+++ b/.changeset/internal-lab-s-dialogheroheader-reads-the-dialog-ctse.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[chore] Internal: an internal entry reserved for Astryx's own packages exposes the Dialog's title id and inline state, so Lab's upcoming DialogHeroHeader can name the dialog and request title focus the way DialogHeader does; 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.test.tsx b/packages/core/src/Dialog/Dialog.test.tsx
index b676be021577d..731a728d0d379 100644
--- a/packages/core/src/Dialog/Dialog.test.tsx
+++ b/packages/core/src/Dialog/Dialog.test.tsx
@@ -9,7 +9,7 @@
* SYNC: When Dialog.tsx changes, update tests to match new behavior
*/
-import {useState, type SyntheticEvent} from 'react';
+import {useLayoutEffect, useState, type SyntheticEvent} from 'react';
import {readFileSync} from 'node:fs';
import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';
import type {MockInstance} from 'vitest';
@@ -20,6 +20,7 @@ import {
resolveDialogPositionOffsets,
} from './Dialog';
import {DialogHeader} from './DialogHeader';
+import {useDialogContext} from './DialogContext';
import {defineTheme, generateThemeCSS} from '../theme';
import {__resetInteractionModalityForTest} from '../utils/interactionModality';
@@ -207,6 +208,75 @@ describe('Dialog', () => {
expect(screen.getByRole('button', {name: 'Continue'})).toHaveFocus();
});
+ it('skips a hidden or inert initial-focus request for the next eligible one', () => {
+ render(
+ ,
+ );
+
+ expect(screen.getByRole('button', {name: 'Continue'})).toHaveFocus();
+ });
+
+ it('falls through an initial-focus request that cannot take focus', () => {
+ render(
+ ,
+ );
+
+ expect(screen.getByRole('button', {name: 'Continue'})).toHaveFocus();
+ });
+
+ it("honors an explicit request before a header's title request", () => {
+ render(
+ ,
+ );
+
+ expect(screen.getByRole('button', {name: 'Continue'})).toHaveFocus();
+ });
+
+ it("focuses a header's title request when no explicit request is eligible", () => {
+ render(
+ ,
+ );
+
+ expect(screen.getByRole('heading', {name: 'Hero title'})).toHaveFocus();
+ });
+
describe('purpose: info (default)', () => {
it('calls onOpenChange(false) when Escape is pressed', () => {
const handleHide = vi.fn();
@@ -1218,6 +1288,38 @@ describe('Dialog', () => {
expect(dialog).toHaveAccessibleName('Rich dialog title');
});
+ it('names itself by a header title that renders after the dialog mounts', () => {
+ // A composed header whose title arrives in a later commit asks the
+ // dialog to check its default name again.
+ function LateTitleHeader({isReady}: {isReady: boolean}) {
+ const context = useDialogContext();
+ const syncDefaultName = context?.syncDefaultName;
+ useLayoutEffect(() => {
+ syncDefaultName?.();
+ }, [isReady, syncDefaultName]);
+ return isReady ?
Late title
: null;
+ }
+ const {rerender} = render(
+ ,
+ );
+ const dialog = screen.getByRole('dialog');
+ expect(dialog).not.toHaveAttribute('aria-labelledby');
+ rerender(
+ ,
+ );
+ expect(dialog).toHaveAccessibleName('Late title');
+ rerender(
+ ,
+ );
+ expect(dialog).not.toHaveAttribute('aria-labelledby');
+ });
+
it('prefers a consumer-provided aria-label over the header title', () => {
render(