Skip to content

Commit c092e84

Browse files
tobiasschweizermmalerba
authored andcommitted
DatePicker: update names of weekdays in month view on init (#16689)
* feature (datepicker): update names of weekdays in month view on init * feature (datepicker): make _initWeekdays a private method (cherry picked from commit 19453d4)
1 parent 4803858 commit c092e84

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/material/datepicker/month-view.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,6 @@ export class MatMonthView<D> implements AfterContentInit {
144144
throw createMissingDateImplError('MAT_DATE_FORMATS');
145145
}
146146

147-
const firstDayOfWeek = this._dateAdapter.getFirstDayOfWeek();
148-
const narrowWeekdays = this._dateAdapter.getDayOfWeekNames('narrow');
149-
const longWeekdays = this._dateAdapter.getDayOfWeekNames('long');
150-
151-
// Rotate the labels for days of the week based on the configured first day of the week.
152-
let weekdays = longWeekdays.map((long, i) => {
153-
return {long, narrow: narrowWeekdays[i]};
154-
});
155-
this._weekdays = weekdays.slice(firstDayOfWeek).concat(weekdays.slice(0, firstDayOfWeek));
156-
157147
this._activeDate = this._dateAdapter.today();
158148
}
159149

@@ -252,6 +242,7 @@ export class MatMonthView<D> implements AfterContentInit {
252242
(DAYS_PER_WEEK + this._dateAdapter.getDayOfWeek(firstOfMonth) -
253243
this._dateAdapter.getFirstDayOfWeek()) % DAYS_PER_WEEK;
254244

245+
this._initWeekdays();
255246
this._createWeekCells();
256247
this._changeDetectorRef.markForCheck();
257248
}
@@ -261,6 +252,19 @@ export class MatMonthView<D> implements AfterContentInit {
261252
this._matCalendarBody._focusActiveCell();
262253
}
263254

255+
/** Initializes the weekdays. */
256+
private _initWeekdays() {
257+
const firstDayOfWeek = this._dateAdapter.getFirstDayOfWeek();
258+
const narrowWeekdays = this._dateAdapter.getDayOfWeekNames('narrow');
259+
const longWeekdays = this._dateAdapter.getDayOfWeekNames('long');
260+
261+
// Rotate the labels for days of the week based on the configured first day of the week.
262+
let weekdays = longWeekdays.map((long, i) => {
263+
return {long, narrow: narrowWeekdays[i]};
264+
});
265+
this._weekdays = weekdays.slice(firstDayOfWeek).concat(weekdays.slice(0, firstDayOfWeek));
266+
}
267+
264268
/** Creates MatCalendarCells for the dates in this month. */
265269
private _createWeekCells() {
266270
const daysInMonth = this._dateAdapter.getNumDaysInMonth(this.activeDate);

0 commit comments

Comments
 (0)