An open source design system that's fully customizable and agent ready
TypeScript
fix(core): Banner endContent wraps to its own row on a narrow header (#5116)
Cindy Zhang72e38c182c5f
diff --git a/.changeset/banner-endcontent-wrap.md b/.changeset/banner-endcontent-wrap.mdnew file mode 100644index 0000000000..1dccbbb14f--- /dev/null+++ b/.changeset/banner-endcontent-wrap.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Banner: `endContent` wraps to its own row on a narrow header instead of squeezing the title to one word per line.++@cixzhangdiff --git a/apps/storybook/stories/Banner.stories.tsx b/apps/storybook/stories/Banner.stories.tsxindex da5f20ba21..572b6a8967 100644--- a/apps/storybook/stories/Banner.stories.tsx+++ b/apps/storybook/stories/Banner.stories.tsx@@ -318,3 +318,22 @@ export const EmptySlots: Story = {</div>),};++export const MultipleActionsNarrow: Story = {+ name: 'Multiple actions (narrow viewport)',+ render: () => (+ <Banner+ status="warning"+ title="A compute node is required"+ description="Attach one of the announcing compute nodes to continue this session."+ endContent={+ <>+ <Button label="Attach od-1234" variant="secondary" size="sm" />+ <Button label="Attach od-9999" variant="secondary" size="sm" />+ <Button label="Provision new" variant="secondary" size="sm" />+ </>+ }+ isDismissable+ />+ ),+};diff --git a/packages/core/src/Banner/Banner.doc.mjs b/packages/core/src/Banner/Banner.doc.mjsindex 51ad89bd33..3ae109892c 100644--- a/packages/core/src/Banner/Banner.doc.mjs+++ b/packages/core/src/Banner/Banner.doc.mjs@@ -70,7 +70,7 @@ export const docs = {name: 'endContent',type: 'ReactNode',description:- 'Action content rendered in the header area, end-aligned. Typically a button or link.',+ 'Action content rendered in the header area, end-aligned. Wraps to its own row below the text when the header is too narrow to hold both.',slotElements: [{__element: 'Icon', props: {icon: 'chevronDown', size: 'sm'}},{__element: 'Badge', props: {label: '3'}},@@ -164,7 +164,7 @@ export const docsZh = {{name: 'icon', type: 'ReactNode', description: '覆盖默认的状态图标。'},{name: 'isDismissable', type: 'boolean', description: '横幅是否可被用户关闭。', default: 'false'},{name: 'onDismiss', type: '() => void', description: '点击关闭按钮时调用;无论是否提供此回调,横幅都会自动隐藏。'},- {name: 'endContent', type: 'ReactNode', description: '渲染在头部区域末端对齐的操作内容,通常是按钮或链接。'},+ {name: 'endContent', type: 'ReactNode', description: '渲染在头部区域末端对齐的操作内容,通常是按钮或链接。头部过窄时会整体换行到文本下方,自成一行。'},{name: 'container', type: "'card' | 'section'", description: '视觉变体:card 带圆角;section 无圆角全宽,适用于页面级场景。', default: "'card'"},{name: 'elevation', type: "'none' | 'low' | 'med' | 'high'", description: '静止阴影深度。用于悬浮于内容之上的浮动横幅;none 为默认内联横幅。', default: "'none'"},{name: 'children', type: 'ReactNode', description: '渲染在彩色头部下方卡片背景区域的内容。'},@@ -238,7 +238,7 @@ export const docsDense = {icon: 'override default status icon',isDismissable: 'user can dismiss banner',onDismiss: 'dismiss callback; banner self-hides regardless',- endContent: 'end-aligned action in header, typically button/link',+ endContent: 'end-aligned action in header, typically button/link; wraps to its own row when the header is too narrow',container: 'card=border-radius; section=full-width no radius for page-level',elevation: 'resting shadow depth: none|low|med|high; raise for a floating banner',children: 'content in card-bg area below colored header',diff --git a/packages/core/src/Banner/Banner.test.tsx b/packages/core/src/Banner/Banner.test.tsxindex 916978174e..371779d663 100644--- a/packages/core/src/Banner/Banner.test.tsx+++ b/packages/core/src/Banner/Banner.test.tsx@@ -523,4 +523,44 @@ describe('Banner', () => {expect(header.children[1].children).toHaveLength(1);});});++ // jsdom does no flex layout, so these read the declarations that produce the+ // wrap. The rendered result is verified in Chromium at 320/375/480/768.+ describe('narrow-viewport wrapping', () => {+ const renderBanner = (endContent?: React.ReactNode) => {+ const {container} = render(+ <Banner+ status="warning"+ title="A compute node is required"+ endContent={endContent}+ />,+ );+ const header = container.firstElementChild!.firstElementChild!;+ return {+ header,+ textColumn: screen.getByText('A compute node is required')+ .parentElement!,+ };+ };++ it('lets the header wrap so the end area can take its own row', () => {+ const {header} = renderBanner(<button type="button">Retry</button>);+ expect(getComputedStyle(header).flexWrap).toBe('wrap');+ });++ it('gives the text column a wrap threshold when endContent is present', () => {+ const {textColumn} = renderBanner(<button type="button">Retry</button>);+ expect(getComputedStyle(textColumn).flexBasis).toBe('8rem');+ });++ it('leaves the text column free to shrink when there is no endContent', () => {+ const {textColumn} = renderBanner();+ expect(getComputedStyle(textColumn).flexBasis).not.toBe('8rem');+ });++ it('leaves it free for an endContent that renders nothing', () => {+ const {textColumn} = renderBanner(false);+ expect(getComputedStyle(textColumn).flexBasis).not.toBe('8rem');+ });+ });});diff --git a/packages/core/src/Banner/Banner.tsx b/packages/core/src/Banner/Banner.tsxindex 06d6d3eec6..13e276b05c 100644--- a/packages/core/src/Banner/Banner.tsx+++ b/packages/core/src/Banner/Banner.tsx@@ -116,6 +116,9 @@ export interface BannerProps extends BaseProps<HTMLDivElement> {* Action button rendered in the header area (end-aligned).* Typically an Button with a secondary or ghost variant.*+ * When the header is too narrow to hold the actions and a readable text+ * column, the whole end area wraps to its own row below the text.+ ** @example* ```* endContent={<Button label="Retry" variant="ghost" onClick={handleRetry} />}@@ -205,7 +208,11 @@ const styles = stylex.create({header: {display: 'flex',alignItems: 'flex-start',- gap: spacingVars['--spacing-2'],+ flexWrap: 'wrap',+ columnGap: spacingVars['--spacing-2'],+ // The end area carries a -4px block margin (see endArea), so the wrapped+ // row reads as one step of spacing rather than two.+ rowGap: spacingVars['--spacing-3'],paddingBlock: spacingVars['--spacing-3'],paddingInline: spacingVars['--spacing-4'],},@@ -231,6 +238,15 @@ const styles = stylex.create({flex: 1,minWidth: 0,},+ // The wrap threshold, applied only when there is `endContent` to wrap. Flex+ // breaks a line when the items no longer fit at their base size, so this+ // basis is what moves the end area to its own row instead of letting it hold+ // the header and squeeze the title down to one word per line. In rem so it+ // tracks the user's font size. The dismiss and expand controls alone are+ // narrow enough never to need it.+ headerContentWithEndContent: {+ flexBasis: '8rem',+ },title: {margin: 0,fontFamily: 'inherit',@@ -260,8 +276,13 @@ const styles = stylex.create({endArea: {display: 'flex',alignItems: 'center',+ flexWrap: 'wrap',+ justifyContent: 'flex-end',gap: spacingVars['--spacing-2'],flexShrink: 0,+ // Bounded so a group of actions wider than the row wraps within itself+ // rather than pushing the banner past the viewport (WCAG 1.4.10).+ maxWidth: '100%',marginInlineStart: 'auto',marginBlock: `calc(-1 * (${spacingVars['--spacing-3']} - ${spacingVars['--spacing-2']}))`,},@@ -537,7 +558,11 @@ export function Banner({/>) : null}</div>- <div {...stylex.props(styles.headerContent)}>+ <div+ {...stylex.props(+ styles.headerContent,+ isRenderable(endContent) && styles.headerContentWithEndContent,+ )}><div {...stylex.props(styles.title)}>{title}</div>{isRenderable(description) && (<div {...stylex.props(styles.description)}>{description}</div>