Skip to content

Commit d822649

Browse files
authored
fix(datepicker): add gap between range rows and handle rtl (#18660)
* Makes the range background shorter so that there's a gap when a range spans across multiple rows. This makes it easier to see what's going on. * Fixes the range styles not accounting for RTL layouts.
1 parent 0b2abce commit d822649

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

src/material/datepicker/calendar-body.scss

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ $mat-calendar-body-cell-radius: 999px !default;
1414
$mat-calendar-body-min-size: 7 * $mat-calendar-body-cell-min-size !default;
1515
$mat-calendar-body-cell-content-size: 100% - $mat-calendar-body-cell-content-margin * 2 !default;
1616

17+
$mat-calendar-range-end-body-cell-size:
18+
$mat-calendar-body-cell-content-size + $mat-calendar-body-cell-content-margin !default;
1719

1820
.mat-calendar-body {
1921
min-width: $mat-calendar-body-min-size;
@@ -43,10 +45,44 @@ $mat-calendar-body-cell-content-size: 100% - $mat-calendar-body-cell-content-mar
4345
&::before {
4446
content: '';
4547
position: absolute;
46-
top: 0;
47-
bottom: 0;
48+
top: $mat-calendar-body-cell-content-margin;
4849
left: 0;
49-
right: 0;
50+
51+
// We want the range background to be slightly shorter than the cell so
52+
// that there's a gap when the range goes across multiple rows.
53+
height: $mat-calendar-body-cell-content-size;
54+
width: 100%;
55+
}
56+
}
57+
58+
.mat-calendar-body-range-start::before {
59+
// Since the range background isn't a perfect circle, we need to size
60+
// and offset the start so that it aligns with the main circle.
61+
left: $mat-calendar-body-cell-content-margin;
62+
width: $mat-calendar-range-end-body-cell-size;
63+
border-top-left-radius: $mat-calendar-body-cell-radius;
64+
border-bottom-left-radius: $mat-calendar-body-cell-radius;
65+
66+
[dir='rtl'] & {
67+
left: 0;
68+
border-radius: 0;
69+
border-top-right-radius: $mat-calendar-body-cell-radius;
70+
border-bottom-right-radius: $mat-calendar-body-cell-radius;
71+
}
72+
}
73+
74+
.mat-calendar-body-range-end::before {
75+
// Since the range background isn't a perfect circle, we need to
76+
// resize the end so that it aligns with the main circle.
77+
width: $mat-calendar-range-end-body-cell-size;
78+
border-top-right-radius: $mat-calendar-body-cell-radius;
79+
border-bottom-right-radius: $mat-calendar-body-cell-radius;
80+
81+
[dir='rtl'] & {
82+
left: $mat-calendar-body-cell-content-margin;
83+
border-radius: 0;
84+
border-top-left-radius: $mat-calendar-body-cell-radius;
85+
border-bottom-left-radius: $mat-calendar-body-cell-radius;
5086
}
5187
}
5288

@@ -81,16 +117,6 @@ $mat-calendar-body-cell-content-size: 100% - $mat-calendar-body-cell-content-mar
81117
}
82118
}
83119

84-
.mat-calendar-body-range-start::before {
85-
border-top-left-radius: $mat-calendar-body-cell-radius;
86-
border-bottom-left-radius: $mat-calendar-body-cell-radius;
87-
}
88-
89-
.mat-calendar-body-range-end::before {
90-
border-top-right-radius: $mat-calendar-body-cell-radius;
91-
border-bottom-right-radius: $mat-calendar-body-cell-radius;
92-
}
93-
94120
@include cdk-high-contrast(active, off) {
95121
.mat-datepicker-popup:not(:empty),
96122
.mat-calendar-body-selected {

src/material/datepicker/calendar-body.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ export class MatCalendarBody implements OnChanges, OnDestroy {
217217

218218
if (cell) {
219219
this._ngZone.run(() => {
220-
this._hoveredValue = cell.enabled ? cell.compareValue : -1;
220+
this._hoveredValue =
221+
cell.enabled && cell.compareValue !== this.startValue ? cell.compareValue : -1;
221222
this._changeDetectorRef.markForCheck();
222223
});
223224
}

0 commit comments

Comments
 (0)