Skip to content

Commit 2d4cb70

Browse files
fix: apply button hover states only on supported devices (#21724)
* fix: apply button hover states only on supported devices * chore: move comment above media * chore: update copyright year * fix: review comments * fix: more cases on mobile * chore: update hover to any-hover to support hybrid setups
1 parent a4a17c4 commit 2d4cb70

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

packages/styles/scss/components/button/_button.scss

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@
164164
$button-tertiary-active
165165
);
166166

167-
&:hover {
168-
color: $text-inverse;
167+
@media (any-hover: hover) {
168+
&:hover {
169+
color: $text-inverse;
170+
}
169171
}
170172

171173
&:focus {
@@ -211,13 +213,16 @@
211213
margin-inline-start: $spacing-03;
212214
}
213215

214-
&:hover,
215-
&:active {
216-
color: $link-primary-hover;
216+
// Apply hover styles only on devices that support hover
217+
@media (hover: hover) {
218+
&:hover {
219+
color: $link-primary-hover;
220+
}
217221
}
218222

219223
&:active {
220224
background-color: $background-active;
225+
color: $link-primary-hover;
221226
}
222227

223228
&:disabled,
@@ -347,9 +352,11 @@
347352
$button-danger-active
348353
);
349354

350-
&:hover {
351-
border-color: $button-danger-hover;
352-
color: $text-on-color;
355+
@media (hover: hover) {
356+
&:hover {
357+
border-color: $button-danger-hover;
358+
color: $text-on-color;
359+
}
353360
}
354361

355362
&:focus {
@@ -394,7 +401,12 @@
394401
margin-inline-start: $spacing-03;
395402
}
396403

397-
&:hover,
404+
@media (hover: hover) {
405+
&:hover {
406+
color: $text-on-color;
407+
}
408+
}
409+
398410
&:active {
399411
color: $text-on-color;
400412
}

packages/styles/scss/components/button/_mixins.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright IBM Corp. 2016, 2023
2+
// Copyright IBM Corp. 2016, 2026
33
//
44
// This source code is licensed under the Apache-2.0 license found in the
55
// LICENSE file in the root directory of this source tree.
@@ -123,8 +123,11 @@ $button-focus-color: custom-property.get-var('button-focus-color', $focus);
123123
background-color: $bg-color;
124124
color: $font-color;
125125

126-
&:hover {
127-
background-color: $hover-bg-color;
126+
// Apply hover styles only on devices that support hover
127+
@media (any-hover: hover) {
128+
&:hover {
129+
background-color: $hover-bg-color;
130+
}
128131
}
129132

130133
&:focus {

0 commit comments

Comments
 (0)