@@ -174,7 +174,7 @@ export class MatDatepickerContent<S, D = ExtractDateTypeFromSelection<S>>
174
174
}
175
175
176
176
ngAfterViewInit ( ) {
177
- this . _subscriptions . add ( this . datepicker . _stateChanges . subscribe ( ( ) => {
177
+ this . _subscriptions . add ( this . datepicker . stateChanges . subscribe ( ( ) => {
178
178
this . _changeDetectorRef . markForCheck ( ) ;
179
179
} ) ) ;
180
180
@@ -232,10 +232,36 @@ export interface MatDatepickerControl<D> {
232
232
stateChanges : Observable < void > ;
233
233
}
234
234
235
+ /** A datepicker that can be attached to a {@link MatDatepickerControl}. */
236
+ export interface MatDatepickerPanel < C extends MatDatepickerControl < D > , S ,
237
+ D = ExtractDateTypeFromSelection < S > > {
238
+ /** Stream that emits whenever the date picker is closed. */
239
+ closedStream : EventEmitter < void > ;
240
+ /** Color palette to use on the datepicker's calendar. */
241
+ color : ThemePalette ;
242
+ /** The input element the datepicker is associated with. */
243
+ datepickerInput : C ;
244
+ /** Whether the datepicker pop-up should be disabled. */
245
+ disabled : boolean ;
246
+ /** The id for the datepicker's calendar. */
247
+ id : string ;
248
+ /** Whether the datepicker is open. */
249
+ opened : boolean ;
250
+ /** Stream that emits whenever the date picker is opened. */
251
+ openedStream : EventEmitter < void > ;
252
+ /** Emits when the datepicker's state changes. */
253
+ stateChanges : Subject < void > ;
254
+ /** Opens the datepicker. */
255
+ open ( ) : void ;
256
+ /** Register an input with the datepicker. */
257
+ registerInput ( input : C ) : MatDateSelectionModel < S , D > ;
258
+ }
259
+
235
260
/** Base class for a datepicker. */
236
261
@Directive ( )
237
262
export abstract class MatDatepickerBase < C extends MatDatepickerControl < D > , S ,
238
- D = ExtractDateTypeFromSelection < S > > implements OnDestroy , OnChanges {
263
+ D = ExtractDateTypeFromSelection < S > > implements MatDatepickerPanel < C , S , D > , OnDestroy ,
264
+ OnChanges {
239
265
private _scrollStrategy : ( ) => ScrollStrategy ;
240
266
private _inputStateChanges = Subscription . EMPTY ;
241
267
@@ -247,7 +273,7 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
247
273
get startAt ( ) : D | null {
248
274
// If an explicit startAt is set we start there, otherwise we start at whatever the currently
249
275
// selected value is.
250
- return this . _startAt || ( this . _datepickerInput ? this . _datepickerInput . getStartValue ( ) : null ) ;
276
+ return this . _startAt || ( this . datepickerInput ? this . datepickerInput . getStartValue ( ) : null ) ;
251
277
}
252
278
set startAt ( value : D | null ) {
253
279
this . _startAt = this . _dateAdapter . getValidDateOrNull ( this . _dateAdapter . deserialize ( value ) ) ;
@@ -261,7 +287,7 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
261
287
@Input ( )
262
288
get color ( ) : ThemePalette {
263
289
return this . _color ||
264
- ( this . _datepickerInput ? this . _datepickerInput . getThemePalette ( ) : undefined ) ;
290
+ ( this . datepickerInput ? this . datepickerInput . getThemePalette ( ) : undefined ) ;
265
291
}
266
292
set color ( value : ThemePalette ) {
267
293
this . _color = value ;
@@ -282,15 +308,15 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
282
308
/** Whether the datepicker pop-up should be disabled. */
283
309
@Input ( )
284
310
get disabled ( ) : boolean {
285
- return this . _disabled === undefined && this . _datepickerInput ?
286
- this . _datepickerInput . disabled : ! ! this . _disabled ;
311
+ return this . _disabled === undefined && this . datepickerInput ?
312
+ this . datepickerInput . disabled : ! ! this . _disabled ;
287
313
}
288
314
set disabled ( value : boolean ) {
289
315
const newValue = coerceBooleanProperty ( value ) ;
290
316
291
317
if ( newValue !== this . _disabled ) {
292
318
this . _disabled = newValue ;
293
- this . _stateChanges . next ( undefined ) ;
319
+ this . stateChanges . next ( undefined ) ;
294
320
}
295
321
}
296
322
private _disabled : boolean ;
@@ -354,16 +380,16 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
354
380
355
381
/** The minimum selectable date. */
356
382
_getMinDate ( ) : D | null {
357
- return this . _datepickerInput && this . _datepickerInput . min ;
383
+ return this . datepickerInput && this . datepickerInput . min ;
358
384
}
359
385
360
386
/** The maximum selectable date. */
361
387
_getMaxDate ( ) : D | null {
362
- return this . _datepickerInput && this . _datepickerInput . max ;
388
+ return this . datepickerInput && this . datepickerInput . max ;
363
389
}
364
390
365
391
_getDateFilter ( ) : DateFilterFn < D > {
366
- return this . _datepickerInput && this . _datepickerInput . dateFilter ;
392
+ return this . datepickerInput && this . datepickerInput . dateFilter ;
367
393
}
368
394
369
395
/** A reference to the overlay when the calendar is opened as a popup. */
@@ -382,10 +408,10 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
382
408
private _backdropHarnessClass = `${ this . id } -backdrop` ;
383
409
384
410
/** The input element this datepicker is associated with. */
385
- _datepickerInput : C ;
411
+ datepickerInput : C ;
386
412
387
413
/** Emits when the datepicker's state changes. */
388
- readonly _stateChanges = new Subject < void > ( ) ;
414
+ readonly stateChanges = new Subject < void > ( ) ;
389
415
390
416
constructor ( private _dialog : MatDialog ,
391
417
private _overlay : Overlay ,
@@ -415,14 +441,14 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
415
441
}
416
442
}
417
443
418
- this . _stateChanges . next ( undefined ) ;
444
+ this . stateChanges . next ( undefined ) ;
419
445
}
420
446
421
447
ngOnDestroy ( ) {
422
448
this . _destroyPopup ( ) ;
423
449
this . close ( ) ;
424
450
this . _inputStateChanges . unsubscribe ( ) ;
425
- this . _stateChanges . complete ( ) ;
451
+ this . stateChanges . complete ( ) ;
426
452
}
427
453
428
454
/** Selects the given date */
@@ -450,14 +476,14 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
450
476
* @param input The datepicker input to register with this datepicker.
451
477
* @returns Selection model that the input should hook itself up to.
452
478
*/
453
- _registerInput ( input : C ) : MatDateSelectionModel < S , D > {
454
- if ( this . _datepickerInput && ( typeof ngDevMode === 'undefined' || ngDevMode ) ) {
479
+ registerInput ( input : C ) : MatDateSelectionModel < S , D > {
480
+ if ( this . datepickerInput && ( typeof ngDevMode === 'undefined' || ngDevMode ) ) {
455
481
throw Error ( 'A MatDatepicker can only be associated with a single input.' ) ;
456
482
}
457
483
this . _inputStateChanges . unsubscribe ( ) ;
458
- this . _datepickerInput = input ;
484
+ this . datepickerInput = input ;
459
485
this . _inputStateChanges =
460
- input . stateChanges . subscribe ( ( ) => this . _stateChanges . next ( undefined ) ) ;
486
+ input . stateChanges . subscribe ( ( ) => this . stateChanges . next ( undefined ) ) ;
461
487
return this . _model ;
462
488
}
463
489
@@ -466,7 +492,7 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
466
492
if ( this . _opened || this . disabled ) {
467
493
return ;
468
494
}
469
- if ( ! this . _datepickerInput && ( typeof ngDevMode === 'undefined' || ngDevMode ) ) {
495
+ if ( ! this . datepickerInput && ( typeof ngDevMode === 'undefined' || ngDevMode ) ) {
470
496
throw Error ( 'Attempted to open an MatDatepicker with no associated input.' ) ;
471
497
}
472
498
if ( this . _document ) {
@@ -584,7 +610,7 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
584
610
/** Create the popup. */
585
611
private _createPopup ( ) : void {
586
612
const positionStrategy = this . _overlay . position ( )
587
- . flexibleConnectedTo ( this . _datepickerInput . getConnectedOverlayOrigin ( ) )
613
+ . flexibleConnectedTo ( this . datepickerInput . getConnectedOverlayOrigin ( ) )
588
614
. withTransformOriginOn ( '.mat-datepicker-content' )
589
615
. withFlexibleDimensions ( false )
590
616
. withViewportMargin ( 8 )
@@ -607,7 +633,7 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
607
633
this . _popupRef . detachments ( ) ,
608
634
this . _popupRef . keydownEvents ( ) . pipe ( filter ( event => {
609
635
// Closing on alt + up is only valid when there's an input associated with the datepicker.
610
- return ( event . keyCode === ESCAPE && ! hasModifierKey ( event ) ) || ( this . _datepickerInput &&
636
+ return ( event . keyCode === ESCAPE && ! hasModifierKey ( event ) ) || ( this . datepickerInput &&
611
637
hasModifierKey ( event , 'altKey' ) && event . keyCode === UP_ARROW ) ;
612
638
} ) )
613
639
) . subscribe ( event => {
0 commit comments