99import { Directionality } from '@angular/cdk/bidi' ;
1010import { BACKSPACE , LEFT_ARROW , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
1111import {
12+ AfterContentInit ,
1213 Directive ,
1314 DoCheck ,
1415 ElementRef ,
15- InjectionToken ,
1616 Injector ,
1717 Input ,
1818 OnInit ,
19- Signal ,
2019 inject ,
2120} from '@angular/core' ;
2221import {
@@ -33,44 +32,18 @@ import {
3332import { ErrorStateMatcher , _ErrorStateTracker } from '@angular/material/core' ;
3433import { _computeAriaAccessibleName } from './aria-accessible-name' ;
3534import { DateRange , DateSelectionModelChange } from './date-selection-model' ;
36- import { DateFilterFn , MatDatepickerInputBase } from './datepicker-input-base' ;
37-
38- /** Parent component that should be wrapped around `MatStartDate` and `MatEndDate`. */
39- export interface MatDateRangeInputParent < D > {
40- id : string ;
41- min : D | null ;
42- max : D | null ;
43- dateFilter : DateFilterFn < D > ;
44- rangePicker : {
45- opened : boolean ;
46- id : string ;
47- } ;
48- // @breaking -change 20.0.0 property to become required.
49- _ariaOwns ?: Signal < string | null > ;
50- _startInput : MatDateRangeInputPartBase < D > ;
51- _endInput : MatDateRangeInputPartBase < D > ;
52- _groupDisabled : boolean ;
53- _handleChildValueChange ( ) : void ;
54- _openDatepicker ( ) : void ;
55- }
56-
57- /**
58- * Used to provide the date range input wrapper component
59- * to the parts without circular dependencies.
60- */
61- export const MAT_DATE_RANGE_INPUT_PARENT = new InjectionToken < MatDateRangeInputParent < unknown > > (
62- 'MAT_DATE_RANGE_INPUT_PARENT' ,
63- ) ;
35+ import { MatDatepickerInputBase } from './datepicker-input-base' ;
36+ import { MatDateRangeInput } from './date-range-input' ;
6437
6538/**
6639 * Base class for the individual inputs that can be projected inside a `mat-date-range-input`.
6740 */
6841@Directive ( )
6942abstract class MatDateRangeInputPartBase < D >
7043 extends MatDatepickerInputBase < DateRange < D > >
71- implements OnInit , DoCheck
44+ implements OnInit , AfterContentInit , DoCheck
7245{
73- _rangeInput = inject < MatDateRangeInputParent < D > > ( MAT_DATE_RANGE_INPUT_PARENT ) ;
46+ _rangeInput = inject < MatDateRangeInput < D > > ( MatDateRangeInput ) ;
7447 override _elementRef = inject < ElementRef < HTMLInputElement > > ( ElementRef ) ;
7548 _defaultErrorStateMatcher = inject ( ErrorStateMatcher ) ;
7649 private _injector = inject ( Injector ) ;
@@ -86,6 +59,7 @@ abstract class MatDateRangeInputPartBase<D>
8659 protected abstract override _validator : ValidatorFn | null ;
8760 protected abstract override _assignValueToModel ( value : D | null ) : void ;
8861 protected abstract override _getValueFromModel ( modelValue : DateRange < D > ) : D | null ;
62+ protected abstract _register ( ) : void ;
8963 protected readonly _dir = inject ( Directionality , { optional : true } ) ;
9064 private _errorStateTracker : _ErrorStateTracker ;
9165
@@ -135,6 +109,10 @@ abstract class MatDateRangeInputPartBase<D>
135109 }
136110 }
137111
112+ ngAfterContentInit ( ) : void {
113+ this . _register ( ) ;
114+ }
115+
138116 ngDoCheck ( ) {
139117 if ( this . ngControl ) {
140118 // We need to re-evaluate this on every change detection cycle, because there are some
@@ -208,7 +186,7 @@ abstract class MatDateRangeInputPartBase<D>
208186 protected override _assignValueProgrammatically ( value : D | null ) {
209187 super . _assignValueProgrammatically ( value ) ;
210188 const opposite = (
211- this === this . _rangeInput . _startInput
189+ this === ( this . _rangeInput . _startInput as MatDateRangeInputPartBase < D > )
212190 ? this . _rangeInput . _endInput
213191 : this . _rangeInput . _startInput
214192 ) as MatDateRangeInputPartBase < D > | undefined ;
@@ -261,6 +239,10 @@ export class MatStartDate<D> extends MatDateRangeInputPartBase<D> {
261239
262240 protected _validator = Validators . compose ( [ ...super . _getValidators ( ) , this . _startValidator ] ) ;
263241
242+ protected override _register ( ) : void {
243+ this . _rangeInput . _startInput = this ;
244+ }
245+
264246 protected _getValueFromModel ( modelValue : DateRange < D > ) {
265247 return modelValue . start ;
266248 }
@@ -349,6 +331,10 @@ export class MatEndDate<D> extends MatDateRangeInputPartBase<D> {
349331 : { 'matEndDateInvalid' : { 'start' : start , 'actual' : end } } ;
350332 } ;
351333
334+ protected override _register ( ) : void {
335+ this . _rangeInput . _endInput = this ;
336+ }
337+
352338 protected _validator = Validators . compose ( [ ...super . _getValidators ( ) , this . _endValidator ] ) ;
353339
354340 protected _getValueFromModel ( modelValue : DateRange < D > ) {
0 commit comments