Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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 reads the tokens of the media 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, and bare text beside other elements, keeps the tooltip's own text color, so a theme's `tooltip` color still reaches it. In the Gothic and Matcha themes, secondary text on a light media surface is darker, so it reaches 4.5:1 on their tooltip and other light inverted surfaces.
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

@cixzhang
53 changes: 53 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,54 @@ export const TouchTriggers: Story = {
</div>
),
};

/**
* Rich content on the inverted surface: a plain string, the docs' `Text`
* example, default and secondary `Text`, an icon with text, and bare text
* mixed with an element 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>
<Tooltip
content={
<>
Saved <strong>now</strong>
</>
}
isDefaultOpen>
<Button label="Mixed content" />
</Tooltip>
</HStack>
</div>
),
};
2 changes: 1 addition & 1 deletion docs/specs/components/Tooltip/Tooltip.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | -------------- | ------------------ |
| Tooltip surface | Presents the current painted overlay surface, in the theme's inverted surface color (`--color-background-inverted`, the surface Toast paints) with the page surface color (`--color-background-surface`) as its text. The layer is always a scroll container (`overflow-y: auto`), so `position: sticky` and `scroll(nearest)` timelines inside its content resolve against the layer, not the page. | Current source and public docs | Supporting | FR1 |
| Tooltip text | Presents supplied content within the owned surface. | Current source and public docs | Prominent | FR1 |
| Tooltip text | Presents supplied content within the owned surface. The content reads the tokens of the media side whose text reads on the surface; inherited text keeps the `tooltip` surface's color (`theme-application` INV8). | Current source and public docs | Prominent | FR1 |

The trigger is caller-owned and outside this anatomy. The current implementation
has no arrow element.
Expand Down
38 changes: 7 additions & 31 deletions packages/core/src/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ import {mergeProps} from '../utils';
import {INTERACTIVE_SELECTORS} from '../hooks/useClickableContainer';
import {useAnnounceRenderedText} from '../hooks/useAnnounceRenderedText';
import type {AnnounceFn} from '../hooks/useAnnounce';
import {useTheme} from '../theme';
import {MediaTheme} from '../theme/MediaTheme';
import {useSurfaceMediaMode} from '../hooks/useAutoMediaMode';
import {useInvertedSurfaceMediaMode} from '../hooks/useAutoMediaMode';
import {pickInvertedSide} from '../hooks/mediaSide';
import {parseColor} from '../utils/color';
import type {
ToastType,
ToastDismissReason,
Expand Down Expand Up @@ -422,37 +420,15 @@ export function ToastSurface({
onDismiss('manual');
}, [onDismiss]);

// Before the measurement, take the side from the theme's resolved surface by
// the measurement's rule. If the surface is translucent, or parseColor cannot
// read it or an on-color, use the mode.
const {mode, tokens} = useTheme();
const surface = parseColor(
tokens[
isError
? '--color-background-error-inverted'
: '--color-background-inverted'
] ?? '',
);
const fromTokens =
surface !== null && surface.a >= 1
? pickInvertedSide(
surface,
null,
parseColor(tokens['--color-on-dark'] ?? ''),
parseColor(tokens['--color-on-light'] ?? ''),
)
: null;
const fallbackMediaMode =
fromTokens === 'dark' || fromTokens === 'light'
? fromTokens
: isError || mode === 'light'
? 'dark'
: 'light';
// Once painted, the card's text takes the side that reads best on it.
const measuredMediaMode = useSurfaceMediaMode(
const mediaMode = useInvertedSurfaceMediaMode(
rootRef,
true,
pickInvertedSide,
isError
? '--color-background-error-inverted'
: '--color-background-inverted',
isError,
);

return (
Expand All @@ -476,7 +452,7 @@ export function ToastSurface({
isExiting && styles.exiting,
),
)}>
<MediaTheme mode={measuredMediaMode ?? fallbackMediaMode}>
<MediaTheme mode={mediaMode}>
{renderContent ? (
renderContent({
body,
Expand Down
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();
});
});
Loading