Skip to content

Commit 106b8a7

Browse files
authored
fix(material/datepicker): hover styles not disabled on touch devices (#23915)
When we introduced the date range picker, some selectors in the calendar became much more specific which ended up overriding the styles that disable the hover indication on touch devices. Now that we don't need to worry about IE, these changes use the `hover` media query to enable hovering only on non-touch devices instead. Fixes #23904.
1 parent 8ae41b0 commit 106b8a7

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/material/datepicker/_datepicker-theme.scss

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ $calendar-weekday-table-font-size: 11px !default;
4242
theming.get-color-from-palette($palette, default-contrast);
4343
}
4444

45-
.mat-calendar-body-cell:not(.mat-calendar-body-disabled):hover,
4645
.cdk-keyboard-focused .mat-calendar-body-active,
4746
.cdk-program-focused .mat-calendar-body-active {
48-
& > .mat-calendar-body-cell-content {
49-
@include _unselected-cell {
50-
background-color: theming.get-color-from-palette($palette, 0.3);
51-
}
47+
@include _highlighted-cell($palette);
48+
}
49+
50+
@media (hover: hover) {
51+
.mat-calendar-body-cell:not(.mat-calendar-body-disabled):hover {
52+
@include _highlighted-cell($palette);
5253
}
5354
}
5455
}
@@ -60,6 +61,15 @@ $calendar-weekday-table-font-size: 11px !default;
6061
}
6162
}
6263

64+
// Styles for a highlighted calendar cell (e.g. hovered or focused).
65+
@mixin _highlighted-cell($palette) {
66+
& > .mat-calendar-body-cell-content {
67+
@include _unselected-cell {
68+
background-color: theming.get-color-from-palette($palette, 0.3);
69+
}
70+
}
71+
}
72+
6373
@mixin color($config-or-theme) {
6474
$config: theming.get-color-config($config-or-theme);
6575
$foreground: map.get($config, foreground);

src/material/datepicker/calendar-body.scss

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,3 @@ $calendar-range-end-body-cell-size:
274274
text-align: right;
275275
}
276276
}
277-
278-
// Disable the hover styles on non-hover devices. Since this is more of a progressive
279-
// enhancement and not all desktop browsers support this kind of media query, we can't
280-
// use something like `@media (hover)`.
281-
@media (hover: none) {
282-
.mat-calendar-body-cell:not(.mat-calendar-body-disabled):hover {
283-
& > .mat-calendar-body-cell-content:not(.mat-calendar-body-selected) {
284-
background-color: transparent;
285-
}
286-
}
287-
}

0 commit comments

Comments
 (0)