Skip to content

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

TypeScript

fix(Banner): contain status foregrounds (#8772)

rubyycheungd6004fdc2dbf
diff --git a/.changeset/banner-end-content-foreground.md b/.changeset/banner-end-content-foreground.md
new file mode 100644
index 0000000000..e6505f1ca0
--- /dev/null
+++ b/.changeset/banner-end-content-foreground.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Keep `Banner` status foreground colors scoped to Banner-owned content so consumer `endContent`, including nested dialogs, retains its own text color.
+
+@rubyycheung
diff --git a/packages/core/src/Banner/Banner.test.tsx b/packages/core/src/Banner/Banner.test.tsx
index 3a164a215a..87c98ae9f0 100644
--- a/packages/core/src/Banner/Banner.test.tsx
+++ b/packages/core/src/Banner/Banner.test.tsx
@@ -5,9 +5,9 @@
* @input Uses vitest, @testing-library/react, Banner component
* @output Unit tests for Banner component behavior, including default and
* explicit live-region roles, augmented-status color fallback, scoped status
- * control context that does not recolor tooltips, the 'banner-frame' theme
- * target on the outer elevation/radius painter, and the 'banner-icon' theme
- * target on the status icon glyph (#4166)
+ * foregrounds that do not recolor consumer content or tooltips, the
+ * 'banner-frame' theme target on the outer elevation/radius painter, and the
+ * 'banner-icon' theme target on the status icon glyph (#4166)
* @position Testing; validates Banner.tsx implementation
*
* SYNC: When modified, update this header
@@ -229,22 +229,41 @@ describe('Banner', () => {
expect(screen.queryByRole('button', {name: /^Dismiss/})).toBeNull();
});
- it('leaves consumer endContent outside the built-in status control context', () => {
+ it('leaves consumer endContent outside the built-in status foreground', () => {
render(
- <Banner
- status="success"
- title="With Action"
- endContent={
- <button type="button" data-testid="end-btn">
- Action
- </button>
- }
- />,
+ <>
+ <style>{'dialog { color: inherit; }'}</style>
+ <Banner
+ status="warning"
+ title="Warning action"
+ endContent={
+ <dialog open data-testid="warning-dialog">
+ Consumer dialog
+ </dialog>
+ }
+ />
+ <Banner
+ status="error"
+ title="Error action"
+ endContent={
+ <dialog open data-testid="error-dialog">
+ Consumer dialog
+ </dialog>
+ }
+ />
+ </>,
+ );
+
+ const warningTitle = screen.getByText('Warning action');
+ const errorTitle = screen.getByText('Error action');
+ const warningDialog = screen.getByTestId('warning-dialog');
+ const errorDialog = screen.getByTestId('error-dialog');
+
+ expect(getComputedStyle(warningTitle).color).not.toBe(
+ getComputedStyle(errorTitle).color,
);
- const action = screen.getByTestId('end-btn');
- expect(action).toBeInTheDocument();
- expect(action.className).not.toContain(
- 'Banner__statusControlStyles.success',
+ expect(getComputedStyle(warningDialog).color).toBe(
+ getComputedStyle(errorDialog).color,
);
});
diff --git a/packages/core/src/Banner/Banner.tsx b/packages/core/src/Banner/Banner.tsx
index 1802decf14..b787a740aa 100644
--- a/packages/core/src/Banner/Banner.tsx
+++ b/packages/core/src/Banner/Banner.tsx
@@ -12,6 +12,7 @@
* - Banner frame (themeProps 'banner-frame'): owns the resting elevation and,
* for elevated card banners, the outer radius that shapes that shadow
* - Header area (themeProps 'banner'): colored status background with icon, title, description, actions, dismiss
+ * - End area restores the ordinary text context for consumer `endContent`; built-in controls opt back into the status foreground
* - Content area (themeProps 'banner-content'): card background for additional content (children)
* - Status icon (themeProps 'banner-icon'): the target rides on the default
* <Icon> itself — the element that paints — so 'status:X' overrides reach
@@ -313,6 +314,10 @@ const styles = stylex.create({
justifyContent: 'flex-end',
gap: spacingVars['--spacing-2'],
flexShrink: 0,
+ // The status surface owns an inherited on-muted foreground, but consumer
+ // endContent does not. Reset the end area's ordinary text context, then let
+ // the built-in controls below opt back into the status foreground.
+ color: colorVars['--color-text-primary'],
// 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%',