Skip to content

Commit 4cea5d2

Browse files
az108claude
andcommitted
Bugfix: Make selected rating chips readable in both colour schemes
The excellent and poor chips became unreadable once selected. A selected chip is filled with its rating colour and labelled with the matching text-on-* token. Those tokens flip with the colour scheme, near-black in light and white in dark, while the fills stay the same shades in both. So each fill ends up paired with a foreground that suits only one of the two schemes. Measured against WCAG AA, in light mode very_bad sat at 2.80:1, very_good at 3.47:1 and bad at 4.39:1; in dark mode neutral sat at 1.65:1 and good at 3.70:1. The two reported are the worst of the five, but three others were failing too, and no single foreground fixes all of them: white is unreadable on the yellow. The foreground is now chosen per fill from the two fixed base tokens, which do not move with the scheme, since the fills do not either. White on the dark red and dark green, black on the yellow and mid green. The lowest pairing is now 4.72:1 and all five clear 4.5:1 in both schemes. Verified the generated utilities resolve in the compiled stylesheet, and updated the class expectations in the rating spec. Verified: 2010 client tests, typecheck, eslint with no errors, a11y lint, the production build and prettier. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b10cab1 commit 4cea5d2

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

src/main/webapp/app/shared/components/atoms/rating/rating.component.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ interface VariantClasses {
1515
textOn: string;
1616
}
1717

18+
/**
19+
* A selected chip is filled with its rating colour, so its label needs a foreground picked for that
20+
* fill. The text-on-* tokens cannot be used here: they flip between near-black and white with the
21+
* colour scheme, while these fills stay the same in both, so each one fails in one scheme or the
22+
* other. The dark red and dark green fills need white, the yellow and mid-green need black. Every
23+
* pairing below clears the WCAG AA 4.5:1 minimum, the tightest being 4.72:1 on the mid red.
24+
*/
1825
const VARIANT_CLASSES: Record<LikertValue, VariantClasses> = {
19-
[-2]: { bg: 'bg-negative-active', hoverBg: 'hover:bg-negative-active/15', textOn: 'text-text-on-danger' },
20-
[-1]: { bg: 'bg-negative-hover', hoverBg: 'hover:bg-negative-hover/15', textOn: 'text-text-on-danger' },
21-
[0]: { bg: 'bg-warning-default', hoverBg: 'hover:bg-warning-default/15', textOn: 'text-text-on-warn' },
22-
[1]: { bg: 'bg-positive-hover', hoverBg: 'hover:bg-positive-hover/15', textOn: 'text-text-on-success' },
23-
[2]: { bg: 'bg-positive-active', hoverBg: 'hover:bg-positive-active/15', textOn: 'text-text-on-success' },
26+
[-2]: { bg: 'bg-negative-active', hoverBg: 'hover:bg-negative-active/15', textOn: 'text-base-white' },
27+
[-1]: { bg: 'bg-negative-hover', hoverBg: 'hover:bg-negative-hover/15', textOn: 'text-base-white' },
28+
[0]: { bg: 'bg-warning-default', hoverBg: 'hover:bg-warning-default/15', textOn: 'text-base-black' },
29+
[1]: { bg: 'bg-positive-hover', hoverBg: 'hover:bg-positive-hover/15', textOn: 'text-base-black' },
30+
[2]: { bg: 'bg-positive-active', hoverBg: 'hover:bg-positive-active/15', textOn: 'text-base-white' },
2431
};
2532

2633
@Component({

src/test/webapp/app/shared/components/atoms/rating/rating.component.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ describe('RatingComponent', () => {
5353
// ---------------- BUTTON STATES ----------------
5454
it.each<[number | undefined, number, string, string | undefined]>([
5555
[undefined, 0, 'hover:bg-negative-active/15', undefined],
56-
[-2, 0, 'bg-negative-active', 'text-text-on-danger'],
57-
[-1, 1, 'bg-negative-hover', 'text-text-on-danger'],
58-
[0, 2, 'bg-warning-default', 'text-text-on-warn'],
59-
[1, 3, 'bg-positive-hover', 'text-text-on-success'],
60-
[2, 4, 'bg-positive-active', 'text-text-on-success'],
56+
[-2, 0, 'bg-negative-active', 'text-base-white'],
57+
[-1, 1, 'bg-negative-hover', 'text-base-white'],
58+
[0, 2, 'bg-warning-default', 'text-base-black'],
59+
[1, 3, 'bg-positive-hover', 'text-base-black'],
60+
[2, 4, 'bg-positive-active', 'text-base-white'],
6161
[2, 0, 'hover:bg-negative-active/15', undefined],
6262
])('should compute classes for rating=%s at index=%i', (rating, index, expectedClass, expectedTextClass) => {
6363
fixture.componentRef.setInput('rating', rating);
@@ -67,7 +67,7 @@ describe('RatingComponent', () => {
6767
if (expectedTextClass !== undefined) {
6868
expect(classes).toContain(expectedTextClass);
6969
} else {
70-
expect(classes).not.toContain('text-text-on-');
70+
expect(classes).not.toContain('text-base-');
7171
}
7272
});
7373

0 commit comments

Comments
 (0)