88
99import { Directionality } from '@angular/cdk/bidi' ;
1010import { BACKSPACE , LEFT_ARROW , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
11- import {
12- Directive ,
13- DoCheck ,
14- ElementRef ,
15- InjectionToken ,
16- Injector ,
17- Input ,
18- OnInit ,
19- Signal ,
20- inject ,
21- } from '@angular/core' ;
11+ import { Directive , DoCheck , ElementRef , Injector , Input , OnInit , inject } from '@angular/core' ;
2212import {
2313 AbstractControl ,
2414 FormGroupDirective ,
@@ -33,34 +23,8 @@ import {
3323import { ErrorStateMatcher , _ErrorStateTracker } from '@angular/material/core' ;
3424import { _computeAriaAccessibleName } from './aria-accessible-name' ;
3525import { 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- ) ;
26+ import { MatDatepickerInputBase } from './datepicker-input-base' ;
27+ import { MatDateRangeInput } from './date-range-input' ;
6428
6529/**
6630 * Base class for the individual inputs that can be projected inside a `mat-date-range-input`.
@@ -70,7 +34,7 @@ abstract class MatDateRangeInputPartBase<D>
7034 extends MatDatepickerInputBase < DateRange < D > >
7135 implements OnInit , DoCheck
7236{
73- _rangeInput = inject < MatDateRangeInputParent < D > > ( MAT_DATE_RANGE_INPUT_PARENT ) ;
37+ _rangeInput = inject < MatDateRangeInput < D > > ( MatDateRangeInput ) ;
7438 override _elementRef = inject < ElementRef < HTMLInputElement > > ( ElementRef ) ;
7539 _defaultErrorStateMatcher = inject ( ErrorStateMatcher ) ;
7640 private _injector = inject ( Injector ) ;
@@ -86,6 +50,7 @@ abstract class MatDateRangeInputPartBase<D>
8650 protected abstract override _validator : ValidatorFn | null ;
8751 protected abstract override _assignValueToModel ( value : D | null ) : void ;
8852 protected abstract override _getValueFromModel ( modelValue : DateRange < D > ) : D | null ;
53+ protected abstract _register ( ) : void ;
8954 protected readonly _dir = inject ( Directionality , { optional : true } ) ;
9055 private _errorStateTracker : _ErrorStateTracker ;
9156
@@ -133,6 +98,8 @@ abstract class MatDateRangeInputPartBase<D>
13398 this . ngControl = ngControl ;
13499 this . _errorStateTracker . ngControl = ngControl ;
135100 }
101+
102+ this . _register ( ) ;
136103 }
137104
138105 ngDoCheck ( ) {
@@ -208,7 +175,7 @@ abstract class MatDateRangeInputPartBase<D>
208175 protected override _assignValueProgrammatically ( value : D | null ) {
209176 super . _assignValueProgrammatically ( value ) ;
210177 const opposite = (
211- this === this . _rangeInput . _startInput
178+ this === ( this . _rangeInput . _startInput as MatDateRangeInputPartBase < D > )
212179 ? this . _rangeInput . _endInput
213180 : this . _rangeInput . _startInput
214181 ) as MatDateRangeInputPartBase < D > | undefined ;
@@ -261,6 +228,10 @@ export class MatStartDate<D> extends MatDateRangeInputPartBase<D> {
261228
262229 protected _validator = Validators . compose ( [ ...super . _getValidators ( ) , this . _startValidator ] ) ;
263230
231+ protected override _register ( ) : void {
232+ this . _rangeInput . _startInput = this ;
233+ }
234+
264235 protected _getValueFromModel ( modelValue : DateRange < D > ) {
265236 return modelValue . start ;
266237 }
@@ -349,6 +320,10 @@ export class MatEndDate<D> extends MatDateRangeInputPartBase<D> {
349320 : { 'matEndDateInvalid' : { 'start' : start , 'actual' : end } } ;
350321 } ;
351322
323+ protected override _register ( ) : void {
324+ this . _rangeInput . _endInput = this ;
325+ }
326+
352327 protected _validator = Validators . compose ( [ ...super . _getValidators ( ) , this . _endValidator ] ) ;
353328
354329 protected _getValueFromModel ( modelValue : DateRange < D > ) {
0 commit comments