Skip to content

Commit 6d4413f

Browse files
crisbetotinayuangao
authored andcommitted
refactor(datepicker): remove MatIconModule dependency (#9499)
Removes the dependency between the `MatDatepickerModule` and `MatIconModule`, because we were only using a handful of styles but were pulling in all of the overhead that comes with the icon module (e.g. the icon registry, the dependency to the `HttpClientModule` etc.).
1 parent 63a5588 commit 6d4413f

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

src/lib/datepicker/BUILD.bazel

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ ng_module(
99
module_name = "@angular/material/datepicker",
1010
assets = [
1111
":datepicker_content_css",
12+
":datepicker_toggle_css",
1213
":calendar_body_css",
1314
":calendar_css",
1415
],
1516
deps = [
1617
"//src/lib/core",
1718
"//src/lib/button",
1819
"//src/lib/dialog",
19-
"//src/lib/icon",
2020
"//src/lib/input",
2121
"//src/cdk/a11y",
2222
"//src/cdk/bidi",
@@ -35,6 +35,12 @@ sass_binary(
3535
deps = ["//src/lib/core:core_scss_lib"],
3636
)
3737

38+
sass_binary(
39+
name = "datepicker_toggle_scss",
40+
src = "datepicker-toggle.scss",
41+
deps = ["//src/lib/core:core_scss_lib"],
42+
)
43+
3844
sass_binary(
3945
name = "calendar_scss",
4046
src = "calendar.scss",
@@ -56,6 +62,15 @@ genrule(
5662
cmd = "cat $(locations :datepicker_content_scss) > $@",
5763
)
5864

65+
# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir.
66+
# Copy the output of the sass_binary such that the filename and path match what we expect.
67+
genrule(
68+
name = "datepicker_toggle_css",
69+
srcs = [":datepicker_toggle_scss"],
70+
outs = ["datepicker-toggle.css"],
71+
cmd = "cat $(locations :datepicker_toggle_scss) > $@",
72+
)
73+
5974
# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir.
6075
# Copy the output of the sass_binary such that the filename and path match what we expect.
6176
genrule(

src/lib/datepicker/datepicker-module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {CommonModule} from '@angular/common';
1212
import {NgModule} from '@angular/core';
1313
import {MatButtonModule} from '@angular/material/button';
1414
import {MatDialogModule} from '@angular/material/dialog';
15-
import {MatIconModule} from '@angular/material/icon';
1615
import {MatCalendar} from './calendar';
1716
import {MatCalendarBody} from './calendar-body';
1817
import {
@@ -33,7 +32,6 @@ import {MatYearView} from './year-view';
3332
CommonModule,
3433
MatButtonModule,
3534
MatDialogModule,
36-
MatIconModule,
3735
OverlayModule,
3836
A11yModule,
3937
],
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<button mat-icon-button type="button" [attr.aria-label]="_intl.openCalendarLabel"
22
[disabled]="disabled" (click)="_open($event)">
3-
<mat-icon *ngIf="!_customIcon">
4-
<svg viewBox="0 0 24 24" width="100%" height="100%" fill="currentColor"
5-
style="vertical-align: top" focusable="false">
6-
<path d="M0 0h24v24H0z" fill="none"/>
7-
<path d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z"/>
8-
</svg>
9-
</mat-icon>
3+
4+
<svg
5+
*ngIf="!_customIcon"
6+
class="mat-datepicker-toggle-default-icon"
7+
viewBox="0 0 24 24"
8+
width="24px"
9+
height="24px"
10+
fill="currentColor"
11+
focusable="false">
12+
<path d="M0 0h24v24H0z" fill="none"/>
13+
<path d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z"/>
14+
</svg>
1015

1116
<ng-content select="[matDatepickerToggleIcon]"></ng-content>
1217
</button>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.mat-datepicker-toggle-default-icon {
2+
.mat-form-field-prefix &,
3+
.mat-form-field-suffix & {
4+
width: 1em;
5+
}
6+
}

src/lib/datepicker/datepicker-toggle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class MatDatepickerToggleIcon {}
3838
moduleId: module.id,
3939
selector: 'mat-datepicker-toggle',
4040
templateUrl: 'datepicker-toggle.html',
41+
styleUrls: ['datepicker-toggle.css'],
4142
host: {
4243
'class': 'mat-datepicker-toggle',
4344
'[class.mat-datepicker-toggle-active]': 'datepicker && datepicker.opened',

0 commit comments

Comments
 (0)