Skip to content

Commit 465bdcb

Browse files
committed
fix(material/button): do not show hover state on devices that don't support hover
Disables the hover state for buttons on devices that don't support it (e.g. touch devices) since it can look off. Fixes #31841.
1 parent 6275d71 commit 465bdcb

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/material/button/button.scss

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ $fallbacks: m3-button.get-tokens();
1515
min-height: fit-content;
1616
flex-shrink: 0;
1717
}
18+
19+
// Hide the hover ripple on devices that don't support hover. Note that we have the `span`
20+
// in the selector in order to increase the specificity over the actual hover styles.
21+
@media (hover: none) {
22+
&:hover > span.mat-mdc-button-persistent-ripple::before {
23+
opacity: 0;
24+
}
25+
}
1826
}
1927

2028
.mdc-button {
@@ -163,8 +171,10 @@ $fallbacks: m3-button.get-tokens();
163171
border-radius: token-utils.slot(button-protected-container-shape, $fallbacks);
164172
}
165173

166-
&:hover {
167-
box-shadow: token-utils.slot(button-protected-hover-container-elevation-shadow, $fallbacks);
174+
@media (hover: hover) {
175+
&:hover {
176+
box-shadow: token-utils.slot(button-protected-hover-container-elevation-shadow, $fallbacks);
177+
}
168178
}
169179

170180
&:focus {

src/material/button/fab.scss

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ $fallbacks: m3-fab.get-tokens();
101101
color: token-utils.slot(fab-foreground-color, $fallbacks, inherit);
102102
box-shadow: token-utils.slot(fab-container-elevation-shadow, $fallbacks);
103103

104-
&:hover {
105-
box-shadow: token-utils.slot(fab-hover-container-elevation-shadow, $fallbacks);
104+
@media (hover: hover) {
105+
&:hover {
106+
box-shadow: token-utils.slot(fab-hover-container-elevation-shadow, $fallbacks);
107+
}
106108
}
107109

108110
&:focus {
@@ -133,8 +135,10 @@ $fallbacks: m3-fab.get-tokens();
133135
color: token-utils.slot(fab-small-foreground-color, $fallbacks, inherit);
134136
box-shadow: token-utils.slot(fab-small-container-elevation-shadow, $fallbacks);
135137

136-
&:hover {
137-
box-shadow: token-utils.slot(fab-small-hover-container-elevation-shadow, $fallbacks);
138+
@media (hover: hover) {
139+
&:hover {
140+
box-shadow: token-utils.slot(fab-small-hover-container-elevation-shadow, $fallbacks);
141+
}
138142
}
139143

140144
&:focus {
@@ -176,8 +180,10 @@ $fallbacks: m3-fab.get-tokens();
176180
font-weight: token-utils.slot(fab-extended-label-text-weight, $fallbacks);
177181
letter-spacing: token-utils.slot(fab-extended-label-text-tracking, $fallbacks);
178182

179-
&:hover {
180-
box-shadow: token-utils.slot(fab-extended-hover-container-elevation-shadow, $fallbacks);
183+
@media (hover: hover) {
184+
&:hover {
185+
box-shadow: token-utils.slot(fab-extended-hover-container-elevation-shadow, $fallbacks);
186+
}
181187
}
182188

183189
&:focus {

0 commit comments

Comments
 (0)