An open source design system that's fully customizable and agent ready
TypeScript
fix(DialogHeader): preserve renderable slot content (#7454)
Cindy Zhang675b29d76ce4
diff --git a/.changeset/dialog-header-renderable-slots.md b/.changeset/dialog-header-renderable-slots.mdnew file mode 100644index 0000000000..242f2303be--- /dev/null+++ b/.changeset/dialog-header-renderable-slots.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `DialogHeader` now keeps valid numeric zero content inside its `startContent` and `endContent` wrappers and theme targets.++@cixzhangdiff --git a/packages/core/src/Dialog/DialogHeader.test.tsx b/packages/core/src/Dialog/DialogHeader.test.tsxindex ebdf4d619c..a1f11345cb 100644--- a/packages/core/src/Dialog/DialogHeader.test.tsx+++ b/packages/core/src/Dialog/DialogHeader.test.tsx@@ -260,6 +260,19 @@ describe('DialogHeader', () => {expect(closeIcon).toHaveClass('astryx-icon');});+ it('renders numeric zero in both content slots', () => {+ const {container} = render(+ <DialogHeader title="Title" startContent={0} endContent={0} />,+ );++ expect(+ container.querySelector('.astryx-dialog-header-start-content'),+ ).toHaveTextContent(/^0$/);+ expect(+ container.querySelector('.astryx-dialog-header-end-content'),+ ).toHaveTextContent(/^0$/);+ });+it('exposes the start-content target when startContent renders', () => {const {container} = render(<DialogHeader@@ -292,8 +305,20 @@ describe('DialogHeader', () => {).toHaveLength(1);});- it('omits the content-slot targets when their content does not render', () => {- const {container} = render(<DialogHeader title="Title" />);+ it.each([+ ['empty string', ''],+ ['false', false],+ ['true', true],+ ['null', null],+ ['undefined', undefined],+ ])('omits both content-slot targets for %s', (_, content) => {+ const {container} = render(+ <DialogHeader+ title="Title"+ startContent={content}+ endContent={content}+ />,+ );expect(container.querySelector('.astryx-dialog-header-start-content'),diff --git a/packages/core/src/Dialog/DialogHeader.tsx b/packages/core/src/Dialog/DialogHeader.tsxindex 2c86294d87..303fb414f1 100644--- a/packages/core/src/Dialog/DialogHeader.tsx+++ b/packages/core/src/Dialog/DialogHeader.tsx@@ -4,7 +4,7 @@/*** @file DialogHeader.tsx- * @input Uses React, StyleX, LayoutHeader, Button, Icon, Heading, Text, DialogContext, mergeProps, themeProps+ * @input Uses React, StyleX, LayoutHeader, Button, Icon, Heading, Text, DialogContext, isRenderable, mergeProps, themeProps* @output Exports DialogHeader component and DialogHeaderProps* @position Dialog header component; used with Dialog and Layout*@@ -25,7 +25,7 @@ import {Icon} from '../Icon';import {Heading} from '../Heading/Heading';import {Text} from '../Text/Text';import type {BaseProps} from '../BaseProps';-import {mergeProps} from '../utils';+import {isRenderable, mergeProps} from '../utils';import {themeProps} from '../utils/themeProps';import {useDialogContext} from './DialogContext';import {useTranslator} from '../i18n';@@ -164,10 +164,9 @@ export function DialogHeader({const dialogContext = useDialogContext();const shouldAutoFocus = dialogContext?.isInline !== true;const titleId = dialogContext?.titleId;- // A node subtitle may be `0`: render it inside Text instead of letting a- // truthiness check leak a bare text node, and skip only empty values.- const hasSubtitle =- subtitle != null && typeof subtitle !== 'boolean' && subtitle !== '';+ const hasSubtitle = isRenderable(subtitle);+ const hasStartContent = isRenderable(startContent);+ const hasEndContent = isRenderable(endContent);const shouldCompensateEndBlock =endContentEdgeCompensation == null? onOpenChange != null@@ -203,7 +202,7 @@ export function DialogHeader({themeProps('dialog-header'),stylex.props(styles.container),)}>- {startContent && (+ {hasStartContent && (<div{...mergeProps(themeProps('dialog-header-start-content'),@@ -231,7 +230,7 @@ export function DialogHeader({</Text>)}</div>- {(endContent || onOpenChange) && (+ {(hasEndContent || onOpenChange != null) && (<div{...mergeProps(themeProps('dialog-header-end-content'),