@@ -34,6 +34,7 @@ import {
34
34
SimpleChanges ,
35
35
OnChanges ,
36
36
inject ,
37
+ signal ,
37
38
} from '@angular/core' ;
38
39
import { DateAdapter , MAT_DATE_FORMATS , MatDateFormats } from '../core' ;
39
40
import { Directionality } from '@angular/cdk/bidi' ;
@@ -183,40 +184,40 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
183
184
@ViewChild ( MatCalendarBody ) _matCalendarBody : MatCalendarBody ;
184
185
185
186
/** The label for this month (e.g. "January 2017"). */
186
- _monthLabel : string ;
187
+ _monthLabel = signal ( '' ) ;
187
188
188
189
/** Grid of calendar cells representing the dates of the month. */
189
- _weeks : MatCalendarCell [ ] [ ] ;
190
+ _weeks = signal < MatCalendarCell [ ] [ ] > ( [ ] ) ;
190
191
191
192
/** The number of blank cells in the first row before the 1st of the month. */
192
- _firstWeekOffset : number ;
193
+ _firstWeekOffset = signal ( 0 ) ;
193
194
194
195
/** Start value of the currently-shown date range. */
195
- _rangeStart : number | null ;
196
+ _rangeStart = signal < number | null > ( null ) ;
196
197
197
198
/** End value of the currently-shown date range. */
198
- _rangeEnd : number | null ;
199
+ _rangeEnd = signal < number | null > ( null ) ;
199
200
200
201
/** Start value of the currently-shown comparison date range. */
201
- _comparisonRangeStart : number | null ;
202
+ _comparisonRangeStart = signal < number | null > ( null ) ;
202
203
203
204
/** End value of the currently-shown comparison date range. */
204
- _comparisonRangeEnd : number | null ;
205
+ _comparisonRangeEnd = signal < number | null > ( null ) ;
205
206
206
207
/** Start of the preview range. */
207
- _previewStart : number | null ;
208
+ _previewStart = signal < number | null > ( null ) ;
208
209
209
210
/** End of the preview range. */
210
- _previewEnd : number | null ;
211
+ _previewEnd = signal < number | null > ( null ) ;
211
212
212
213
/** Whether the user is currently selecting a range of dates. */
213
- _isRange : boolean ;
214
+ _isRange = signal ( false ) ;
214
215
215
216
/** The date of the month that today falls on. Null if today is in another month. */
216
- _todayDate : number | null ;
217
+ _todayDate = signal < number | null > ( null ) ;
217
218
218
219
/** The names of the weekdays. */
219
- _weekdays : { long : string ; narrow : string ; id : number } [ ] ;
220
+ _weekdays = signal < { long : string ; narrow : string ; id : number } [ ] > ( [ ] ) ;
220
221
221
222
constructor ( ...args : unknown [ ] ) ;
222
223
@@ -359,7 +360,7 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
359
360
return ;
360
361
case ESCAPE :
361
362
// Abort the current range selection if the user presses escape mid-selection.
362
- if ( this . _previewEnd != null && ! hasModifierKey ( event ) ) {
363
+ if ( this . _previewEnd ( ) != null && ! hasModifierKey ( event ) ) {
363
364
this . _clearPreview ( ) ;
364
365
// If a drag is in progress, cancel the drag without changing the
365
366
// current selection.
@@ -402,23 +403,26 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
402
403
/** Initializes this month view. */
403
404
_init ( ) {
404
405
this . _setRanges ( this . selected ) ;
405
- this . _todayDate = this . _getCellCompareValue ( this . _dateAdapter . today ( ) ) ;
406
- this . _monthLabel = this . _dateFormats . display . monthLabel
407
- ? this . _dateAdapter . format ( this . activeDate , this . _dateFormats . display . monthLabel )
408
- : this . _dateAdapter
409
- . getMonthNames ( 'short' )
410
- [ this . _dateAdapter . getMonth ( this . activeDate ) ] . toLocaleUpperCase ( ) ;
406
+ this . _todayDate . set ( this . _getCellCompareValue ( this . _dateAdapter . today ( ) ) ) ;
407
+ this . _monthLabel . set (
408
+ this . _dateFormats . display . monthLabel
409
+ ? this . _dateAdapter . format ( this . activeDate , this . _dateFormats . display . monthLabel )
410
+ : this . _dateAdapter
411
+ . getMonthNames ( 'short' )
412
+ [ this . _dateAdapter . getMonth ( this . activeDate ) ] . toLocaleUpperCase ( ) ,
413
+ ) ;
411
414
412
415
let firstOfMonth = this . _dateAdapter . createDate (
413
416
this . _dateAdapter . getYear ( this . activeDate ) ,
414
417
this . _dateAdapter . getMonth ( this . activeDate ) ,
415
418
1 ,
416
419
) ;
417
- this . _firstWeekOffset =
420
+ this . _firstWeekOffset . set (
418
421
( DAYS_PER_WEEK +
419
422
this . _dateAdapter . getDayOfWeek ( firstOfMonth ) -
420
423
this . _dateAdapter . getFirstDayOfWeek ( ) ) %
421
- DAYS_PER_WEEK ;
424
+ DAYS_PER_WEEK ,
425
+ ) ;
422
426
423
427
this . _initWeekdays ( ) ;
424
428
this . _createWeekCells ( ) ;
@@ -446,8 +450,8 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
446
450
this . selected as DateRange < D > ,
447
451
event ,
448
452
) ;
449
- this . _previewStart = this . _getCellCompareValue ( previewRange . start ) ;
450
- this . _previewEnd = this . _getCellCompareValue ( previewRange . end ) ;
453
+ this . _previewStart . set ( this . _getCellCompareValue ( previewRange . start ) ) ;
454
+ this . _previewEnd . set ( this . _getCellCompareValue ( previewRange . end ) ) ;
451
455
452
456
if ( this . activeDrag && value ) {
453
457
const dragRange = this . _rangeStrategy . createDrag ?.(
@@ -458,8 +462,8 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
458
462
) ;
459
463
460
464
if ( dragRange ) {
461
- this . _previewStart = this . _getCellCompareValue ( dragRange . start ) ;
462
- this . _previewEnd = this . _getCellCompareValue ( dragRange . end ) ;
465
+ this . _previewStart . set ( this . _getCellCompareValue ( dragRange . start ) ) ;
466
+ this . _previewEnd . set ( this . _getCellCompareValue ( dragRange . end ) ) ;
463
467
}
464
468
}
465
469
}
@@ -506,20 +510,20 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
506
510
const longWeekdays = this . _dateAdapter . getDayOfWeekNames ( 'long' ) ;
507
511
508
512
// Rotate the labels for days of the week based on the configured first day of the week.
509
- let weekdays = longWeekdays . map ( ( long , i ) => {
513
+ const weekdays = longWeekdays . map ( ( long , i ) => {
510
514
return { long, narrow : narrowWeekdays [ i ] , id : uniqueIdCounter ++ } ;
511
515
} ) ;
512
- this . _weekdays = weekdays . slice ( firstDayOfWeek ) . concat ( weekdays . slice ( 0 , firstDayOfWeek ) ) ;
516
+ this . _weekdays . set ( weekdays . slice ( firstDayOfWeek ) . concat ( weekdays . slice ( 0 , firstDayOfWeek ) ) ) ;
513
517
}
514
518
515
519
/** Creates MatCalendarCells for the dates in this month. */
516
520
private _createWeekCells ( ) {
517
521
const daysInMonth = this . _dateAdapter . getNumDaysInMonth ( this . activeDate ) ;
518
522
const dateNames = this . _dateAdapter . getDateNames ( ) ;
519
- this . _weeks = [ [ ] ] ;
520
- for ( let i = 0 , cell = this . _firstWeekOffset ; i < daysInMonth ; i ++ , cell ++ ) {
523
+ const weeks : MatCalendarCell [ ] [ ] = [ [ ] ] ;
524
+ for ( let i = 0 , cell = this . _firstWeekOffset ( ) ; i < daysInMonth ; i ++ , cell ++ ) {
521
525
if ( cell == DAYS_PER_WEEK ) {
522
- this . _weeks . push ( [ ] ) ;
526
+ weeks . push ( [ ] ) ;
523
527
cell = 0 ;
524
528
}
525
529
const date = this . _dateAdapter . createDate (
@@ -531,7 +535,7 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
531
535
const ariaLabel = this . _dateAdapter . format ( date , this . _dateFormats . display . dateA11yLabel ) ;
532
536
const cellClasses = this . dateClass ? this . dateClass ( date , 'month' ) : undefined ;
533
537
534
- this . _weeks [ this . _weeks . length - 1 ] . push (
538
+ weeks [ weeks . length - 1 ] . push (
535
539
new MatCalendarCell < D > (
536
540
i + 1 ,
537
541
dateNames [ i ] ,
@@ -543,6 +547,7 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
543
547
) ,
544
548
) ;
545
549
}
550
+ this . _weeks . set ( weeks ) ;
546
551
}
547
552
548
553
/** Date filter for the month */
@@ -597,16 +602,17 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
597
602
/** Sets the current range based on a model value. */
598
603
private _setRanges ( selectedValue : DateRange < D > | D | null ) {
599
604
if ( selectedValue instanceof DateRange ) {
600
- this . _rangeStart = this . _getCellCompareValue ( selectedValue . start ) ;
601
- this . _rangeEnd = this . _getCellCompareValue ( selectedValue . end ) ;
602
- this . _isRange = true ;
605
+ this . _rangeStart . set ( this . _getCellCompareValue ( selectedValue . start ) ) ;
606
+ this . _rangeEnd . set ( this . _getCellCompareValue ( selectedValue . end ) ) ;
607
+ this . _isRange . set ( true ) ;
603
608
} else {
604
- this . _rangeStart = this . _rangeEnd = this . _getCellCompareValue ( selectedValue ) ;
605
- this . _isRange = false ;
609
+ this . _rangeStart . set ( this . _getCellCompareValue ( selectedValue ) ) ;
610
+ this . _rangeEnd . set ( this . _rangeStart ( ) ) ;
611
+ this . _isRange . set ( false ) ;
606
612
}
607
613
608
- this . _comparisonRangeStart = this . _getCellCompareValue ( this . comparisonStart ) ;
609
- this . _comparisonRangeEnd = this . _getCellCompareValue ( this . comparisonEnd ) ;
614
+ this . _comparisonRangeStart . set ( this . _getCellCompareValue ( this . comparisonStart ) ) ;
615
+ this . _comparisonRangeEnd . set ( this . _getCellCompareValue ( this . comparisonEnd ) ) ;
610
616
}
611
617
612
618
/** Gets whether a date can be selected in the month view. */
@@ -616,6 +622,7 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
616
622
617
623
/** Clears out preview state. */
618
624
private _clearPreview ( ) {
619
- this . _previewStart = this . _previewEnd = null ;
625
+ this . _previewStart . set ( null ) ;
626
+ this . _previewEnd . set ( null ) ;
620
627
}
621
628
}
0 commit comments