Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion packages/diffs/src/editor/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
pointer-events: auto;

@supports (color: contrast-color(red)) {
color: contrast-color(var(--diffs-marker-bg), var(--diffs-bg));
color: contrast-color(var(--diffs-marker-bg, var(--diffs-bg)));
}

[data-marker-message] {
Expand Down
20 changes: 16 additions & 4 deletions packages/diffs/test/e2e/markers.pw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,18 @@ function openScrolledMarkerNearGutter(page: Page): Promise<{
}

// Hovers the marker whose squiggle sits under `token`, then returns the WCAG
// contrast ratio between the popover's resolved text and background colors.
// Guards the marker popover fallback in browsers without contrast-color(): the
// severity fill is a theme editorX.foreground token, so its text candidate must
// remain legible in both light and dark themes.
// contrast ratio between the popover's resolved text and background colors, plus
// whether this browser took the contrast-color() path or the static fallback.
// The severity fill is a theme editorX.foreground token, so the text must remain
// legible in both light and dark themes on either path.
async function popoverContrast(
page: Page,
token: string
): Promise<{
backgroundColor: string;
color: string;
ratio: number;
supportsContrastColor: boolean;
} | null> {
await page.locator(CONTENT).getByText(token, { exact: true }).hover();
await expect(page.locator('[data-marker-popover]')).toBeVisible();
Expand Down Expand Up @@ -130,6 +131,7 @@ async function popoverContrast(
backgroundColor: cs.backgroundColor,
color: cs.color,
ratio: (lighter + 0.05) / (darker + 0.05),
supportsContrastColor: CSS.supports('color', 'contrast-color(red)'),
};
});
}
Expand Down Expand Up @@ -185,6 +187,16 @@ test.describe('editor markers', () => {
sample!.ratio,
`${theme} theme marker under "${token}": ${sample!.color} on ${sample!.backgroundColor}`
).toBeGreaterThanOrEqual(4.5);

// contrast-color() always resolves to pure black or white, so any other
// value means the declaration was invalid and `color` fell back to the
// inherited editor foreground.
if (sample!.supportsContrastColor) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exercise the supported contrast-color branch

In the inspected E2E configuration, the only project is the Chromium bundled with @playwright/test 1.51.1 (packages/diffs/test/e2e/playwright.config.ts:43-47, pnpm-workspace.yaml:65), which predates Chromium support for contrast-color(). Therefore this condition is false in every CI run and the new assertion is always skipped, so restoring the invalid two-argument declaration would still leave the regression test green. Run this check in a browser/channel that supports the function or add a test that actually exercises the supported declaration path.

Useful? React with 👍 / 👎.

expect(
['rgb(0, 0, 0)', 'rgb(255, 255, 255)'],
`${theme} theme marker under "${token}" resolved contrast-color() to ${sample!.color}`
).toContain(sample!.color);
}
}
}
});
Expand Down