An open source design system that's fully customizable and agent ready
TypeScript
feat(DialogHeader): add end-content edge compensation (#6465)
Cindy Zhangd72e4d6b474d
diff --git a/.changeset/dialog-header-end-content-edge-compensation.md b/.changeset/dialog-header-end-content-edge-compensation.mdnew file mode 100644index 0000000000..1411c85fd4--- /dev/null+++ b/.changeset/dialog-header-end-content-edge-compensation.md@@ -0,0 +1,9 @@+---+'@astryxdesign/core': patch+---++[feat] DialogHeader: add end-content edge compensation control++DialogHeader now accepts `endContentEdgeCompensation="inline" | "block" | "all"` to select which axes of its existing end-content wrapper receive fixed compensation. Omitting the prop preserves the current automatic compensation whenever the close action renders.++@cixzhangdiff --git a/apps/storybook/stories/Dialog.stories.tsx b/apps/storybook/stories/Dialog.stories.tsxindex fc3ed26bd4..3106dbd82a 100644--- a/apps/storybook/stories/Dialog.stories.tsx+++ b/apps/storybook/stories/Dialog.stories.tsx@@ -954,6 +954,54 @@ export const ReadinessNarrowViewport: Story = {},};+/** Visual reference for DialogHeader's default and explicit end-slot compensation. */+export const HeaderEndEdgeCompensation: Story = {+ name: 'Header / end edge compensation',+ render: () => (+ <VStack gap={4}>+ <Dialog isOpen isInline onOpenChange={() => {}} width={400}>+ <Layout+ header={+ <DialogHeader+ title="Automatic end-content compensation"+ endContent={<Button label="Help" variant="ghost" />}+ onOpenChange={() => {}}+ />+ }+ content={+ <LayoutContent>+ <Text type="body">+ Omission preserves the released block and logical inline-end+ compensation whenever the close action renders.+ </Text>+ </LayoutContent>+ }+ />+ </Dialog>+ <Dialog isOpen isInline onOpenChange={() => {}} width={400}>+ <Layout+ header={+ <DialogHeader+ title="Inline-only end-content compensation"+ endContent={<Button label="Help" variant="ghost" />}+ endContentEdgeCompensation="inline"+ onOpenChange={() => {}}+ />+ }+ content={+ <LayoutContent>+ <Text type="body">+ The anatomy-targeted prop keeps logical inline-end alignment+ while leaving the slot inside the header's block edges.+ </Text>+ </LayoutContent>+ }+ />+ </Dialog>+ </VStack>+ ),+};+type PresentationChoiceProps = {presentation: 'dialog' | 'fullscreen' | 'bottom-sheet';};diff --git a/packages/core/src/Dialog/DialogHeader.doc.mjs b/packages/core/src/Dialog/DialogHeader.doc.mjsindex 609191a793..f8c7d0331e 100644--- a/packages/core/src/Dialog/DialogHeader.doc.mjs+++ b/packages/core/src/Dialog/DialogHeader.doc.mjs@@ -66,6 +66,11 @@ export const docs = {},],},+ {+ name: 'endContentEdgeCompensation',+ type: "'inline' | 'block' | 'all'",+ description: 'Selects compensation axes for the end-content slot. Omit to preserve automatic close-action compensation.',+ },{name: 'hasDivider',type: 'boolean',@@ -166,6 +171,11 @@ export const docsZh = {type: 'ReactNode',description: '标题之后、关闭按钮之前的内容。',},+ {+ name: 'endContentEdgeCompensation',+ type: "'inline' | 'block' | 'all'",+ description: '选择尾部内容插槽的补偿轴;省略时保留关闭操作的自动补偿。',+ },{name: 'hasDivider',type: 'boolean',@@ -201,6 +211,8 @@ export const docsDense = {onOpenChange: 'close button callback (omit=no button)',startContent: 'content before title (e.g. back button)',endContent: 'content after title, before close button',+ endContentEdgeCompensation:+ 'end-content slot axes: inline | block | all; omit=automatic close-action compensation',hasDivider: 'bottom border',},};diff --git a/packages/core/src/Dialog/DialogHeader.test.tsx b/packages/core/src/Dialog/DialogHeader.test.tsxindex 168c39a0b5..8d0a77d1b0 100644--- a/packages/core/src/Dialog/DialogHeader.test.tsx+++ b/packages/core/src/Dialog/DialogHeader.test.tsx@@ -22,6 +22,17 @@ function generateThemeTestCSS(theme: Parameters<typeof generateThemeCSS>[0]) {return [prose, component].filter(Boolean).join('\n\n');}+function getEndSlot(): HTMLElement {+ const child =+ screen.queryByRole('button', {name: 'Action'}) ??+ screen.getByRole('button', {name: /close/i});+ const slot = child.parentElement;+ if (slot == null) {+ throw new Error('Expected DialogHeader end slot');+ }+ return slot;+}+describe('DialogHeader', () => {it('renders the title', () => {render(<DialogHeader title="My Dialog Title" />);@@ -63,6 +74,92 @@ describe('DialogHeader', () => {expect(screen.getByRole('button', {name: /close/i})).toBeInTheDocument();});+ it('preserves automatic end-slot compensation when the close action renders', () => {+ const {rerender} = render(+ <DialogHeader title="Title" onOpenChange={() => {}} />,+ );+ const automaticClassName = getEndSlot().className;++ rerender(+ <DialogHeader+ title="Title"+ endContent={<button type="button">Action</button>}+ onOpenChange={() => {}}+ />,+ );+ expect(getEndSlot().className).toBe(automaticClassName);++ rerender(+ <DialogHeader+ title="Title"+ endContent={<button type="button">Action</button>}+ />,+ );+ expect(getEndSlot().className).not.toBe(automaticClassName);+ });++ it('lets endContentEdgeCompensation select inline, block, or all', () => {+ const {rerender} = render(+ <DialogHeader+ title="Title"+ endContent={<button type="button">Action</button>}+ />,+ );+ const noCompensationClassName = getEndSlot().className;++ rerender(+ <DialogHeader+ title="Title"+ endContent={<button type="button">Action</button>}+ endContentEdgeCompensation="inline"+ />,+ );+ const inlineClassName = getEndSlot().className;++ rerender(+ <DialogHeader+ title="Title"+ endContent={<button type="button">Action</button>}+ endContentEdgeCompensation="block"+ />,+ );+ const blockClassName = getEndSlot().className;++ rerender(+ <DialogHeader+ title="Title"+ endContent={<button type="button">Action</button>}+ endContentEdgeCompensation="all"+ />,+ );+ const allClassName = getEndSlot().className;++ expect(inlineClassName).not.toBe(noCompensationClassName);+ expect(blockClassName).not.toBe(noCompensationClassName);+ expect(inlineClassName).not.toBe(blockClassName);+ expect(allClassName).not.toBe(inlineClassName);+ expect(allClassName).not.toBe(blockClassName);++ rerender(+ <DialogHeader+ title="Title"+ endContent={<button type="button">Action</button>}+ onOpenChange={() => {}}+ />,+ );+ expect(getEndSlot().className).toBe(allClassName);++ rerender(+ <DialogHeader+ title="Title"+ endContent={<button type="button">Action</button>}+ endContentEdgeCompensation="inline"+ onOpenChange={() => {}}+ />,+ );+ expect(getEndSlot().className).toBe(inlineClassName);+ });+it('exposes theme targets for the header row, title block, and close icon', () => {const {container} = render(<DialogHeaderdiff --git a/packages/core/src/Dialog/DialogHeader.tsx b/packages/core/src/Dialog/DialogHeader.tsxindex 5f37e4c238..ae91882f71 100644--- a/packages/core/src/Dialog/DialogHeader.tsx+++ b/packages/core/src/Dialog/DialogHeader.tsx@@ -37,9 +37,11 @@ const styles = stylex.create({justifyContent: 'space-between',gap: spacingVars['--spacing-3'],},- // Compensate for the icon button's visual padding on the actions area- actionsCompensation: {+ // Compensate for the medium icon button's visual padding on the end slot.+ endBlockEdgeCompensation: {marginBlock: `calc(-1 * ${spacingVars['--spacing-2']})`,+ },+ endInlineEdgeCompensation: {marginInlineEnd: `calc(-1 * ${spacingVars['--spacing-2']})`,},titleWrapper: {@@ -98,6 +100,14 @@ export interface DialogHeaderProps extends BaseProps<HTMLDivElement> {*/endContent?: ReactNode;+ /**+ * Overrides automatic end-slot compensation. When omitted, the slot keeps its+ * existing behavior: rendering the close action applies block and logical+ * inline-end compensation. Use `inline`, `block`, or `all` to select the axes+ * explicitly.+ */+ endContentEdgeCompensation?: 'inline' | 'block' | 'all';+/*** Adds a themed border at the bottom edge.* When false, spacing collapse is applied automatically for seamless visual flow.@@ -134,6 +144,7 @@ export function DialogHeader({onOpenChange,startContent,endContent,+ endContentEdgeCompensation,hasDivider,xstyle,className,@@ -146,6 +157,16 @@ export function DialogHeader({const dialogContext = useDialogContext();const shouldAutoFocus = dialogContext?.isInline !== true;const titleId = dialogContext?.titleId;+ const shouldCompensateEndBlock =+ endContentEdgeCompensation == null+ ? onOpenChange != null+ : endContentEdgeCompensation === 'block' ||+ endContentEdgeCompensation === 'all';+ const shouldCompensateEndInline =+ endContentEdgeCompensation == null+ ? onOpenChange != null+ : endContentEdgeCompensation === 'inline' ||+ endContentEdgeCompensation === 'all';// Auto-focus the title when mounted for screen reader accessibility.// Inline dialogs are documentation/showcase previews, so suppress focus to@@ -197,7 +218,8 @@ export function DialogHeader({<div{...stylex.props(styles.actions,- onOpenChange && styles.actionsCompensation,+ shouldCompensateEndBlock && styles.endBlockEdgeCompensation,+ shouldCompensateEndInline && styles.endInlineEdgeCompensation,)}>{endContent}{onOpenChange && (