Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
de9bf69
fix(Tooltip): content keeps contrast on the inverted surface
cixzhang Nov 17, 2026
28ddf08
fix(Tooltip): keep the media-side helper inside useTooltip
cixzhang Nov 17, 2026
63e5d50
fix(Tooltip): measure the content's media side inside the open layer;…
cixzhang Nov 17, 2026
80b6792
fix(Tooltip): content reads the media tokens and keeps the surface te…
cixzhang Nov 17, 2026
805e5f9
fix(Tooltip): string and number content renders without the media wra…
cixzhang Nov 17, 2026
f9d7d99
docs(Tooltip): the media wrapper comment says it renders while closed
cixzhang Nov 18, 2026
c9fae25
Merge remote-tracking branch 'refs/remotes/l4/main-new' into lane4/pr…
cixzhang Nov 18, 2026
22494e5
perf(Tooltip): the media context adds about 0.4 to 1.3 KB to a page, …
cixzhang Nov 18, 2026
fc6ef3b
Merge main into #12410
cixzhang Nov 19, 2026
d28b067
Merge main into fix-tooltip-content-contrast
cixzhang Dec 1, 2026
2a718c7
fix(Tooltip): the content's side follows the theme's surface in the p…
cixzhang Dec 1, 2026
2212a34
fix(Tooltip): keep the side code local to Tooltip and out of the firs…
cixzhang Dec 2, 2026
d849f49
docs(Tooltip): record the content contrast gap before the side module…
cixzhang Dec 2, 2026
305ce5e
fix(Tooltip): content takes the surface's text color until its side i…
cixzhang Dec 2, 2026
499e914
docs(Tooltip): the pre-measurement content color is unmuted
cixzhang Dec 2, 2026
0ff348c
chore(changeset): name the CLI for the Gothic and Matcha theme templates
cixzhang Dec 2, 2026
4abee12
perf(Tooltip): import the media side statically; no loader and no aft…
cixzhang Dec 3, 2026
6e51074
probe: surface-only content colors, no measurement (size probe, not f…
cixzhang Dec 3, 2026
bb8f887
wip: tooltip text derivation
cixzhang Dec 3, 2026
5fd30c0
card-depth A: tooltip text tokens derived per theme; tooltip content …
cixzhang Dec 3, 2026
45000d8
card-depth A v2: grammar names (--color-text-*-inverted); mapping on …
cixzhang Dec 3, 2026
1e53364
card-depth A v3: render tooltip children directly; deps as on main (d…
cixzhang Dec 3, 2026
5739253
fix(Tooltip): token-colored content takes the theme's text roles for …
cixzhang Dec 3, 2026
65efcd0
Merge main into fix-tooltip-content-contrast
cixzhang Dec 3, 2026
a901598
docs(theme-tokens): INV15 records the text roles on the inverted surf…
cixzhang Dec 3, 2026
be8899d
fix(Tooltip): token docs list the inverted text roles; the derivation…
cixzhang Dec 3, 2026
17f3965
chore(changeset): name the CLI, whose token docs list the inverted roles
cixzhang Dec 3, 2026
9792af4
chore(Tooltip): narrow the changeset to the roles it moves; drop the …
cixzhang Dec 3, 2026
e9540c4
chore(theme): the derivation header names no record
cixzhang Dec 3, 2026
ad35457
fix(themes): Butter, Gothic, Matcha, Stone and Y2K set the inverted t…
cixzhang Dec 3, 2026
19f5653
fix(theme): share the readable-ink and ratio helpers; regenerate the …
cixzhang Dec 3, 2026
8718581
style(theme): format statusColor.ts
cixzhang Dec 3, 2026
d587f48
docs(Tooltip): bound the inverted text roles to primary, secondary an…
cixzhang Dec 3, 2026
b8d3143
docs(theme-tokens): INV15 scopes to tooltip content and to themes who…
cixzhang Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tooltip-content-media-theme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
---

[fix] Tooltip content is readable when it uses `Text` or other token-colored components, as the Tooltip docs show. The content now renders inside a `MediaTheme` on the side whose text reads best on the tooltip's inverted surface, as Toast's content does. Before, `<Text>` content took the page theme's primary text color, which is the color of the tooltip surface, so the tooltip looked empty in light and dark. Plain-text tooltips now use that side's primary text color, which can differ slightly from the page surface color they used before.

@cixzhang
44 changes: 44 additions & 0 deletions apps/storybook/stories/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type {Meta, StoryObj} from '@storybook/react';
import {Tooltip, useTooltip} from '@astryxdesign/core/Tooltip';
import {Button} from '@astryxdesign/core/Button';
import {HStack} from '@astryxdesign/core/Layout';
import {Text} from '@astryxdesign/core/Text';
import {Icon} from '@astryxdesign/core/Icon';

const meta: Meta<typeof Tooltip> = {
title: 'Core/Tooltip',
Expand Down Expand Up @@ -416,3 +418,45 @@ export const TouchTriggers: Story = {
</div>
),
};

/**
* Rich content on the inverted surface: a plain string, the docs' `Text`
* example, default and secondary `Text`, and an icon with text stay readable
* in light and dark.
*/
export const RichContent: Story = {
render: () => (
<div style={{padding: '80px 24px'}}>
<HStack gap={4}>
<Tooltip content="Plain string" isDefaultOpen>
<Button label="Plain string" />
</Tooltip>
<Tooltip content={<Text type="body">Body text</Text>} isDefaultOpen>
<Button label="Text body" />
</Tooltip>
<Tooltip content={<Text>Default text</Text>} isDefaultOpen>
<Button label="Text default" />
</Tooltip>
<Tooltip
content={
<Text type="supporting" color="secondary">
Secondary text
</Text>
}
isDefaultOpen>
<Button label="Text secondary" />
</Tooltip>
<Tooltip
content={
<HStack gap={1}>
<Icon icon="calendar" size="sm" />
<Text type="body">With icon</Text>
</HStack>
}
isDefaultOpen>
<Button label="Icon and text" />
</Tooltip>
</HStack>
</div>
),
};
88 changes: 88 additions & 0 deletions packages/core/src/Tooltip/Tooltip.mediaTheme.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/**
* @file Tooltip.mediaTheme.test.tsx
* @input Tooltip with `Text` content under themes whose inverted surface is
* dark or light, in either color mode
* @output Proves that the supplied content renders inside a MediaTheme whose
* side reads on the tooltip's inverted surface, so token-colored content
* such as `Text` does not take the surface's own color
* @position Unit test for the tooltip content's media context
*/

import {describe, expect, it} from 'vitest';
import {render, screen} from '@testing-library/react';
import {Theme, defineTheme} from '../theme';
import {Text} from '../Text/Text';
import {MediaTheme} from '../theme/MediaTheme';
import {Tooltip} from './Tooltip';

/** A theme whose inverted surface is `surface` in both modes. */
const withSurface = (surface: string) => ({
...defineTheme({
name: `tooltip-surface-${surface.replace(/[^a-z0-9]+/gi, '-')}`,
tokens: {
'--color-background-inverted': [surface, surface],
'--color-on-dark': ['#ffffff', '#ffffff'],
'--color-on-light': ['#111111', '#111111'],
},
}),
__built: true as const,
});

const mediaOfContent = (
theme: ReturnType<typeof withSurface>,
mode: 'light' | 'dark',
) => {
render(
<Theme theme={theme} mode={mode}>
<Tooltip content={<Text type="body">Content text</Text>} isDefaultOpen>
<button type="button">Trigger</button>
</Tooltip>
</Theme>,
);
return screen
.getByText('Content text')
.closest('[data-astryx-media]')
?.getAttribute('data-astryx-media');
};

describe('Tooltip content media context', () => {
it('a dark inverted surface gives Text content light text in a light page', () => {
expect(mediaOfContent(withSurface('#0a1317'), 'light')).toBe('dark');
});

it('a dark inverted surface in a dark page still gives light text', () => {
expect(mediaOfContent(withSurface('#0a1317'), 'dark')).toBe('dark');
});

it('a light inverted surface gives Text content dark text', () => {
expect(mediaOfContent(withSurface('#f4f0e8'), 'dark')).toBe('light');
});

it('a surface the theme cannot resolve starts from the color mode', () => {
expect(mediaOfContent(withSurface('oklch(0.2 0.01 230)'), 'light')).toBe(
'dark',
);
});

it('content that already holds a MediaTheme keeps its own and gets no second one', () => {
render(
<Theme theme={withSurface('#0a1317')} mode="light">
<Tooltip
content={
<MediaTheme mode="light">
<Text type="body">Own context</Text>
</MediaTheme>
}
isDefaultOpen>
<button type="button">Trigger</button>
</Tooltip>
</Theme>,
);
const text = screen.getByText('Own context');
const media = text.closest('[data-astryx-media]');
expect(media?.getAttribute('data-astryx-media')).toBe('light');
expect(media?.parentElement?.closest('[data-astryx-media]')).toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
// @pr-a11y scope ^packages/core/src/theme/ ^packages/themes/

/**
* @file TooltipContentContrast.a11y.chromium.spec.ts
* @input The built `Core/Tooltip` RichContent story in every shipped theme,
* light and dark: a plain string, the docs' `Text` example, default and
* secondary `Text`, and an icon with text, each in an open tooltip
* @output Chromium proof that text in a tooltip meets WCAG AA (4.5:1) and an
* icon meets 3:1 against the tooltip's painted surface
* @position Content colors come from the media context around the content.
* Only a real engine resolves the theme tokens and the painted surface, so
* the measure runs in a browser.
*
* SYNC: Fixture lives in /apps/storybook/stories/Tooltip.stories.tsx
* (RichContent).
*/

import {expect, test, type Page} from '@astryxdesign/a11y-spec/playwright';
import {
DEFAULT_STORYBOOK_DIR,
serveStorybook,
type StaticServer,
} from '@astryxdesign/a11y-spec/storybook';

let storybook: StaticServer;
test.beforeAll(async () => {
storybook = await serveStorybook(
process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
);
});
test.afterAll(async () => {
await storybook?.close();
});

const STORY = 'core-tooltip--rich-content';
const SHIPPED_THEMES = [
'butter',
'chocolate',
'gothic',
'matcha',
'neutral',
'stone',
'y2k',
];
const MODES = ['light', 'dark'];

/**
* Each tooltip's text runs and icons that fall below their minimum: 4.5:1 for
* text, 3:1 for an icon. The measure uses the painted surface behind the
* content and the color each part draws with, opacity included.
*/
async function lowContrastParts(page: Page): Promise<string[]> {
return page.evaluate(() => {
const canvas = document.createElement('canvas').getContext('2d', {
willReadFrequently: true,
}) as CanvasRenderingContext2D;
type Rgba = [number, number, number, number];
const rgba = (color: string): Rgba => {
canvas.clearRect(0, 0, 1, 1);
canvas.fillStyle = color;
canvas.fillRect(0, 0, 1, 1);
const [r, g, b, a] = canvas.getImageData(0, 0, 1, 1).data;
return [r, g, b, a / 255];
};
const over = (top: Rgba, under: Rgba): Rgba => {
const a = top[3] + under[3] * (1 - top[3]);
const mix = (i: number) =>
a === 0
? 0
: (top[i] * top[3] + under[i] * under[3] * (1 - top[3])) / a;
return [mix(0), mix(1), mix(2), a];
};
const luminance = ([r, g, b]: Rgba) => {
const linear = (v: number) => {
const c = v / 255;
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
};
return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);
};
const ratio = (a: Rgba, b: Rgba) => {
const [high, low] = [luminance(a), luminance(b)].sort((x, y) => y - x);
return (high + 0.05) / (low + 0.05);
};
const backdropOf = (element: Element): Rgba => {
const chain: Element[] = [];
for (
let node: Element | null = element;
node;
node = node.parentElement
) {
chain.unshift(node);
}
let background: Rgba = [255, 255, 255, 1];
for (const node of chain) {
background = over(
rgba(getComputedStyle(node).backgroundColor),
background,
);
}
return background;
};
const drawnColor = (element: Element, color: string, background: Rgba) => {
let opacity = 1;
for (
let node: Element | null = element;
node;
node = node.parentElement
) {
opacity *= Number(getComputedStyle(node).opacity);
}
const ink = rgba(color);
return over([ink[0], ink[1], ink[2], ink[3] * opacity], background);
};

const failures: string[] = [];
for (const tooltip of document.querySelectorAll('[role="tooltip"]')) {
const walker = document.createTreeWalker(tooltip, NodeFilter.SHOW_TEXT);
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
const text = node.textContent?.trim();
const element = node.parentElement;
if (!text || element == null) {
continue;
}
const background = backdropOf(element);
const drawn = drawnColor(
element,
getComputedStyle(element).color,
background,
);
const found = ratio(drawn, background);
if (found < 4.5) {
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
failures.push(`text "${text}": ${found.toFixed(2)}:1`);
}
}
for (const icon of tooltip.querySelectorAll('svg')) {
const background = backdropOf(icon);
const style = getComputedStyle(icon);
const paint =
style.fill !== 'none' && !style.fill.startsWith('url(')
? style.fill
: style.stroke !== 'none'
? style.stroke
: style.color;
const drawn = drawnColor(icon, paint, background);
const found = ratio(drawn, background);
if (found < 3) {
failures.push(`icon: ${found.toFixed(2)}:1`);
}
}
}
return failures;
});
}

for (const theme of SHIPPED_THEMES) {
test(`tooltip text reaches 4.5:1 and icons 3:1 in ${theme}, light and dark`, async ({
page,
}) => {
const failures: string[] = [];
for (const mode of MODES) {
await page.goto(
`${storybook.origin}/iframe.html?id=${STORY}&viewMode=story&globals=astryxTheme:${theme};colorMode:${mode}`,
);
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
await expect(page.getByRole('tooltip')).toHaveCount(5);
await expect(page.getByText('Body text')).toBeVisible();
await page.evaluate(async () => {
await document.fonts.ready;
await new Promise(resolve =>
requestAnimationFrame(() => requestAnimationFrame(resolve)),
);
});
failures.push(
...(await lowContrastParts(page)).map(failure => `${mode}: ${failure}`),
);
}
expect(failures).toEqual([]);
});
}
Loading
Loading