Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: add forced-colors primary button variant",
"packageName": "@fluentui/react-button",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -296,6 +315,7 @@ const useRootDisabledStyles = makeStyles({
// High contrast styles
highContrast: {
'@media (forced-colors: active)': {
backgroundColor: 'ButtonFace',
...shorthands.borderColor('GrayText'),
color: 'GrayText',

Expand All @@ -304,11 +324,13 @@ const useRootDisabledStyles = makeStyles({
},

':hover': {
backgroundColor: 'ButtonFace',
...shorthands.borderColor('GrayText'),
color: 'GrayText',
},

':hover:active': {
backgroundColor: 'ButtonFace',
...shorthands.borderColor('GrayText'),
color: 'GrayText',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down