diff --git a/change/@fluentui-react-button-6070b42d-35c8-4c8a-b515-e0893216885b.json b/change/@fluentui-react-button-6070b42d-35c8-4c8a-b515-e0893216885b.json new file mode 100644 index 00000000000000..c834aaa88a751e --- /dev/null +++ b/change/@fluentui-react-button-6070b42d-35c8-4c8a-b515-e0893216885b.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix: add forced-colors primary button variant", + "packageName": "@fluentui/react-button", + "email": "sarah.higley@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-components/react-button/src/components/Button/useButtonStyles.ts b/packages/react-components/react-button/src/components/Button/useButtonStyles.ts index 95dd16afe90210..d57a6783b323e0 100644 --- a/packages/react-components/react-button/src/components/Button/useButtonStyles.ts +++ b/packages/react-components/react-button/src/components/Button/useButtonStyles.ts @@ -161,6 +161,25 @@ const useRootStyles = makeStyles({ ...shorthands.borderColor('transparent'), color: tokens.colorNeutralForegroundOnBrand, }, + + '@media (forced-colors: active)': { + backgroundColor: 'Highlight', + ...shorthands.borderColor('HighlightText'), + color: 'HighlightText', + forcedColorAdjust: 'none', + + ':hover': { + backgroundColor: 'HighlightText', + ...shorthands.borderColor('Highlight'), + color: 'Highlight', + }, + + ':hover:active': { + backgroundColor: 'HighlightText', + ...shorthands.borderColor('Highlight'), + color: 'Highlight', + }, + }, }, secondary: { /* The secondary styles are exactly the same as the base styles. */ @@ -296,6 +315,7 @@ const useRootDisabledStyles = makeStyles({ // High contrast styles highContrast: { '@media (forced-colors: active)': { + backgroundColor: 'ButtonFace', ...shorthands.borderColor('GrayText'), color: 'GrayText', @@ -304,11 +324,13 @@ const useRootDisabledStyles = makeStyles({ }, ':hover': { + backgroundColor: 'ButtonFace', ...shorthands.borderColor('GrayText'), color: 'GrayText', }, ':hover:active': { + backgroundColor: 'ButtonFace', ...shorthands.borderColor('GrayText'), color: 'GrayText', }, diff --git a/packages/react-components/react-button/src/components/CompoundButton/useCompoundButtonStyles.ts b/packages/react-components/react-button/src/components/CompoundButton/useCompoundButtonStyles.ts index b811f96e9b880c..b2acd1992a6018 100644 --- a/packages/react-components/react-button/src/components/CompoundButton/useCompoundButtonStyles.ts +++ b/packages/react-components/react-button/src/components/CompoundButton/useCompoundButtonStyles.ts @@ -70,6 +70,12 @@ const useRootStyles = makeStyles({ color: tokens.colorNeutralForegroundOnBrand, }, }, + + '@media (forced-colors: active)': { + [`& .${compoundButtonClassNames.secondaryContent}`]: { + color: 'HighlightText', + }, + }, }, secondary: { /* The secondary styles are exactly the same as the base styles. */ diff --git a/packages/react-components/react-button/src/components/SplitButton/useSplitButtonStyles.ts b/packages/react-components/react-button/src/components/SplitButton/useSplitButtonStyles.ts index f0e51476fa0b59..fabd4b2341603a 100644 --- a/packages/react-components/react-button/src/components/SplitButton/useSplitButtonStyles.ts +++ b/packages/react-components/react-button/src/components/SplitButton/useSplitButtonStyles.ts @@ -64,6 +64,24 @@ const useRootStyles = makeStyles({ borderRightColor: tokens.colorNeutralForegroundOnBrand, }, }, + + '@media (forced-colors: active)': { + [`& .${splitButtonClassNames.primaryActionButton}`]: { + borderRightColor: 'HighlightText', + }, + + ':hover': { + [`& .${splitButtonClassNames.primaryActionButton}`]: { + borderRightColor: 'Highlight', + }, + }, + + ':hover:active': { + [`& .${splitButtonClassNames.primaryActionButton}`]: { + borderRightColor: 'Highlight', + }, + }, + }, }, secondary: { /* The secondary styles are exactly the same as the base styles. */ diff --git a/packages/react-components/react-button/src/components/ToggleButton/useToggleButtonStyles.ts b/packages/react-components/react-button/src/components/ToggleButton/useToggleButtonStyles.ts index be6139e6219e2c..f86d55ca9a80ba 100644 --- a/packages/react-components/react-button/src/components/ToggleButton/useToggleButtonStyles.ts +++ b/packages/react-components/react-button/src/components/ToggleButton/useToggleButtonStyles.ts @@ -217,16 +217,45 @@ const useIconCheckedStyles = makeStyles({ }, }); +const usePrimaryHighContrastStyles = makeStyles({ + // Do not use primary variant high contrast styles for toggle buttons + // otherwise there isn't enough difference between on/off states + base: { + '@media (forced-colors: active)': { + backgroundColor: 'ButtonFace', + ...shorthands.borderColor('ButtonBorder'), + color: 'ButtonText', + forcedColorAdjust: 'auto', + }, + }, + + disabled: { + '@media (forced-colors: active)': { + ...shorthands.borderColor('GrayText'), + color: 'GrayText', + + ':focus': { + ...shorthands.borderColor('GrayText'), + }, + }, + }, +}); + export const useToggleButtonStyles_unstable = (state: ToggleButtonState): ToggleButtonState => { const rootCheckedStyles = useRootCheckedStyles(); const rootDisabledStyles = useRootDisabledStyles(); const iconCheckedStyles = useIconCheckedStyles(); + const primaryHighContrastStyles = usePrimaryHighContrastStyles(); const { appearance, checked, disabled, disabledFocusable } = state; state.root.className = mergeClasses( toggleButtonClassNames.root, + // Primary high contrast styles + appearance === 'primary' && primaryHighContrastStyles.base, + appearance === 'primary' && (disabled || disabledFocusable) && primaryHighContrastStyles.disabled, + // Checked styles checked && rootCheckedStyles.base, checked && rootCheckedStyles.highContrast,