Skip to content

Commit 6d0a4d2

Browse files
author
Tobias Schweizer
committed
refactor (MatCalendarHeader): fix some styling issues
1 parent c287495 commit 6d0a4d2

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ <h2>Options</h2>
4040
</p>
4141
<p>
4242
<mat-form-field>
43-
<input matInput [matDatepicker]="customCalendarHeaderPicker" placeholder="Custom calendar header"
43+
<mat-label>Custom calendar header</mat-label>
44+
<input matInput [matDatepicker]="customCalendarHeaderPicker"
4445
[disabled]="inputDisabled">
4546
<mat-datepicker-toggle matSuffix [for]="customCalendarHeaderPicker"></mat-datepicker-toggle>
4647
<mat-datepicker #customCalendarHeaderPicker [touchUi]="touch" [disabled]="datepickerDisabled" [calendarHeaderComponent]="customHeader"></mat-datepicker>

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export class DatepickerDemo {
5252
template: `
5353
<div>
5454
<button (click)="previousClicked('year')">&lt;&lt;</button>
55-
<button (click)="previousClicked('month')">&lt;</button>
55+
<button (click)="previousClicked('month')">&lt;</button>
5656
{{periodLabel}}
5757
<button (click)="nextClicked('month')">&gt;</button>
58-
<button (click)="nextClicked('year')">&gt;&gt;</button>
58+
<button (click)="nextClicked('year')">&gt;&gt;</button>
5959
</div>
6060
`
6161
})
@@ -71,19 +71,13 @@ export class CustomHeader {
7171

7272
previousClicked(mode: 'month' | 'year') {
7373
this.calendar.activeDate = mode == 'month' ?
74-
this._dateAdapter.addCalendarMonths(this.calendar.activeDate, -1) :
75-
this._dateAdapter.addCalendarYears(
76-
this.calendar.activeDate,
77-
-1
78-
);
74+
this._dateAdapter.addCalendarMonths(this.calendar.activeDate, -1) :
75+
this._dateAdapter.addCalendarYears(this.calendar.activeDate, -1);
7976
}
8077

8178
nextClicked(mode: 'month' | 'year') {
8279
this.calendar.activeDate = mode == 'month' ?
83-
this._dateAdapter.addCalendarMonths(this.calendar.activeDate, 1) :
84-
this._dateAdapter.addCalendarYears(
85-
this.calendar.activeDate,
86-
1
87-
);
80+
this._dateAdapter.addCalendarMonths(this.calendar.activeDate, 1) :
81+
this._dateAdapter.addCalendarYears(this.calendar.activeDate, 1);
8882
}
8983
}

src/lib/datepicker/calendar.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,31 @@ export class MatCalendarHeader implements OnDestroy {
5252
@Optional() private _dateAdapter: DateAdapter<any>,
5353
@Optional() @Inject(MAT_DATE_FORMATS) private _dateFormats: MatDateFormats,
5454
changeDetectorRef: ChangeDetectorRef) {
55-
_intl.changes.pipe(takeUntil(this._destroyed)).subscribe(
56-
() => changeDetectorRef.markForCheck()
57-
);
55+
_intl.changes.pipe(takeUntil(this._destroyed))
56+
.subscribe(() => changeDetectorRef.markForCheck());
5857
}
5958

6059
/** The label for the current calendar view. */
6160
get periodButtonText(): string {
6261
if (this.calendar.currentView == 'month') {
6362
return this._dateAdapter
64-
.format(this.calendar.activeDate, this._dateFormats.display.monthYearLabel)
65-
.toLocaleUpperCase();
63+
.format(this.calendar.activeDate, this._dateFormats.display.monthYearLabel)
64+
.toLocaleUpperCase();
6665
}
6766
if (this.calendar.currentView == 'year') {
6867
return this._dateAdapter.getYearName(this.calendar.activeDate);
6968
}
7069
const activeYear = this._dateAdapter.getYear(this.calendar.activeDate);
7170
const firstYearInView = this._dateAdapter.getYearName(
72-
this._dateAdapter.createDate(activeYear - activeYear % 24, 0, 1));
71+
this._dateAdapter.createDate(activeYear - activeYear % 24, 0, 1));
7372
const lastYearInView = this._dateAdapter.getYearName(
74-
this._dateAdapter.createDate(activeYear + yearsPerPage - 1 - activeYear % 24, 0, 1));
73+
this._dateAdapter.createDate(activeYear + yearsPerPage - 1 - activeYear % 24, 0, 1));
7574
return `${firstYearInView} \u2013 ${lastYearInView}`;
7675
}
7776

7877
get periodButtonLabel(): string {
7978
return this.calendar.currentView == 'month' ?
80-
this._intl.switchToMultiYearViewLabel : this._intl.switchToMonthViewLabel;
79+
this._intl.switchToMultiYearViewLabel : this._intl.switchToMonthViewLabel;
8180
}
8281

8382
/** The label for the the previous button. */
@@ -106,19 +105,18 @@ export class MatCalendarHeader implements OnDestroy {
106105
/** Handles user clicks on the previous button. */
107106
previousClicked(): void {
108107
this.calendar.activeDate = this.calendar.currentView == 'month' ?
109-
this._dateAdapter.addCalendarMonths(this.calendar.activeDate, -1) :
108+
this._dateAdapter.addCalendarMonths(this.calendar.activeDate, -1) :
110109
this._dateAdapter.addCalendarYears(
111-
this.calendar.activeDate,
112-
this.calendar.currentView == 'year' ? -1 : -yearsPerPage
110+
this.calendar.activeDate, this.calendar.currentView == 'year' ? -1 : -yearsPerPage
113111
);
114112
}
115113

116114
/** Handles user clicks on the next button. */
117115
nextClicked(): void {
118116
this.calendar.activeDate = this.calendar.currentView == 'month' ?
119-
this._dateAdapter.addCalendarMonths(this.calendar.activeDate, 1) :
117+
this._dateAdapter.addCalendarMonths(this.calendar.activeDate, 1) :
120118
this._dateAdapter.addCalendarYears(
121-
this.calendar.activeDate,
119+
this.calendar.activeDate,
122120
this.calendar.currentView == 'year' ? 1 : yearsPerPage
123121
);
124122
}
@@ -129,13 +127,13 @@ export class MatCalendarHeader implements OnDestroy {
129127
return true;
130128
}
131129
return !this.calendar.minDate ||
132-
!this.calendar.isSameView(this.calendar.activeDate, this.calendar.minDate);
130+
!this.calendar.isSameView(this.calendar.activeDate, this.calendar.minDate);
133131
}
134132

135133
/** Whether the next period button is enabled. */
136134
nextEnabled(): boolean {
137135
return !this.calendar.maxDate ||
138-
!this.calendar.isSameView(this.calendar.activeDate, this.calendar.maxDate);
136+
!this.calendar.isSameView(this.calendar.activeDate, this.calendar.maxDate);
139137
}
140138

141139
ngOnDestroy() {

0 commit comments

Comments
 (0)