Skip to content

Commit c097e96

Browse files
authored
SelectPanel: High contrast theme (#4966)
* use border-width to make icon visible * ActionList: include active-descendant for high contrast * e2e test for forced-colors (windows high contrast) * test(vrt): update snapshots * Create ten-gifts-own.md * update snapshots --------- Co-authored-by: siddharthkp <[email protected]>
1 parent d1b48bc commit c097e96

File tree

8 files changed

+110
-15
lines changed

8 files changed

+110
-15
lines changed

.changeset/ten-gifts-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
SelectPanel: Fix focus and selection styles for Windows high contrast themes (behind feature flag `primer_react_select_panel_with_modern_action_list`)
32.7 KB
Loading
32.7 KB
Loading

e2e/components/SelectPanel.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,27 @@ test.describe('SelectPanel', () => {
6060
await expect(page).toHaveNoViolations()
6161
})
6262
}
63+
64+
test(`Default @vrt forced-colors .modern-action-list--true`, async ({page}) => {
65+
await visit(page, {
66+
id: 'components-selectpanel--default',
67+
globals: {featureFlags: {primer_react_select_panel_with_modern_action_list: true}},
68+
})
69+
70+
// Open select panel
71+
await page.keyboard.press('Tab')
72+
await page.keyboard.press('Enter')
73+
74+
// windows high contrast mode: light
75+
await page.emulateMedia({forcedColors: 'active', colorScheme: 'light'})
76+
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
77+
`SelectPanel-Default-forced-colors-light-modern-action-list--true.png`,
78+
)
79+
80+
// windows high contrast mode: dark
81+
await page.emulateMedia({forcedColors: 'active', colorScheme: 'dark'})
82+
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
83+
`SelectPanel-Default-forced-colors-dark-modern-action-list--true.png`,
84+
)
85+
})
6386
})

packages/react/src/ActionList/Item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
196196
marginY: 'unset',
197197

