Skip to content

Commit 206f0fc

Browse files
authored
fix(material/datepicker): fix M3 styles (#28556)
* fix(material/datepicker): fix M3 styles * fix(material/datepicker): fix m2 text button color
1 parent acf72e1 commit 206f0fc

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

src/dev-app/datepicker/datepicker-demo.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h2>Options</h2>
1515
</mat-form-field>
1616
</p>
1717
<p>
18-
<mat-form-field color="accent">
18+
<mat-form-field [color]="color">
1919
<mat-label>Min date</mat-label>
2020
<input matInput [matDatepicker]="minDatePicker" [(ngModel)]="minDate"
2121
[disabled]="inputDisabled" [max]="maxDate">
@@ -29,7 +29,7 @@ <h2>Options</h2>
2929
}
3030
</mat-datepicker>
3131
</mat-form-field>
32-
<mat-form-field color="accent">
32+
<mat-form-field [color]="color">
3333
<mat-label>Max date</mat-label>
3434
<input matInput [matDatepicker]="maxDatePicker" [(ngModel)]="maxDate"
3535
[disabled]="inputDisabled" [min]="minDate">
@@ -45,7 +45,7 @@ <h2>Options</h2>
4545
</mat-form-field>
4646
</p>
4747
<p>
48-
<mat-form-field color="accent">
48+
<mat-form-field [color]="color">
4949
<mat-label>Start at date</mat-label>
5050
<input matInput [matDatepicker]="startAtPicker" [(ngModel)]="startAt"
5151
[disabled]="inputDisabled">

src/material-experimental/theming/_custom-tokens.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,10 @@
341341
toggle-active-state-icon-color: map.get($systems, md-sys-color, on-surface-variant),
342342
toggle-icon-color: map.get($systems, md-sys-color, on-surface-variant),
343343
calendar-body-label-text-color: map.get($systems, md-sys-color, on-surface),
344+
calendar-period-button-text-color: map.get($systems, md-sys-color, on-surface-variant),
344345
calendar-period-button-icon-color: map.get($systems, md-sys-color, on-surface-variant),
345346
calendar-navigation-button-icon-color: map.get($systems, md-sys-color, on-surface-variant),
346-
calendar-header-divider-color: map.get($systems, md-sys-color, outline-variant),
347+
calendar-header-divider-color: transparent,
347348
calendar-header-text-color: map.get($systems, md-sys-color, on-surface-variant),
348349
calendar-date-today-outline-color: map.get($systems, md-sys-color, primary),
349350
calendar-date-today-disabled-state-outline-color: mat.private-safe-color-change(
@@ -368,6 +369,9 @@
368369
),
369370
calendar-container-background-color: map.get($systems, md-sys-color, surface-container-high),
370371
calendar-container-text-color: map.get($systems, md-sys-color, on-surface),
372+
calendar-container-elevation-shadow: _hardcode(mdc-elevation.elevation-box-shadow(0),
373+
$exclude-hardcoded),
374+
calendar-container-shape: map.get($systems, md-sys-shape, corner-large),
371375
calendar-text-font: map.get($systems, md-sys-typescale, body-large-font),
372376
calendar-text-size: map.get($systems, md-sys-typescale, body-large-size),
373377
calendar-body-label-text-size: map.get($systems, md-sys-typescale, title-small-size),

src/material/core/tokens/m2/mat/_datepicker.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use '@material/elevation/elevation-theme' as mdc-elevation;
12
@use 'sass:color';
23
@use 'sass:meta';
34
@use 'sass:math';
@@ -30,7 +31,10 @@ $private-default-overlap-color: #a8dab5;
3031
// Tokens that can't be configured through Angular Material's current theming API,
3132
// but may be in a future version of the theming API.
3233
@function get-unthemable-tokens() {
33-
@return ();
34+
@return (
35+
calendar-container-shape: 4px,
36+
calendar-container-elevation-shadow: mdc-elevation.elevation-box-shadow(4),
37+
);
3438
}
3539

3640
// Tokens that can be configured through Angular Material's color theming API.
@@ -43,6 +47,8 @@ $private-default-overlap-color: #a8dab5;
4347
$hint-text-color: inspection.get-theme-color($theme, foreground, hint-text);
4448
$preview-outline-color: $divider-color;
4549
$today-disabled-outline-color: null;
50+
$is-dark: inspection.get-theme-type($theme) == dark;
51+
$on-surface: if($is-dark, #fff, #000);
4652

4753
$primary-color: inspection.get-theme-color($theme, primary);
4854
$range-tokens: get-range-color-tokens(private-get-range-background-color($primary-color));
@@ -67,6 +73,7 @@ $private-default-overlap-color: #a8dab5;
6773
@return sass-utils.merge-all($calendar-tokens, $toggle-tokens, $range-tokens, (
6874
toggle-icon-color: $inactive-icon-color,
6975
calendar-body-label-text-color: $secondary-text-color,
76+
calendar-period-button-text-color: $on-surface,
7077
calendar-period-button-icon-color: $inactive-icon-color,
7178
calendar-navigation-button-icon-color: $inactive-icon-color,
7279
calendar-header-divider-color: $divider-color,

src/material/datepicker/_datepicker-theme.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ $calendar-weekday-table-font-size: 11px !default;
3434
@if inspection.get-theme-version($theme) == 1 {
3535
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
3636
}
37-
@else {}
37+
@else {
38+
@include sass-utils.current-selector-or-root() {
39+
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
40+
tokens-mat-datepicker.get-unthemable-tokens());
41+
}
42+
}
3843
}
3944

4045
/// Outputs color theme styles for the mat-datepicker.

src/material/datepicker/calendar.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ $_tokens: tokens-mat-datepicker.$prefix, tokens-mat-datepicker.get-token-slots()
5959
@include token-utils.use-tokens($_tokens...) {
6060
@include token-utils.create-token-slot(font-size, calendar-period-button-text-size);
6161
@include token-utils.create-token-slot(font-weight, calendar-period-button-text-weight);
62+
@include token-utils.create-token-slot(--mdc-text-button-label-text-color,
63+
calendar-period-button-text-color);
6264
}
6365
}
6466

src/material/datepicker/datepicker-content.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ $touch-max-height: 788px;
2727

2828

2929
.mat-datepicker-content {
30-
@include elevation.elevation(4);
3130
display: block;
3231
border-radius: 4px;
3332

3433
@include token-utils.use-tokens(
3534
tokens-mat-datepicker.$prefix, tokens-mat-datepicker.get-token-slots()) {
3635
@include token-utils.create-token-slot(background-color, calendar-container-background-color);
3736
@include token-utils.create-token-slot(color, calendar-container-text-color);
37+
@include token-utils.create-token-slot(box-shadow, calendar-container-elevation-shadow);
38+
@include token-utils.create-token-slot(border-radius, calendar-container-shape);
3839
}
3940

4041
.mat-calendar {

0 commit comments

Comments
 (0)