Skip to content
Open
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
10 changes: 10 additions & 0 deletions packages/cli/src/linter/linter/rules/contrast-ratio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ describe('contrastCheck', () => {
expect(findings[0]!.message).toMatch(/contrast/);
});

it('does not judge a translucent background without a known backdrop', () => {
const state = buildState({
colors: { surface: '#1a1d21', warn: '#f2b33d', 'warn-tint': '#f2b33d1a' },
components: {
'alert-tint': { backgroundColor: '{colors.warn-tint}', textColor: '{colors.warn}' },
},
});
expect(contrastCheck(state)).toEqual([]);
});

it('returns empty for high contrast pair', () => {
const state = buildState({
colors: { black: '#000000', white: '#ffffff' },
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/linter/linter/rules/contrast-ratio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export function contrastCheck(state: DesignSystemState): RuleFinding[] {
const textColor = resolveToColor(textValue);
if (!bgColor || !textColor) continue;

// A translucent color's contrast depends on what it is composited over.
// The rule has no backdrop for a component, so comparing the raw color
// produces false warnings (for example a 10% tint against its own text).
// Leave those pairs to manual review instead of guessing a surface.
if ((bgColor.a ?? 1) < 1 || (textColor.a ?? 1) < 1) continue;

const ratio = contrastRatio(bgColor, textColor);
if (ratio < WCAG_AA_MINIMUM) {
findings.push({
Expand Down