Skip to content

Commit 3ae1ade

Browse files
committed
fix(datepicker): resolve visual inconsistencies with comparison ranges (#18819)
Fixes some extra circles showing up when they're not supposed to when hovering over the start of the range or when the starts/ends of ranges are the same. Also clears out a few selectors that aren't necessary anymore.
1 parent 59f4ec3 commit 3ae1ade

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

src/material/datepicker/calendar-body.scss

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ $mat-calendar-range-end-body-cell-size:
3838
cursor: pointer;
3939
}
4040

41-
.mat-calendar-body-cell::before,
42-
.mat-calendar-body-cell::after,
43-
.mat-calendar-body-comparison-bridge-start::before {
41+
.mat-calendar-body-cell {
4442
// We use ::before to apply a background to the body cell, because we need to apply a border
4543
// radius to the start/end which means that part of the element will be cut off, making
4644
// hovering through all the cells look glitchy. We can't do it on the cell itself, because
4745
// it's the one that has the event listener and it can't be on the cell content, because
4846
// it always has a border radius.
49-
content: '';
50-
position: absolute;
51-
top: $mat-calendar-body-cell-content-margin;
52-
left: 0;
53-
z-index: 0;
47+
&::before, &::after {
48+
content: '';
49+
position: absolute;
50+
top: $mat-calendar-body-cell-content-margin;
51+
left: 0;
52+
z-index: 0;
5453

55-
// We want the range background to be slightly shorter than the cell so
56-
// that there's a gap when the range goes across multiple rows.
57-
height: $mat-calendar-body-cell-content-size;
58-
width: 100%;
54+
// We want the range background to be slightly shorter than the cell so
55+
// that there's a gap when the range goes across multiple rows.
56+
height: $mat-calendar-body-cell-content-size;
57+
width: 100%;
58+
}
5959
}
6060

6161
.mat-calendar-body-range-start:not(.mat-calendar-body-in-comparison-range)::before,
@@ -99,15 +99,24 @@ $mat-calendar-range-end-body-cell-size:
9999
}
100100
}
101101

102+
// Styles necessary to make RTL work.
102103
[dir='rtl'] {
103104
.mat-calendar-body-comparison-bridge-start.mat-calendar-body-range-end::after,
104-
.mat-calendar-body-comparison-bridge-end.mat-calendar-body-range-start::after,
105-
.mat-calendar-body-range-start.mat-calendar-body-range-end::before,
106-
.mat-calendar-body-range-start.mat-calendar-body-range-end::after {
105+
.mat-calendar-body-comparison-bridge-end.mat-calendar-body-range-start::after {
107106
@include _mat-calendar-body-range-right-radius;
108107
}
109108
}
110109

110+
// Prevents the extra overlap range indication from showing up when it's not supposed to.
111+
.mat-calendar-body-comparison-start.mat-calendar-body-range-end::after,
112+
.mat-calendar-body-comparison-end.mat-calendar-body-range-start::after {
113+
// Note that the RTL selector here is redundant, but we need to keep it in order to
114+
// raise the specificity since it can be overridden by some of the styles from above.
115+
&, [dir='rtl'] & {
116+
width: $mat-calendar-body-cell-content-size;
117+
}
118+
}
119+
111120
.mat-calendar-body-disabled {
112121
cursor: default;
113122
}

src/material/datepicker/calendar-body.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ export class MatCalendarBody implements OnChanges, OnDestroy {
279279

280280
if (cell) {
281281
const value = cell.compareValue;
282-
const hoveredValue = cell.enabled ? value : -1;
282+
283+
// Only set as the hovered value if we're after the start of the range.
284+
const hoveredValue = (cell.enabled && value > this.startValue) ? value : -1;
283285

284286
if (hoveredValue !== this._hoveredValue) {
285287
this._hoveredValue = hoveredValue;

0 commit comments

Comments
 (0)