Skip to content

Commit

Permalink
ActionMenu: Fix styles for windows high contrast mode (#1970)
Browse files Browse the repository at this point in the history
* add forced-colors styles for Overlay & focused Button

* respect comment style

* add changeset

* update snapshots

* Revert "update snapshots"

This reverts commit 63743cd.

* only update relevant snapshots
  • Loading branch information
siddharthkp committed Mar 17, 2022
1 parent c83a06f commit 3b23604
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/actionmenu-fix-high-contrast-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

ActionMenu: Fix styles for windows high contrast mode
3 changes: 1 addition & 2 deletions src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(

'@media (forced-colors: active)': {
':focus': {
// we set color to be transparent and let the high contrast rules
// decide what color with contrast should that be corrected to
// Support for Windows high contrast https://sarahmhigley.com/writing/whcm-quick-tips
outline: 'solid 1px transparent !important'
}
},
Expand Down
6 changes: 6 additions & 0 deletions src/Button/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ export const getBaseStyles = (theme?: Theme) => ({
},
'&:disabled svg': {
opacity: '0.6'
},
'@media (forced-colors: active)': {
'&:focus': {
// Support for Windows high contrast https://sarahmhigley.com/writing/whcm-quick-tips
outline: 'solid 1px transparent'
}
}
})

Expand Down
6 changes: 6 additions & 0 deletions src/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ const StyledOverlay = styled.div<StyledOverlayProps>`
:focus {
outline: none;
}
@media (forced-colors: active) {
/* Support for Windows high contrast https://sarahmhigley.com/writing/whcm-quick-tips */
outline: solid 1px transparent;
}
${sx};
`
type BaseOverlayProps = {
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/__snapshots__/ActionMenu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ exports[`ActionMenu renders consistently 1`] = `
margin-right: -4px;
}
@media (forced-colors:active) {
.c1:focus {
outline: solid 1px transparent;
}
}
<div
className="c0"
color="fg.default"
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ exports[`AnchoredOverlay should render consistently when open 1`] = `
outline: none;
}
@media (forced-colors:active) {
.c2 {
outline: solid 1px transparent;
}
}
<div>
<div
class="c0"
Expand Down
30 changes: 30 additions & 0 deletions src/__tests__/__snapshots__/Button.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ exports[`Button renders consistently 1`] = `
border-color: rgba(27,31,36,0.15);
}
@media (forced-colors:active) {
.c0:focus {
outline: solid 1px transparent;
}
}
<button
className="c0"
/>
Expand Down Expand Up @@ -198,6 +204,12 @@ exports[`Button styles danger button appropriately 1`] = `
border-color: btn.danger.selectedBorder;
}
@media (forced-colors:active) {
.c0:focus {
outline: solid 1px transparent;
}
}
<button
class="c0"
>
Expand Down Expand Up @@ -294,6 +306,12 @@ exports[`Button styles invisible button appropriately 1`] = `
background-color: btn.selectedBg;
}
@media (forced-colors:active) {
.c0:focus {
outline: solid 1px transparent;
}
}
<button
class="c0"
>
Expand Down Expand Up @@ -411,6 +429,12 @@ exports[`Button styles outline button appropriately 1`] = `
border-color: btn.outline.selectedBorder;
}
@media (forced-colors:active) {
.c0:focus {
outline: solid 1px transparent;
}
}
<button
class="c0"
>
Expand Down Expand Up @@ -514,6 +538,12 @@ exports[`Button styles primary button appropriately 1`] = `
box-shadow: undefined;
}
@media (forced-colors:active) {
.c0:focus {
outline: solid 1px transparent;
}
}
<button
class="c0"
>
Expand Down

0 comments on commit 3b23604

Please sign in to comment.