Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-button): apply hover styles only on devices that support it #31700

Closed
Closed
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": "differentiate between hover and pointer for hover styles",
"packageName": "@fluentui/react-button",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ const useRootBaseClassName = makeResetStyles({
fontFamily: tokens.fontFamilyBase,
outlineStyle: 'none',

':hover': {
backgroundColor: tokens.colorNeutralBackground1Hover,
borderColor: tokens.colorNeutralStroke1Hover,
color: tokens.colorNeutralForeground1Hover,
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorNeutralBackground1Hover,
borderColor: tokens.colorNeutralStroke1Hover,
color: tokens.colorNeutralForeground1Hover,

cursor: 'pointer',
cursor: 'pointer',
},
},

':hover:active': {
Expand Down Expand Up @@ -83,11 +86,14 @@ const useRootBaseClassName = makeResetStyles({
borderColor: 'ButtonText',
},

':hover': {
backgroundColor: 'HighlightText',
borderColor: 'Highlight',
color: 'Highlight',
forcedColorAdjust: 'none',
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: 'HighlightText',
borderColor: 'Highlight',
color: 'Highlight',
forcedColorAdjust: 'none',
},
},

':hover:active': {
Expand Down Expand Up @@ -138,8 +144,11 @@ const useRootStyles = makeStyles({
outline: {
backgroundColor: tokens.colorTransparentBackground,

':hover': {
backgroundColor: tokens.colorTransparentBackgroundHover,
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorTransparentBackgroundHover,
},
},

':hover:active': {
Expand All @@ -151,10 +160,13 @@ const useRootStyles = makeStyles({
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForegroundOnBrand,

':hover': {
backgroundColor: tokens.colorBrandBackgroundHover,
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForegroundOnBrand,
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorBrandBackgroundHover,
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForegroundOnBrand,
},
},

':hover:active': {
Expand All @@ -168,11 +180,13 @@ const useRootStyles = makeStyles({
...shorthands.borderColor('HighlightText'),
color: 'HighlightText',
forcedColorAdjust: 'none',

':hover': {
backgroundColor: 'HighlightText',
...shorthands.borderColor('Highlight'),
color: 'Highlight',
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: 'HighlightText',
...shorthands.borderColor('Highlight'),
color: 'Highlight',
},
},

':hover:active': {
Expand All @@ -189,19 +203,21 @@ const useRootStyles = makeStyles({
backgroundColor: tokens.colorSubtleBackground,
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForeground2,

':hover': {
backgroundColor: tokens.colorSubtleBackgroundHover,
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForeground2Hover,
[`& .${iconFilledClassName}`]: {
display: 'inline',
},
[`& .${iconRegularClassName}`]: {
display: 'none',
},
[`& .${buttonClassNames.icon}`]: {
color: tokens.colorNeutralForeground2BrandHover,
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorSubtleBackgroundHover,
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForeground2Hover,
[`& .${iconFilledClassName}`]: {
display: 'inline',
},
[`& .${iconRegularClassName}`]: {
display: 'none',
},
[`& .${buttonClassNames.icon}`]: {
color: tokens.colorNeutralForeground2BrandHover,
},
},
},

Expand All @@ -221,11 +237,14 @@ const useRootStyles = makeStyles({
},

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

[`& .${buttonClassNames.icon}`]: {
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
color: 'Highlight',

[`& .${buttonClassNames.icon}`]: {
color: 'Highlight',
},
},
},
':hover:active': {
Expand All @@ -241,16 +260,18 @@ const useRootStyles = makeStyles({
backgroundColor: tokens.colorTransparentBackground,
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForeground2,

':hover': {
backgroundColor: tokens.colorTransparentBackgroundHover,
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForeground2BrandHover,
[`& .${iconFilledClassName}`]: {
display: 'inline',
},
[`& .${iconRegularClassName}`]: {
display: 'none',
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorTransparentBackgroundHover,
...shorthands.borderColor('transparent'),
color: tokens.colorNeutralForeground2BrandHover,
[`& .${iconFilledClassName}`]: {
display: 'inline',
},
[`& .${iconRegularClassName}`]: {
display: 'none',
},
},
},

Expand All @@ -267,9 +288,12 @@ const useRootStyles = makeStyles({
},

'@media (forced-colors: active)': {
':hover': {
backgroundColor: tokens.colorTransparentBackground,
color: 'Highlight',
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorTransparentBackground,
color: 'Highlight',
},
},
':hover:active': {
backgroundColor: tokens.colorTransparentBackground,
Expand Down Expand Up @@ -328,22 +352,24 @@ const useRootDisabledStyles = makeStyles({
[`& .${buttonClassNames.icon}`]: {
color: tokens.colorNeutralForegroundDisabled,
},
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorNeutralBackgroundDisabled,
...shorthands.borderColor(tokens.colorNeutralStrokeDisabled),
color: tokens.colorNeutralForegroundDisabled,

':hover': {
backgroundColor: tokens.colorNeutralBackgroundDisabled,
...shorthands.borderColor(tokens.colorNeutralStrokeDisabled),
color: tokens.colorNeutralForegroundDisabled,

cursor: 'not-allowed',
cursor: 'not-allowed',

[`& .${iconFilledClassName}`]: {
display: 'none',
},
[`& .${iconRegularClassName}`]: {
display: 'inline',
},
[`& .${buttonClassNames.icon}`]: {
color: tokens.colorNeutralForegroundDisabled,
[`& .${iconFilledClassName}`]: {
display: 'none',
},
[`& .${iconRegularClassName}`]: {
display: 'inline',
},
[`& .${buttonClassNames.icon}`]: {
color: tokens.colorNeutralForegroundDisabled,
},
},
},

Expand Down Expand Up @@ -376,11 +402,13 @@ const useRootDisabledStyles = makeStyles({
':focus': {
...shorthands.borderColor('GrayText'),
},

':hover': {
backgroundColor: 'ButtonFace',
...shorthands.borderColor('GrayText'),
color: 'GrayText',
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: 'ButtonFace',
...shorthands.borderColor('GrayText'),
color: 'GrayText',
},
},

':hover:active': {
Expand All @@ -394,9 +422,11 @@ const useRootDisabledStyles = makeStyles({
// Appearance variations
outline: {
backgroundColor: tokens.colorTransparentBackground,

':hover': {
backgroundColor: tokens.colorTransparentBackground,
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorTransparentBackground,
},
},

':hover:active': {
Expand All @@ -405,9 +435,11 @@ const useRootDisabledStyles = makeStyles({
},
primary: {
...shorthands.borderColor('transparent'),

':hover': {
...shorthands.borderColor('transparent'),
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
...shorthands.borderColor('transparent'),
},
},

':hover:active': {
Expand All @@ -420,10 +452,12 @@ const useRootDisabledStyles = makeStyles({
subtle: {
backgroundColor: tokens.colorTransparentBackground,
...shorthands.borderColor('transparent'),

':hover': {
backgroundColor: tokens.colorTransparentBackground,
...shorthands.borderColor('transparent'),
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorTransparentBackground,
...shorthands.borderColor('transparent'),
},
},

':hover:active': {
Expand All @@ -434,10 +468,12 @@ const useRootDisabledStyles = makeStyles({
transparent: {
backgroundColor: tokens.colorTransparentBackground,
...shorthands.borderColor('transparent'),

':hover': {
backgroundColor: tokens.colorTransparentBackground,
...shorthands.borderColor('transparent'),
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
backgroundColor: tokens.colorTransparentBackground,
...shorthands.borderColor('transparent'),
},
},

':hover:active': {
Expand All @@ -460,18 +496,24 @@ const useRootFocusStyles = makeStyles({
...createCustomFocusIndicatorStyle({
...shorthands.borderColor(tokens.colorStrokeFocus2),
boxShadow: `${tokens.shadow2}, 0 0 0 ${tokens.strokeWidthThin} ${tokens.colorStrokeFocus2} inset, 0 0 0 ${tokens.strokeWidthThick} ${tokens.colorNeutralForegroundOnBrand} inset`,
':hover': {
boxShadow: `${tokens.shadow2}, 0 0 0 ${tokens.strokeWidthThin} ${tokens.colorStrokeFocus2} inset`,
...shorthands.borderColor(tokens.colorStrokeFocus2),
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
boxShadow: `${tokens.shadow2}, 0 0 0 ${tokens.strokeWidthThin} ${tokens.colorStrokeFocus2} inset`,
...shorthands.borderColor(tokens.colorStrokeFocus2),
},
},
}),

// BUGFIX: Mozilla specific styles (Mozilla BugID: 1857642)
'@supports (-moz-appearance:button)': {
...createCustomFocusIndicatorStyle({
boxShadow: `${tokens.shadow2}, 0 0 0 ${boxShadowStrokeWidthThinMoz} ${tokens.colorStrokeFocus2} inset, 0 0 0 ${tokens.strokeWidthThick} ${tokens.colorNeutralForegroundOnBrand} inset`,
':hover': {
boxShadow: `${tokens.shadow2}, 0 0 0 ${boxShadowStrokeWidthThinMoz} ${tokens.colorStrokeFocus2} inset`,
// Query devices that support hover: https://www.w3.org/TR/mediaqueries-4/#any-input
'@media (any-hover: hover)': {
':hover': {
boxShadow: `${tokens.shadow2}, 0 0 0 ${boxShadowStrokeWidthThinMoz} ${tokens.colorStrokeFocus2} inset`,
},
},
}),
},
Expand Down
Loading
Loading