Skip to content

Commit a320af2

Browse files
crisbetojelbourn
authored andcommittedNov 3, 2018
fix(button-toggle): remove hover state on touch devices (#13724)
Negates the `:hover` state on touch devices, in order to prevent it from lingering after the user taps on a button toggle. Also fixes the native tap highlight showing up if the user taps on a disabled toggle group.
1 parent 8fad5d1 commit a320af2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed
 

‎src/lib/button-toggle/button-toggle.scss

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ $mat-button-toggle-legacy-border-radius: 2px !default;
1818
white-space: nowrap;
1919
overflow: hidden;
2020
border-radius: $mat-button-toggle-legacy-border-radius;
21+
-webkit-tap-highlight-color: transparent;
2122

2223
@include cdk-high-contrast {
2324
outline: solid 1px;
@@ -46,7 +47,6 @@ $mat-button-toggle-legacy-border-radius: 2px !default;
4647
.mat-button-toggle {
4748
white-space: nowrap;
4849
position: relative;
49-
-webkit-tap-highlight-color: transparent;
5050

5151
&.cdk-keyboard-focused {
5252
.mat-button-toggle-focus-overlay {
@@ -77,6 +77,16 @@ $mat-button-toggle-legacy-border-radius: 2px !default;
7777
opacity: 0.5;
7878
}
7979
}
80+
81+
// On touch devices the hover state will linger on the element after the user has tapped.
82+
// Disable it, because it can be confused with focus. We target the :hover state explicitly,
83+
// because we still want to preserve the keyboard focus state for hybrid devices that have
84+
// a keyboard and a touchscreen.
85+
@media (hover: none) {
86+
&:not(.mat-button-toggle-disabled):hover .mat-button-toggle-focus-overlay {
87+
display: none;
88+
}
89+
}
8090
}
8191

8292
.mat-button-toggle-label-content {

0 commit comments

Comments
 (0)
Please sign in to comment.