Skip to content

Commit

Permalink
fix: High contrast mode hover style icon fixes in react-button compon…
Browse files Browse the repository at this point in the history
…ents (microsoft#28156)

* buttons a11y fix: subtle hover icon color and transparent text color

* compound button, subtle secondary content color fix

* changefile

* menubutton high contrast fix

* fix icon colors in togglebutton, in high contrast

* capitalization

* capitalization
  • Loading branch information
emmayjiang authored Jul 20, 2023
1 parent 14804fe commit 638b05a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: high contrast mode hover style icon fixes",
"packageName": "@fluentui/react-button",
"email": "eysjiang@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ const useRootStyles = makeStyles({
color: tokens.colorNeutralForeground2BrandPressed,
},
},

'@media (forced-colors: active)': {
':hover': {
color: 'Canvas',

[`& .${buttonClassNames.icon}`]: {
color: 'Canvas',
},
},
':hover:active': {
color: 'Canvas',

[`& .${buttonClassNames.icon}`]: {
color: 'Canvas',
},
},
},
},
transparent: {
backgroundColor: tokens.colorTransparentBackground,
Expand All @@ -225,6 +242,19 @@ const useRootStyles = makeStyles({
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForeground2BrandPressed,
},

'@media (forced-colors: active)': {
':hover': {
backgroundColor: tokens.colorTransparentBackgroundHover,
...shorthands.borderColor('transparent'),
color: 'Highlight',
},
':hover:active': {
backgroundColor: tokens.colorTransparentBackgroundHover,
...shorthands.borderColor('transparent'),
color: 'Highlight',
},
},
},

// Shape variations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ const useRootStyles = makeStyles({
color: tokens.colorNeutralForeground2Pressed,
},
},

'@media (forced-colors: active)': {
':hover': {
[`& .${compoundButtonClassNames.secondaryContent}`]: {
color: 'Canvas',
},
},
':hover:active': {
[`& .${compoundButtonClassNames.secondaryContent}`]: {
color: 'Canvas',
},
},
},
},
transparent: {
[`& .${compoundButtonClassNames.secondaryContent}`]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ const useIconExpandedStyles = makeStyles({
transparent: {
color: tokens.colorNeutralForeground2BrandSelected,
},
highContrast: {
// High contrast styles
'@media (forced-colors: active)': {
':hover': {
color: 'Canvas',
},
},
},
});

const useMenuIconStyles = makeStyles({
Expand Down Expand Up @@ -110,7 +118,7 @@ export const useMenuButtonStyles_unstable = (state: MenuButtonState): MenuButton
if (state.icon) {
state.icon.className = mergeClasses(
menuButtonClassNames.icon,
state.root['aria-expanded'] && iconExpandedStyles[state.appearance],
state.root['aria-expanded'] && iconExpandedStyles[state.appearance] && iconExpandedStyles.highContrast,
state.icon.className,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ const useIconCheckedStyles = makeStyles({
subtleOrTransparent: {
color: tokens.colorNeutralForeground2BrandSelected,
},
// High contrast styles
highContrast: {
'@media (forced-colors: active)': {
forcedColorAdjust: 'auto',
},
},
});

const usePrimaryHighContrastStyles = makeStyles({
Expand Down Expand Up @@ -272,7 +278,9 @@ export const useToggleButtonStyles_unstable = (state: ToggleButtonState): Toggle
if (state.icon) {
state.icon.className = mergeClasses(
toggleButtonClassNames.icon,
(appearance === 'subtle' || appearance === 'transparent') && iconCheckedStyles.subtleOrTransparent,
(appearance === 'subtle' || appearance === 'transparent') &&
iconCheckedStyles.subtleOrTransparent &&
iconCheckedStyles.highContrast,
state.icon.className,
);
}
Expand Down

0 comments on commit 638b05a

Please sign in to comment.