Skip to content

Commit ca54283

Browse files
authored
feat(material/datepicker): make compatible with MDC & legacy components (#25648)
BREAKING CHANGE: Buttons inside the datepicker popup and datepicker toggle now use the MDC-based button implementation. They have different CSS classes and styles, so custom style overrides may need to be updated
1 parent 73ef52c commit ca54283

33 files changed

+926
-103
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
/src/dev-app/layout/** @andrewseguin
187187
/src/dev-app/legacy-card/** @mmalerba
188188
/src/dev-app/legacy-checkbox/** @mmalerba
189+
/src/dev-app/legacy-datepicker/** @mmalerba
189190
/src/dev-app/legacy-dialog/** @devversion
190191
/src/dev-app/legacy-input/** @mmalerba
191192
/src/dev-app/legacy-list/** @mmalerba

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ng_module(
5252
"//src/dev-app/legacy-button",
5353
"//src/dev-app/legacy-card",
5454
"//src/dev-app/legacy-checkbox",
55+
"//src/dev-app/legacy-datepicker",
5556
"//src/dev-app/legacy-dialog",
5657
"//src/dev-app/legacy-input",
5758
"//src/dev-app/legacy-list",

src/dev-app/datepicker/BUILD.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ ng_module(
1212
":custom_header_scss",
1313
],
1414
deps = [
15+
"//src/material/button",
16+
"//src/material/checkbox",
1517
"//src/material/core",
1618
"//src/material/datepicker",
19+
"//src/material/form-field",
1720
"//src/material/icon",
18-
"//src/material/legacy-button",
19-
"//src/material/legacy-checkbox",
20-
"//src/material/legacy-form-field",
21-
"//src/material/legacy-input",
22-
"//src/material/legacy-select",
21+
"//src/material/input",
22+
"//src/material/select",
2323
],
2424
)
2525

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,33 @@ <h2>Range picker with custom selection strategy</h2>
302302
</mat-date-range-picker>
303303
</mat-form-field>
304304
</div>
305+
306+
<h2>With custom icon</h2>
307+
<p>
308+
<mat-form-field appearance="fill">
309+
<mat-label>Custom icon</mat-label>
310+
<input matInput [matDatepicker]="ci1">
311+
<mat-datepicker-toggle matSuffix [for]="ci1">
312+
<mat-icon matDatepickerToggleIcon>add</mat-icon>
313+
</mat-datepicker-toggle>
314+
<mat-datepicker #ci1></mat-datepicker>
315+
</mat-form-field>
316+
<br>
317+
<mat-form-field appearance="outline">
318+
<mat-label>Custom icon</mat-label>
319+
<input matInput [matDatepicker]="ci2">
320+
<mat-datepicker-toggle matSuffix [for]="ci2">
321+
<mat-icon matDatepickerToggleIcon>add</mat-icon>
322+
</mat-datepicker-toggle>
323+
<mat-datepicker #ci2></mat-datepicker>
324+
</mat-form-field>
325+
<br>
326+
<mat-form-field>
327+
<mat-label>Custom icon</mat-label>
328+
<input matInput [matDatepicker]="ci3">
329+
<mat-datepicker #ci3></mat-datepicker>
330+
</mat-form-field>
331+
<mat-datepicker-toggle matSuffix [for]="ci3">
332+
<mat-icon matDatepickerToggleIcon>add</mat-icon>
333+
</mat-datepicker-toggle>
334+
</p>

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {
2020
} from '@angular/core';
2121
import {CommonModule} from '@angular/common';
2222
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
23-
import {MatLegacyButtonModule} from '@angular/material/legacy-button';
24-
import {MatLegacyCheckboxModule} from '@angular/material/legacy-checkbox';
23+
import {MatButtonModule} from '@angular/material/button';
24+
import {MatCheckboxModule} from '@angular/material/checkbox';
2525
import {
2626
DateAdapter,
2727
MAT_DATE_FORMATS,
@@ -38,10 +38,10 @@ import {
3838
DateRange,
3939
MatDatepickerModule,
4040
} from '@angular/material/datepicker';
41-
import {MatLegacyFormFieldModule} from '@angular/material/legacy-form-field';
41+
import {MatFormFieldModule} from '@angular/material/form-field';
4242
import {MatIconModule} from '@angular/material/icon';
43-
import {MatLegacyInputModule} from '@angular/material/legacy-input';
44-
import {MatLegacySelectModule} from '@angular/material/legacy-select';
43+
import {MatInputModule} from '@angular/material/input';
44+
import {MatSelectModule} from '@angular/material/select';
4545
import {Subject} from 'rxjs';
4646
import {takeUntil} from 'rxjs/operators';
4747

@@ -185,14 +185,14 @@ export class CustomHeaderNgContent<D> {
185185
imports: [
186186
CommonModule,
187187
FormsModule,
188-
MatLegacyButtonModule,
189-
MatLegacyCheckboxModule,
188+
MatButtonModule,
189+
MatCheckboxModule,
190190
MatDatepickerModule,
191-
MatLegacyFormFieldModule,
191+
MatFormFieldModule,
192192
MatIconModule,
193-
MatLegacyInputModule,
193+
MatInputModule,
194194
MatNativeDateModule,
195-
MatLegacySelectModule,
195+
MatSelectModule,
196196
ReactiveFormsModule,
197197
CustomHeader,
198198
CustomHeaderNgContent,

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class DevAppLayout {
109109
{name: 'Legacy Button', route: '/legacy-button'},
110110
{name: 'Legacy Card', route: '/legacy-card'},
111111
{name: 'Legacy Checkbox', route: '/legacy-checkbox'},
112+
{name: 'Legacy Datepicker', route: '/legacy-datepicker'},
112113
{name: 'Legacy Dialog', route: '/legacy-dialog'},
113114
{name: 'Legacy Input', route: '/legacy-input'},
114115
{name: 'Legacy List', route: '/legacy-list'},
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
load("//tools:defaults.bzl", "ng_module", "sass_binary")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
ng_module(
6+
name = "legacy-datepicker",
7+
srcs = glob(["**/*.ts"]),
8+
assets = [
9+
"datepicker-demo.html",
10+
"custom-header.html",
11+
":datepicker_demo_scss",
12+
":custom_header_scss",
13+
],
14+
deps = [
15+
"//src/material/core",
16+
"//src/material/datepicker",
17+
"//src/material/icon",
18+
"//src/material/legacy-button",
19+
"//src/material/legacy-checkbox",
20+
"//src/material/legacy-form-field",
21+
"//src/material/legacy-input",
22+
"//src/material/legacy-select",
23+
],
24+
)
25+
26+
sass_binary(
27+
name = "datepicker_demo_scss",
28+
src = "datepicker-demo.scss",
29+
deps = [
30+
"//:mdc_sass_lib",
31+
"//src/material:sass_lib",
32+
],
33+
)
34+
35+
sass_binary(
36+
name = "custom_header_scss",
37+
src = "custom-header.scss",
38+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="demo-calendar-header">
2+
<button mat-icon-button class="demo-double-arrow" (click)="previousClicked('year')">
3+
<mat-icon>keyboard_arrow_left</mat-icon>
4+
<mat-icon>keyboard_arrow_left</mat-icon>
5+
</button>
6+
<button mat-icon-button (click)="previousClicked('month')">
7+
<mat-icon>keyboard_arrow_left</mat-icon>
8+
</button>
9+
<span class="demo-calendar-header-label">{{periodLabel}}</span>
10+
<button mat-icon-button (click)="nextClicked('month')">
11+
<mat-icon>keyboard_arrow_right</mat-icon>
12+
</button>
13+
<button mat-icon-button class="demo-double-arrow" (click)="nextClicked('year')">
14+
<mat-icon>keyboard_arrow_right</mat-icon>
15+
<mat-icon>keyboard_arrow_right</mat-icon>
16+
</button>
17+
</div>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.demo-calendar-header {
2+
display: flex;
3+
align-items: center;
4+
padding: 0.5em;
5+
}
6+
7+
.demo-calendar-header-label {
8+
flex: 1;
9+
height: 1em;
10+
font-weight: bold;
11+
text-align: center;
12+
}
13+
14+
.demo-double-arrow .mat-icon {
15+
margin: -22%;
16+
}

0 commit comments

Comments
 (0)