Skip to content

Commit 3fc968a

Browse files
committed
fix(material/datepicker): use SVG icons for calendar (#29957)
The calendar's next/previous icons are currently rendered using an `:after` element, borders and a transform. This makes them hard to position accurately and fragile to changes in the container size. These changes switch to using SVG which is more robust. Fixes #29956. (cherry picked from commit 4d3c22c)
1 parent 9c8bd3e commit 3fc968a

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

src/material/datepicker/calendar-header.html

+6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@
2121
<button mat-icon-button type="button" class="mat-calendar-previous-button"
2222
[disabled]="!previousEnabled()" (click)="previousClicked()"
2323
[attr.aria-label]="prevButtonLabel">
24+
<svg viewBox="0 0 24 24" focusable="false" aria-hidden="true">
25+
<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/>
26+
</svg>
2427
</button>
2528

2629
<button mat-icon-button type="button" class="mat-calendar-next-button"
2730
[disabled]="!nextEnabled()" (click)="nextClicked()"
2831
[attr.aria-label]="nextButtonLabel">
32+
<svg viewBox="0 0 24 24" focusable="false" aria-hidden="true">
33+
<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/>
34+
</svg>
2935
</button>
3036
</div>
3137
</div>

src/material/datepicker/calendar.scss

-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@use '@angular/cdk';
22

3-
@use '../core/style/layout-common';
43
@use '../core/focus-indicators/private';
54
@use '../core/tokens/m2/mat/datepicker' as tokens-mat-datepicker;
65
@use '../core/tokens/token-utils';
@@ -16,12 +15,6 @@ $calendar-controls-side-margin: calc(33% / 7 - 16px);
1615
$calendar-arrow-size: 5px !default;
1716
$calendar-arrow-disabled-opacity: 0.5 !default;
1817

19-
// Values chosen to approximate https://material.io/icons/#ic_navigate_before and
20-
// https://material.io/icons/#ic_navigate_next as closely as possible.
21-
$calendar-prev-next-icon-border-width: 2px;
22-
$calendar-prev-next-icon-margin: 15.5px;
23-
$calendar-prev-icon-transform: translateX(2px) rotate(-45deg);
24-
$calendar-next-icon-transform: translateX(-2px) rotate(45deg);
2518
$_tokens: tokens-mat-datepicker.$prefix, tokens-mat-datepicker.get-token-slots();
2619

2720
.mat-calendar {
@@ -94,38 +87,18 @@ $_tokens: tokens-mat-datepicker.$prefix, tokens-mat-datepicker.get-token-slots()
9487

9588
.mat-calendar-previous-button,
9689
.mat-calendar-next-button {
97-
position: relative;
98-
9990
@include token-utils.use-tokens($_tokens...) {
10091
// Needs need a bit more specificity to avoid being overwritten by the .mat-icon-button.
10192
.mat-datepicker-content &:not(.mat-mdc-button-disabled) {
10293
@include token-utils.create-token-slot(color, calendar-navigation-button-icon-color);
10394
}
10495
}
10596

106-
&::after {
107-
@include layout-common.fill;
108-
content: '';
109-
margin: $calendar-prev-next-icon-margin;
110-
border: 0 solid currentColor;
111-
border-top-width: $calendar-prev-next-icon-border-width;
112-
}
113-
11497
[dir='rtl'] & {
11598
transform: rotate(180deg);
11699
}
117100
}
118101

119-
.mat-calendar-previous-button::after {
120-
border-left-width: $calendar-prev-next-icon-border-width;
121-
transform: $calendar-prev-icon-transform;
122-
}
123-
124-
.mat-calendar-next-button::after {
125-
border-right-width: $calendar-prev-next-icon-border-width;
126-
transform: $calendar-next-icon-transform;
127-
}
128-
129102
.mat-calendar-table {
130103
border-spacing: 0;
131104
border-collapse: collapse;

0 commit comments

Comments
 (0)