Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

Banner audit: dismiss focus handoff, status fall-through, empty slots and 320px reflow (#5096)

Cindy Zhang4d004cdb4c3d
diff --git a/.changeset/banner-dismiss-focus-and-status-fallthrough.md b/.changeset/banner-dismiss-focus-and-status-fallthrough.md
new file mode 100644
index 0000000000..d9efd40f8d
--- /dev/null
+++ b/.changeset/banner-dismiss-focus-and-status-fallthrough.md
@@ -0,0 +1,18 @@
+---
+'@astryxdesign/core': patch
+'@astryxdesign/theme-neutral': patch
+---
+
+[fix] Banner: a dismissed banner no longer drops focus, a custom status no longer loses its ARIA role, and the info banner paints again under the neutral theme.
+
+Dismissing unmounted the focused dismiss button, so focus landed on `<body>` and a keyboard user lost their place in the page. Banner now records where focus entered from and returns it there, the same handoff `ToastViewport` makes for a dismissed toast. Measured in Chromium: `document.activeElement` was `BODY`, and is now the control the user tabbed in from.
+
+`BannerStatusMap` is documented as augmentable, but all four status lookups were closed `Record<BannerStatus, ...>` maps. Adding the augmentation the docs show produced four TypeScript errors inside `Banner.tsx` itself, which a consumer cannot fix, and at runtime an unknown status resolved to `undefined` for its icon, its background and its ARIA role, so the banner stopped being a live region at all. The lookups are partial now: an unrecognized status renders with no status fill, no default glyph and `role="status"`.
+
+A theme could not reach the banner's radius. `--_banner-radius` was declared in the doc file and in `derivedVarRegistry.ts`, but no rule read it, so a theme's `borderRadius` on the `banner` target expanded into a variable nothing consumed. The four card-silhouette radii read it now, falling back to `--radius-container`.
+
+Under `@astryxdesign/theme-neutral` the info banner had no background at all, light or dark: the override set `background-color` directly and forced `--color-accent-muted` to `transparent`, and a plain CSS property written by a theme lands in `@layer astryx-theme`, which StyleX's `@layer priority4` outranks. Info now goes through `--color-accent-muted` like the other three statuses and like the stone theme already did.
+
+Also in this change: `children={false}` (the ordinary `{cond && <ul/>}` idiom) no longer produces an expand toggle that opens an empty box, and `description=""` no longer leaves an empty 20px row, both via `isRenderable`; a long unbroken word in the title or description no longer forces the page into horizontal scrolling at a 320px viewport, measured at `document.scrollWidth` 529px before; and the content area's bottom border uses logical `border-block-end` alongside its inline siblings.
+
+@cixzhang
diff --git a/.github/a11y-baseline.json b/.github/a11y-baseline.json
index 45c233f4fb..644230e187 100644
--- a/.github/a11y-baseline.json
+++ b/.github/a11y-baseline.json
@@ -18,11 +18,6 @@
"impact": "serious",
"helpUrl": "https://dequeuniversity.com/rules/axe/4.12/color-contrast?application=playwright"
},
- {
- "key": "Banner::Collapsible Content (Expanded)::color-contrast",
- "impact": "serious",
- "helpUrl": "https://dequeuniversity.com/rules/axe/4.12/color-contrast?application=playwright"
- },
{
"key": "Card::Callout::color-contrast",
"impact": "serious",
diff --git a/apps/storybook/stories/Banner.stories.tsx b/apps/storybook/stories/Banner.stories.tsx
index e8fb605151..da5f20ba21 100644
--- a/apps/storybook/stories/Banner.stories.tsx
+++ b/apps/storybook/stories/Banner.stories.tsx
@@ -136,10 +136,9 @@ export const CollapsibleContent: Story = {
children: (
<div
style={{
- fontSize: '13px',
padding: '40px',
textAlign: 'center',
- color: '#999',
+ color: 'var(--color-text-secondary)',
}}>
Flex Slot
</div>
@@ -159,10 +158,9 @@ export const CollapsibleContentExpanded: Story = {
children: (
<div
style={{
- fontSize: '13px',
padding: '40px',
textAlign: 'center',
- color: '#999',
+ color: 'var(--color-text-secondary)',
}}>
Flex Slot
</div>
@@ -274,3 +272,49 @@ export const AllFeatures: Story = {
</div>
),
};
+
+export const LongText: Story = {
+ name: 'Overflow (long text and a long word)',
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '16px'}}>
+ <Banner
+ status="error"
+ title="Your subscription payment could not be processed because the card on file has expired"
+ description="Update the payment method in billing settings to restore access to every workspace on this account before the grace period ends."
+ isDismissable
+ />
+ <Banner
+ status="warning"
+ title="Pneumonoultramicroscopicsilicovolcanoconiosisdiagnosisunavailable"
+ description="Verkehrsinfrastrukturfinanzierungsgesellschaftsvorstandsvorsitzender"
+ isDismissable
+ />
+ </div>
+ ),
+};
+
+export const NarrowContainer: Story = {
+ name: 'Narrow container (240px)',
+ render: () => (
+ <div style={{width: '240px'}}>
+ <Banner
+ status="info"
+ title="Storage almost full"
+ description="Free up space or upgrade your plan to keep syncing."
+ isDismissable
+ />
+ </div>
+ ),
+};
+
+export const EmptySlots: Story = {
+ name: 'Empty slots (falsy children and description)',
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '16px'}}>
+ <Banner status="info" title="No expand affordance" description="">
+ {false}
+ </Banner>
+ <Banner status="success" title="Title only" />
+ </div>
+ ),
+};
diff --git a/packages/cli/assets/templates/themes/neutral/neutralTheme.ts b/packages/cli/assets/templates/themes/neutral/neutralTheme.ts
index 5b562372e7..206545a246 100644
--- a/packages/cli/assets/templates/themes/neutral/neutralTheme.ts
+++ b/packages/cli/assets/templates/themes/neutral/neutralTheme.ts
@@ -528,15 +528,17 @@ export const neutralTheme = defineTheme({
// to a deep tinted bg + light text rather than locking the
// light-mode pastel.
//
- // The inner-header *-muted token is forced transparent so the outer
- // tinted background shows through cleanly.
+ // The inner-header *-muted token carries the tinted background for every
+ // status, info included. A theme override that sets a plain CSS property
+ // instead lands in @layer astryx-theme, which StyleX's @layer priority4
+ // outranks, so `backgroundColor` here would silently do nothing and the
+ // info banner would paint no background at all.
//
// Status overrides reference --color-text-{hue} so text/icon colors
// stay in sync with the palette anchors automatically.
banner: {
'status:info': {
- backgroundColor: 'var(--color-background-blue)',
- '--color-accent-muted': 'transparent',
+ '--color-accent-muted': 'var(--color-background-blue)',
'--color-text-primary': 'var(--color-text-blue)',
'--color-text-secondary': 'var(--color-text-blue)',
'--color-accent': 'var(--color-text-blue)',
diff --git a/packages/core/src/Banner/Banner.doc.mjs b/packages/core/src/Banner/Banner.doc.mjs
index ebfc833347..51ad89bd33 100644
--- a/packages/core/src/Banner/Banner.doc.mjs
+++ b/packages/core/src/Banner/Banner.doc.mjs
@@ -17,11 +17,13 @@ export const docs = {
{guidance: true, description: 'Keep titles short and scannable: "Payment failed" not "There was a problem processing your most recent payment."'},
{guidance: false, description: 'Use Banner for short-lived messages that disappear on their own; use Toast instead.'},
{guidance: false, description: 'Stack multiple banners with the same status; combine related messages into one banner.'},
+ {guidance: true, description: 'Error and warning banners render as role="alert"; info and success render as role="status". Mount an alert banner in response to an event rather than on first paint, so assistive tech has a change to report.'},
+ {guidance: false, description: 'Rely on the status color or icon alone to carry meaning; say which status it is in the title text, because the icon is decorative to a screen reader.'},
],
anatomy: [
{name: 'Icon', required: true, description: 'Automatically set based on the status (info, warning, error, success).'},
- {name: 'Title', required: false, description: 'The main message. Required if no description is provided.'},
- {name: 'Description', required: false, description: 'Additional detail below the title. Required if no title is provided.'},
+ {name: 'Title', required: true, description: 'The main message. Always required.'},
+ {name: 'Description', required: false, description: 'Additional detail below the title.'},
{name: 'Action button', required: false, description: 'A button for the user to act on the message, like "Review" or "Retry".'},
{name: 'Dismiss button', required: false, description: 'Lets the user close the banner. Enabled by setting isDismissable.'},
{name: 'Collapsible content', required: false, description: 'Extra detail that expands below the banner header, like a list of errors.'},
@@ -123,7 +125,7 @@ export const docs = {
{className: 'astryx-banner-content', visualProps: ['container', 'status']},
],
vars: [
- {name: '--_banner-radius', description: 'Border radius (card container only)', default: 'var(--radius-container)', private: true},
+ {name: '--_banner-radius', description: 'Border radius of the card container (header, content area and the elevated root silhouette)', default: 'var(--radius-container)', private: true},
],
derived: [
{property: 'borderRadius', vars: ['--_banner-radius']},
@@ -148,8 +150,8 @@ export const docsZh = {
],
anatomy: [
{name: 'Icon', required: true, description: 'Automatically set based on the status (info, warning, error, success).'},
- {name: 'Title', required: false, description: 'The main message. Required if no description is provided.'},
- {name: 'Description', required: false, description: 'Additional detail below the title. Required if no title is provided.'},
+ {name: 'Title', required: true, description: 'The main message. Always required.'},
+ {name: 'Description', required: false, description: 'Additional detail below the title.'},
{name: 'Action button', required: false, description: 'A button for the user to act on the message, like "Review" or "Retry".'},
{name: 'Dismiss button', required: false, description: 'Lets the user close the banner. Enabled by setting isDismissable.'},
{name: 'Collapsible content', required: false, description: 'Extra detail that expands below the banner header, like a list of errors.'},
@@ -198,7 +200,7 @@ export const docsZh = {
},
],
vars: [
- {name: '--_banner-radius', description: 'Border radius (card container only)', default: 'var(--radius-container)', private: true},
+ {name: '--_banner-radius', description: 'Border radius of the card container (header, content area and the elevated root silhouette)', default: 'var(--radius-container)', private: true},
],
derived: [
{property: 'borderRadius', vars: ['--_banner-radius']},
@@ -222,7 +224,7 @@ export const docsDense = {
],
anatomy: [
{name: 'Icon', required: true, description: 'Set automatically from status.'},
- {name: 'Title', required: false, description: 'Main message text.'},
+ {name: 'Title', required: true, description: 'Main message text.'},
{name: 'Description', required: false, description: 'Detail below title.'},
{name: 'Action button', required: false, description: 'CTA like Review or Retry.'},
{name: 'Dismiss button', required: false, description: 'Close button via isDismissable.'},
diff --git a/packages/core/src/Banner/Banner.test.tsx b/packages/core/src/Banner/Banner.test.tsx
index 9fd7309786..916978174e 100644
--- a/packages/core/src/Banner/Banner.test.tsx
+++ b/packages/core/src/Banner/Banner.test.tsx
@@ -455,4 +455,72 @@ describe('Banner', () => {
);
});
});
+
+ describe('dismiss focus handoff', () => {
+ it('returns focus to where it came from instead of dropping it to body', async () => {
+ const user = userEvent.setup();
+ render(
+ <>
+ <button type="button">Before</button>
+ <Banner status="info" title="Heads up" isDismissable />
+ </>,
+ );
+ const before = screen.getByRole('button', {name: 'Before'});
+ before.focus();
+
+ await user.tab();
+ expect(screen.getByRole('button', {name: 'Dismiss'})).toHaveFocus();
+
+ await user.keyboard('{Enter}');
+
+ expect(screen.queryByRole('status')).not.toBeInTheDocument();
+ expect(before).toHaveFocus();
+ expect(document.activeElement).not.toBe(document.body);
+ });
+
+ it('leaves focus alone when it never entered the banner', async () => {
+ const user = userEvent.setup();
+ render(
+ <>
+ <button type="button">Elsewhere</button>
+ <Banner status="info" title="Heads up" isDismissable />
+ </>,
+ );
+ await user.click(screen.getByRole('button', {name: 'Dismiss'}));
+ expect(screen.queryByRole('status')).not.toBeInTheDocument();
+ });
+ });
+
+ describe('empty slots', () => {
+ it('does not show the expand affordance for children that render nothing', () => {
+ render(
+ <Banner status="info" title="Heads up">
+ {false}
+ </Banner>,
+ );
+ expect(
+ screen.queryByRole('button', {name: 'Expand'}),
+ ).not.toBeInTheDocument();
+ });
+
+ it('still shows the expand affordance for real children', () => {
+ render(
+ <Banner status="info" title="Heads up">
+ <p>Detail</p>
+ </Banner>,
+ );
+ expect(
+ screen.getByRole('button', {name: 'Expand'}),
+ ).toBeInTheDocument();
+ });
+
+ it('renders no description node for a description that renders nothing', () => {
+ const {container} = render(
+ <Banner status="info" title="Heads up" description="" />,
+ );
+ const header = container.firstElementChild!.firstElementChild!;
+ // icon wrapper + text column, and the text column holds the title alone
+ expect(header.children[1].children).toHaveLength(1);
+ });
+ });
});
diff --git a/packages/core/src/Banner/Banner.tsx b/packages/core/src/Banner/Banner.tsx
index 768b800c4a..06d6d3eec6 100644
--- a/packages/core/src/Banner/Banner.tsx
+++ b/packages/core/src/Banner/Banner.tsx
@@ -4,7 +4,7 @@
/**
* @file Banner.tsx
- * @input Uses React useState, Button, Icon (with registry string names), StyleX
+ * @input Uses React useState/useRef/useId, Button, Icon (with registry string names), StyleX
* @output Exports Banner component, BannerProps, BannerStatus, BannerContainer types
* @position Core implementation; consumed by index.ts, tested by Banner.test.tsx
*
@@ -19,6 +19,10 @@
* - Each visual area owns its own border-radius (no overflow:clip on the container)
* - When children are provided, a collapse/expand toggle button appears in the end area
*
+ * A status added through `BannerStatusMap` augmentation has no entry in the
+ * status lookups, so it renders with no status fill, no default glyph and the
+ * polite `role="status"` rather than losing its ARIA role entirely.
+ *
* Title and description render as <div> (not <p>): they accept arbitrary
* ReactNode content, and <p> cannot legally contain block-level children
* (the HTML parser reparents them, desyncing SSR markup from the hydrated
@@ -34,12 +38,12 @@
* - /packages/cli/assets/templates/blocks/components/Banner/ (showcase blocks)
*/
-import {useId, useState, type ReactNode} from 'react';
+import {useId, useRef, useState, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {BaseProps} from '../BaseProps';
import {Button} from '../Button';
import {Icon} from '../Icon';
-import type {IconName} from '../Icon';
+import type {IconName, IconColor} from '../Icon';
import {
colorVars,
spacingVars,
@@ -51,7 +55,7 @@ import {
easeVars,
shadowVars,
} from '../theme/tokens.stylex';
-import {mergeProps} from '../utils';
+import {composeEventHandlers, isRenderable, mergeProps} from '../utils';
import type {Elevation} from '../utils/types';
import {edgeCompSlot} from '../Layout/edgeCompensation.stylex';
import {themeProps} from '../utils/themeProps';
@@ -147,37 +151,38 @@ export interface BannerProps extends BaseProps<HTMLDivElement> {
}
// =============================================================================
-// Status → Icon mapping
+// Status lookups
// =============================================================================
-const defaultIconNames: Record<BannerStatus, IconName> = {
+// `BannerStatus` is `keyof BannerStatusMap`, and index.ts documents augmenting
+// that interface to add a status. Every lookup below is therefore partial: an
+// augmented status the library has never heard of falls through to the base
+// treatment (no status fill, no glyph, the polite role) instead of resolving to
+// `undefined` and dropping the ARIA role along with it.
+
+const defaultIconNames: Partial<Record<BannerStatus, IconName>> = {
info: 'info',
warning: 'warning',
error: 'error',
success: 'success',
};
-// =============================================================================
-// Status → ARIA role mapping
-// =============================================================================
-
-const statusRole: Record<BannerStatus, 'alert' | 'status'> = {
+const statusRole: Partial<Record<BannerStatus, 'alert' | 'status'>> = {
info: 'status',
warning: 'alert',
error: 'alert',
success: 'status',
};
-// =============================================================================
-// Status → Icon color mapping
-// =============================================================================
+/** An unknown status is not urgent by definition, so it announces politely. */
+const FALLBACK_ROLE = 'status';
-const statusIconColor = {
+const statusIconColor: Partial<Record<BannerStatus, IconColor>> = {
info: 'accent',
warning: 'warning',
error: 'error',
success: 'success',
-} as const;
+};
// =============================================================================
// Styles
@@ -193,7 +198,7 @@ const styles = stylex.create({
// When elevated, a card-container banner rounds its root so the shadow
// follows the same silhouette as the header/content border-radius.
rootElevatedCard: {
- borderRadius: radiusVars['--radius-container'],
+ borderRadius: `var(--_banner-radius, ${radiusVars['--radius-container']})`,
},
// Header area — colored status background with icon, title, description, actions
// This is the primary theme target ('banner')
@@ -206,11 +211,11 @@ const styles = stylex.create({
},
// Border-radius for card container: all corners when standalone, top-only when content is visible
headerCardStandalone: {
- borderRadius: radiusVars['--radius-container'],
+ borderRadius: `var(--_banner-radius, ${radiusVars['--radius-container']})`,
},
headerCardWithContent: {
- borderStartStartRadius: radiusVars['--radius-container'],
- borderStartEndRadius: radiusVars['--radius-container'],
+ borderStartStartRadius: `var(--_banner-radius, ${radiusVars['--radius-container']})`,
+ borderStartEndRadius: `var(--_banner-radius, ${radiusVars['--radius-container']})`,
borderEndStartRadius: 0,
borderEndEndRadius: 0,
},
@@ -233,6 +238,10 @@ const styles = stylex.create({
fontWeight: fontWeightVars['--font-weight-semibold'],
lineHeight: typeScaleVars['--text-label-leading'],
color: colorVars['--color-text-primary'],
+ // A single unbroken token (a URL, an ID, a German compound) otherwise sets
+ // the flex item's min-content width and pushes the page into horizontal
+ // scrolling at 320px, which is a WCAG 1.4.10 reflow failure.
+ overflowWrap: 'anywhere',
},
description: {
margin: 0,
@@ -241,6 +250,7 @@ const styles = stylex.create({
fontWeight: fontWeightVars['--font-weight-normal'],
lineHeight: typeScaleVars['--text-supporting-leading'],
color: colorVars['--color-text-secondary'],
+ overflowWrap: 'anywhere',
},
iconWrapper: {
display: 'flex',
@@ -262,17 +272,17 @@ const styles = stylex.create({
paddingInline: spacingVars['--spacing-4'],
borderInlineStartWidth: borderVars['--border-width'],
borderInlineEndWidth: borderVars['--border-width'],
- borderBottomWidth: borderVars['--border-width'],
+ borderBlockEndWidth: borderVars['--border-width'],
borderInlineStartStyle: 'solid',
borderInlineEndStyle: 'solid',
- borderBottomStyle: 'solid',
+ borderBlockEndStyle: 'solid',
borderInlineStartColor: colorVars['--color-border'],
borderInlineEndColor: colorVars['--color-border'],
- borderBottomColor: colorVars['--color-border'],
+ borderBlockEndColor: colorVars['--color-border'],
},
contentAreaCard: {
- borderEndStartRadius: radiusVars['--radius-container'],
- borderEndEndRadius: radiusVars['--radius-container'],
+ borderEndStartRadius: `var(--_banner-radius, ${radiusVars['--radius-container']})`,
+ borderEndEndRadius: `var(--_banner-radius, ${radiusVars['--radius-container']})`,
},
// Applied to the chevron <Icon> itself (via `xstyle`) rather than a wrapper,
// so the element that rotates is the element a theme targets.
@@ -304,6 +314,17 @@ const statusStyles = stylex.create({
},
});
+/**
+ * Narrows an augmented `BannerStatus` to one the style map actually carries,
+ * so an unknown status renders with no status fill rather than crashing the
+ * lookup. StyleX style maps cannot be declared `Partial`, hence the guard.
+ */
+function hasStatusStyle(
+ status: BannerStatus,
+): status is BannerStatus & keyof typeof statusStyles {
+ return Object.prototype.hasOwnProperty.call(statusStyles, status);
+}
+
// Resting elevation for the banner. Applied to the root so the shadow wraps
// the whole banner (header + optional content). 'none' is the default and
// leaves the layout-only root untouched. For the `card` container the root is
@@ -381,28 +402,63 @@ export function Banner({
className,
style,
ref,
+ onFocusCapture,
+ onPointerDownCapture,
...rest
}: BannerProps) {
const t = useTranslator();
const [isDismissed, setIsDismissed] = useState(false);
const [isExpanded, setIsExpanded] = useState(defaultIsExpanded);
+ // The element focus came from before it entered the banner. Dismissing
+ // unmounts the whole banner, dismiss button included, so without a handoff
+ // the browser drops focus to <body> and a keyboard user loses their place.
+ // ToastViewport makes the same handoff when a focused toast is dismissed.
+ const focusOriginRef = useRef<HTMLElement | null>(null);
// Links the expand/collapse toggle to the content region it shows/hides so
// assistive tech can move from the button to its controlled content
// (disclosure pattern). The region is conditionally rendered, so aria-controls
// below is set only while it's mounted to avoid a dangling reference.
const contentId = useId();
const defaultIconName = defaultIconNames[status];
- const role = statusRole[status];
+ const role = statusRole[status] ?? FALLBACK_ROLE;
const iconColor = statusIconColor[status];
- const hasChildren = children != null;
+ const hasChildren = isRenderable(children);
if (isDismissed) {
return null;
}
+ // `focusin` reports the element focus came *from* as relatedTarget; on
+ // pointerdown focus has not moved yet, so document.activeElement is it.
+ const rememberFocusOrigin = (candidate: EventTarget | null, root: Node) => {
+ if (
+ candidate instanceof HTMLElement &&
+ candidate !== document.body &&
+ !root.contains(candidate)
+ ) {
+ focusOriginRef.current = candidate;
+ }
+ };
+
+ const handleFocusCapture = (event: React.FocusEvent<HTMLDivElement>) => {
+ rememberFocusOrigin(event.relatedTarget, event.currentTarget);
+ };
+
+ const handlePointerDownCapture = (
+ event: React.PointerEvent<HTMLDivElement>,
+ ) => {
+ rememberFocusOrigin(document.activeElement, event.currentTarget);
+ };
+
const handleDismiss = () => {
+ const origin = focusOriginRef.current;
setIsDismissed(true);
onDismiss?.();
+ // Move focus before React removes the subtree, so the browser never has a
+ // frame where the focused node is gone.
+ if (origin?.isConnected) {
+ origin.focus();
+ }
};
const handleToggleExpand = () => {
@@ -410,11 +466,11 @@ export function Banner({
};
// Show the end area if there are actions, dismiss, or a collapsible toggle
- const showEndArea = endContent != null || isDismissable || hasChildren;
+ const showEndArea = isRenderable(endContent) || isDismissable || hasChildren;
// Center items vertically when there's only a title (no description)
// and the banner has action buttons
- const hasActions = endContent != null || isDismissable;
- const isSingleLine = description == null && hasActions;
+ const hasActions = isRenderable(endContent) || isDismissable;
+ const isSingleLine = !isRenderable(description) && hasActions;
const showContent = hasChildren && isExpanded;
const isCard = container === 'card';
@@ -423,6 +479,11 @@ export function Banner({
<div
ref={ref}
role={role}
+ onFocusCapture={composeEventHandlers(onFocusCapture, handleFocusCapture)}
+ onPointerDownCapture={composeEventHandlers(
+ onPointerDownCapture,
+ handlePointerDownCapture,
+ )}
{...mergeProps(
stylex.props(
styles.root,
@@ -441,7 +502,7 @@ export function Banner({
stylex.props(
styles.header,
isSingleLine && styles.headerCentered,
- statusStyles[status],
+ hasStatusStyle(status) && statusStyles[status],
isCard &&
(showContent
? styles.headerCardWithContent
@@ -454,16 +515,16 @@ export function Banner({
overrides reach it via inheritance). The wrapper itself stays
layout-only. */}
<div
- {...(icon != null
+ {...(isRenderable(icon)
? mergeProps(
themeProps('banner-icon', {status}),
stylex.props(styles.iconWrapper),
)
: stylex.props(styles.iconWrapper))}
aria-hidden="true">
- {icon != null ? (
+ {isRenderable(icon) ? (
icon
- ) : (
+ ) : defaultIconName != null ? (
// Applied to the status <Icon> itself rather than the wrapper, so
// the element that paints the glyph is the element a theme
// targets — a 'banner-icon' 'status:X' color override beats the
@@ -474,11 +535,11 @@ export function Banner({
color={iconColor}
{...themeProps('banner-icon', {status})}
/>
- )}
+ ) : null}
</div>
<div {...stylex.props(styles.headerContent)}>
<div {...stylex.props(styles.title)}>{title}</div>
- {description != null && (
+ {isRenderable(description) && (
<div {...stylex.props(styles.description)}>{description}</div>
)}
</div>
diff --git a/packages/core/src/Banner/index.ts b/packages/core/src/Banner/index.ts
index 5eba048189..acf637ac17 100644
--- a/packages/core/src/Banner/index.ts
+++ b/packages/core/src/Banner/index.ts
@@ -11,19 +11,6 @@
* SYNC: When modified, update this header and /packages/core/src/Banner/Banner.doc.mjs
*/
-/**
- * Extensible status map for Banner.
- *
- * Theme packages can add custom statuses via TypeScript module augmentation:
- * @example
- * ```
- * declare module '@astryxdesign/core/Banner' {
- * interface BannerStatusMap {
- * 'neutral': true;
- * }
- * }
- * ```
- */
/**
* Extensible container map for Banner.
*
@@ -42,6 +29,21 @@ export interface BannerContainerMap {
section: true;
}
+/**
+ * Extensible status map for Banner.
+ *
+ * Theme packages can add custom statuses via TypeScript module augmentation.
+ * A status the library does not know falls through to the base treatment: no
+ * status fill, no default glyph, and `role="status"`.
+ * @example
+ * ```
+ * declare module '@astryxdesign/core/Banner' {
+ * interface BannerStatusMap {
+ * 'neutral': true;
+ * }
+ * }
+ * ```
+ */
export interface BannerStatusMap {
info: true;
warning: true;
diff --git a/packages/themes/neutral/src/neutralTheme.ts b/packages/themes/neutral/src/neutralTheme.ts
index 5b562372e7..206545a246 100644
--- a/packages/themes/neutral/src/neutralTheme.ts
+++ b/packages/themes/neutral/src/neutralTheme.ts
@@ -528,15 +528,17 @@ export const neutralTheme = defineTheme({
// to a deep tinted bg + light text rather than locking the
// light-mode pastel.
//
- // The inner-header *-muted token is forced transparent so the outer
- // tinted background shows through cleanly.
+ // The inner-header *-muted token carries the tinted background for every
+ // status, info included. A theme override that sets a plain CSS property
+ // instead lands in @layer astryx-theme, which StyleX's @layer priority4
+ // outranks, so `backgroundColor` here would silently do nothing and the
+ // info banner would paint no background at all.
//
// Status overrides reference --color-text-{hue} so text/icon colors
// stay in sync with the palette anchors automatically.
banner: {
'status:info': {
- backgroundColor: 'var(--color-background-blue)',
- '--color-accent-muted': 'transparent',
+ '--color-accent-muted': 'var(--color-background-blue)',
'--color-text-primary': 'var(--color-text-blue)',
'--color-text-secondary': 'var(--color-text-blue)',
'--color-accent': 'var(--color-text-blue)',