Skip to content

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

TypeScript

fix(theme): baseline media theme color-scheme flip in reset.css (#1921)

Cindy Zhang87bbfea16caf
diff --git a/packages/core/src/reset.css b/packages/core/src/reset.css
index 0fbd5ff3fb..b63920de4b 100644
--- a/packages/core/src/reset.css
+++ b/packages/core/src/reset.css
@@ -385,4 +385,21 @@
:where(html:not([data-theme])) {
color-scheme: light dark;
}
+
+ /* ===========================================================================
+ Media Theme Baseline
+ =========================================================================== */
+
+ /*
+ * color-scheme flip for [data-xds-media] — makes light-dark() base
+ * tokens resolve correctly on inverted surfaces without a theme.
+ * Token overrides (text/icon/accent) are theme-level (generateOnMediaCSS).
+ */
+ :where([data-xds-media="dark"]) {
+ color-scheme: dark;
+ }
+
+ :where([data-xds-media="light"]) {
+ color-scheme: light;
+ }
}
diff --git a/packages/core/src/theme/onMediaTokens.test.ts b/packages/core/src/theme/onMediaTokens.test.ts
index 20610a8767..65b23b9ef6 100644
--- a/packages/core/src/theme/onMediaTokens.test.ts
+++ b/packages/core/src/theme/onMediaTokens.test.ts
@@ -168,7 +168,9 @@ describe('generateOnMediaCSS', () => {
});
const css = generateOnMediaCSS(theme);
expect(css).toContain('[data-xds-media="dark"] .xds-button.secondary');
- expect(css).toContain('background-color: color-mix(in srgb, white 20%, transparent)');
+ expect(css).toContain(
+ 'background-color: color-mix(in srgb, white 20%, transparent)',
+ );
});
it('emits pseudo-class rules for on-media components', () => {
@@ -190,3 +192,48 @@ describe('generateOnMediaCSS', () => {
expect(css).toContain('color: rgba(255,255,255,0.8)');
});
});
+
+describe('reset.css baseline media rules', () => {
+ /**
+ * Validates that reset.css provides the minimum baseline for
+ * XDSMediaTheme: a color-scheme flip on [data-xds-media].
+ *
+ * Token overrides (text-primary, icon-primary, accent) are a
+ * theme-level concern — themes handle those via generateOnMediaCSS.
+ */
+ let resetCSS: string;
+
+ beforeAll(async () => {
+ const fs = await import('fs');
+ const path = await import('path');
+ resetCSS = fs.readFileSync(
+ path.resolve(__dirname, '../reset.css'),
+ 'utf-8',
+ );
+ });
+
+ it('flips color-scheme on [data-xds-media="dark"]', () => {
+ const darkMatch = resetCSS.match(
+ /:where\(\[data-xds-media="dark"\]\)\s*\{([^}]+)\}/,
+ );
+ expect(darkMatch).not.toBeNull();
+ expect(darkMatch![1]).toContain('color-scheme: dark');
+ });
+
+ it('flips color-scheme on [data-xds-media="light"]', () => {
+ const lightMatch = resetCSS.match(
+ /:where\(\[data-xds-media="light"\]\)\s*\{([^}]+)\}/,
+ );
+ expect(lightMatch).not.toBeNull();
+ expect(lightMatch![1]).toContain('color-scheme: light');
+ });
+
+ it('does NOT include token overrides at baseline level', () => {
+ const darkMatch = resetCSS.match(
+ /:where\(\[data-xds-media="dark"\]\)\s*\{([^}]+)\}/,
+ );
+ expect(darkMatch![1]).not.toContain('--color-text-primary');
+ expect(darkMatch![1]).not.toContain('--color-icon-primary');
+ expect(darkMatch![1]).not.toContain('--color-accent');
+ });
+});