198198
'@media (forced-colors: active)': {
199-
':focus, &:focus-visible, > a.focus-visible': {
199+
':focus, &:focus-visible, > a.focus-visible, &[data-is-active-descendant]': {
200200
// Support for Windows high contrast https://sarahmhigley.com/writing/whcm-quick-tips
201201
outline: 'solid 1px transparent !important',
202202
},

packages/react/src/ActionList/Selection.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ export const Selection: React.FC<React.PropsWithChildren<SelectionProps>> = ({se
9797
'@keyframes checkmarkIn': checkmarkIn,
9898
'@keyframes checkmarkOut': checkmarkOut,
9999
},
100+
'@media (forced-colors: active)': {
101+
// Support for Windows high contrast https://sarahmhigley.com/writing/whcm-quick-tips
102+
// background-color will be overriden but border-width is a workaround
103+
borderWidth: selected ? '8px' : '1px',
104+
},
100105
}}
101106
data-component="ActionList.Checkbox"
102107
/>

packages/react/src/NavList/__snapshots__/NavList.test.tsx.snap

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ exports[`NavList renders a simple list 1`] = `
304304
@media (forced-colors:active) {
305305
.c2:focus,
306306
.c2:focus-visible,
307-
.c2 > a.focus-visible {
307+
.c2 > a.focus-visible,
308+
.c2[data-is-active-descendant] {
308309
outline: solid 1px transparent !important;
309310
}
310311
}
@@ -333,7 +334,8 @@ exports[`NavList renders a simple list 1`] = `
333334
@media (forced-colors:active) {
334335
.c7:focus,
335336
.c7:focus-visible,
336-
.c7 > a.focus-visible {
337+
.c7 > a.focus-visible,
338+
.c7[data-is-active-descendant] {
337339
outline: solid 1px transparent !important;
338340
}
339341
}
@@ -794,7 +796,8 @@ exports[`NavList renders with groups 1`] = `
794796
@media (forced-colors:active) {
795797
.c6:focus,
796798
.c6:focus-visible,
797-
.c6 > a.focus-visible {
799+
.c6 > a.focus-visible,
800+
.c6[data-is-active-descendant] {
798801
outline: solid 1px transparent !important;
799802
}
800803
}
@@ -823,7 +826,8 @@ exports[`NavList renders with groups 1`] = `
823826
@media (forced-colors:active) {
824827
.c11:focus,
825828
.c11:focus-visible,
826-
.c11 > a.focus-visible {
829+
.c11 > a.focus-visible,
830+
.c11[data-is-active-descendant] {
827831
outline: solid 1px transparent !important;
828832
}
829833
}
@@ -1313,7 +1317,8 @@ exports[`NavList.Item with NavList.SubNav does not have active styles if SubNav
13131317
@media (forced-colors:active) {
13141318
.c11:focus,
13151319
.c11:focus-visible,
1316-
.c11 > a.focus-visible {
1320+
.c11 > a.focus-visible,
1321+
.c11[data-is-active-descendant] {
13171322
outline: solid 1px transparent !important;
13181323
}
13191324
}
@@ -1342,7 +1347,8 @@ exports[`NavList.Item with NavList.SubNav does not have active styles if SubNav
13421347
@media (forced-colors:active) {
13431348
.c4:focus,
13441349
.c4:focus-visible,
1345-
.c4 > a.focus-visible {
1350+
.c4 > a.focus-visible,
1351+
.c4[data-is-active-descendant] {
13461352
outline: solid 1px transparent !important;
13471353
}
13481354
}
@@ -1837,7 +1843,8 @@ exports[`NavList.Item with NavList.SubNav has active styles if SubNav contains t
18371843
@media (forced-colors:active) {
18381844
.c11:focus,
18391845
.c11:focus-visible,
1840-
.c11 > a.focus-visible {
1846+
.c11 > a.focus-visible,
1847+
.c11[data-is-active-descendant] {
18411848
outline: solid 1px transparent !important;
18421849
}
18431850
}
@@ -1874,7 +1881,8 @@ exports[`NavList.Item with NavList.SubNav has active styles if SubNav contains t
18741881
@media (forced-colors:active) {
18751882
.c4:focus,
18761883
.c4:focus-visible,
1877-
.c4 > a.focus-visible {
1884+
.c4 > a.focus-visible,
1885+
.c4[data-is-active-descendant] {
18781886
outline: solid 1px transparent !important;
18791887
}
18801888
}

packages/react/src/__tests__/__snapshots__/Autocomplete.test.tsx.snap

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,14 @@ exports[`snapshots renders a menu that contains an item to add to the menu 1`] =
527527
528528
}
529529
530+
@media (forced-colors:active) {
531+
532+
}
533+
534+
@media (forced-colors:active) {
535+
536+
}
537+
530538
@media (hover:hover) and (pointer:fine) {
531539
532540
}
@@ -812,10 +820,21 @@ exports[`snapshots renders a menu that contains an item to add to the menu 1`] =
812820
--divider-color: transparent;
813821
}
814822
823+
@media (forced-colors:active) {
824+
.c6 {
825+
border-width: 1px;
826+
}
827+
}
828+
829+
@media (forced-colors:active) {
830+
831+
}
832+
815833
@media (forced-colors:active) {
816834
.c3:focus,
817835
.c3:focus-visible,
818-
.c3 > a.focus-visible {
836+
.c3 > a.focus-visible,
837+
.c3[data-is-active-descendant] {
819838
outline: solid 1px transparent !important;
820839
}
821840
}
@@ -1359,6 +1378,10 @@ exports[`snapshots renders a multiselect input 1`] = `
13591378
13601379
}
13611380
1381+
@media (forced-colors:active) {
1382+
1383+
}
1384+
13621385
@media (hover:hover) and (pointer:fine) {
13631386
13641387
}
@@ -1595,10 +1618,17 @@ exports[`snapshots renders a multiselect input 1`] = `
15951618
border-radius: 6px;
15961619
}
15971620
1621+
@media (forced-colors:active) {
1622+
.c5 {
1623+
border-width: 1px;
1624+
}
1625+
}
1626+
15981627
@media (forced-colors:active) {
15991628
.c3:focus,
16001629
.c3:focus-visible,
1601-
.c3 > a.focus-visible {
1630+
.c3 > a.focus-visible,
1631+
.c3[data-is-active-descendant] {
16021632
outline: solid 1px transparent !important;
16031633
}
16041634
}
@@ -2077,6 +2107,14 @@ exports[`snapshots renders a multiselect input with selected menu items 1`] = `
20772107
20782108
}
20792109
2110+
@media (forced-colors:active) {
2111+
2112+
}
2113+
2114+
@media (forced-colors:active) {
2115+
2116+
}
2117+
20802118
@media (hover:hover) and (pointer:fine) {
20812119
20822120
}
@@ -2456,10 +2494,23 @@ exports[`snapshots renders a multiselect input with selected menu items 1`] = `
24562494
border-radius: 6px;
24572495
}
24582496
2497+
@media (forced-colors:active) {
2498+
.c5 {
2499+
border-width: 8px;
2500+
}
2501+
}
2502+
2503+
@media (forced-colors:active) {
2504+
.c9 {
2505+
border-width: 1px;
2506+
}
2507+
}
2508+
24592509
@media (forced-colors:active) {
24602510
.c3:focus,
24612511
.c3:focus-visible,
2462-
.c3 > a.focus-visible {
2512+
.c3 > a.focus-visible,
2513+
.c3[data-is-active-descendant] {
24632514
outline: solid 1px transparent !important;
24642515
}
24652516
}
@@ -2488,7 +2539,8 @@ exports[`snapshots renders a multiselect input with selected menu items 1`] = `
24882539
@media (forced-colors:active) {
24892540
.c8:focus,
24902541
.c8:focus-visible,
2491-
.c8 > a.focus-visible {
2542+
.c8 > a.focus-visible,
2543+
.c8[data-is-active-descendant] {
24922544
outline: solid 1px transparent !important;
24932545
}
24942546
}
@@ -3168,7 +3220,8 @@ exports[`snapshots renders a single select input 1`] = `
31683220
@media (forced-colors:active) {
31693221
.c3:focus,
31703222
.c3:focus-visible,
3171-
.c3 > a.focus-visible {
3223+
.c3 > a.focus-visible,
3224+
.c3[data-is-active-descendant] {
31723225
outline: solid 1px transparent !important;
31733226
}
31743227
}
@@ -3654,7 +3707,8 @@ exports[`snapshots renders with a custom text input component 1`] = `
36543707
@media (forced-colors:active) {
36553708
.c3:focus,
36563709
.c3:focus-visible,
3657-
.c3 > a.focus-visible {
3710+
.c3 > a.focus-visible,
3711+
.c3[data-is-active-descendant] {
36583712
outline: solid 1px transparent !important;
36593713
}
36603714
}

0 commit comments

Comments
 (0)