9
9
import { Directionality } from '@angular/cdk/bidi' ;
10
10
import { BACKSPACE , LEFT_ARROW , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
11
11
import {
12
+ AfterContentInit ,
12
13
Directive ,
13
14
DoCheck ,
14
15
ElementRef ,
15
- InjectionToken ,
16
16
Injector ,
17
17
Input ,
18
18
OnInit ,
19
- Signal ,
20
19
inject ,
21
20
} from '@angular/core' ;
22
21
import {
@@ -33,44 +32,18 @@ import {
33
32
import { ErrorStateMatcher , _ErrorStateTracker } from '@angular/material/core' ;
34
33
import { _computeAriaAccessibleName } from './aria-accessible-name' ;
35
34
import { 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' ;
64
37
65
38
/**
66
39
* Base class for the individual inputs that can be projected inside a `mat-date-range-input`.
67
40
*/
68
41
@Directive ( )
69
42
abstract class MatDateRangeInputPartBase < D >
70
43
extends MatDatepickerInputBase < DateRange < D > >
71
- implements OnInit , DoCheck
44
+ implements OnInit , AfterContentInit , DoCheck
72
45
{
73
- _rangeInput = inject < MatDateRangeInputParent < D > > ( MAT_DATE_RANGE_INPUT_PARENT ) ;
46
+ _rangeInput = inject < MatDateRangeInput < D > > ( MatDateRangeInput ) ;
74
47
override _elementRef = inject < ElementRef < HTMLInputElement > > ( ElementRef ) ;
75
48
_defaultErrorStateMatcher = inject ( ErrorStateMatcher ) ;
76
49
private _injector = inject ( Injector ) ;
@@ -86,6 +59,7 @@ abstract class MatDateRangeInputPartBase<D>
86
59
protected abstract override _validator : ValidatorFn | null ;
87
60
protected abstract override _assignValueToModel ( value : D | null ) : void ;
88
61
protected abstract override _getValueFromModel ( modelValue : DateRange < D > ) : D | null ;
62
+ protected abstract _register ( ) : void ;
89
63
protected readonly _dir = inject ( Directionality , { optional : true } ) ;
90
64
private _errorStateTracker : _ErrorStateTracker ;
91
65
@@ -135,6 +109,10 @@ abstract class MatDateRangeInputPartBase<D>
135
109
}
136
110
}
137
111
112
+ ngAfterContentInit ( ) : void {
113
+ this . _register ( ) ;
114
+ }
115
+
138
116
ngDoCheck ( ) {
139
117
if ( this . ngControl ) {
140
118
// We need to re-evaluate this on every change detection cycle, because there are some
@@ -208,7 +186,7 @@ abstract class MatDateRangeInputPartBase<D>
208
186
protected override _assignValueProgrammatically ( value : D | null ) {
209
187
super . _assignValueProgrammatically ( value ) ;
210
188
const opposite = (
211
- this === this . _rangeInput . _startInput
189
+ this === ( this . _rangeInput . _startInput as MatDateRangeInputPartBase < D > )
212
190
? this . _rangeInput . _endInput
213
191
: this . _rangeInput . _startInput
214
192
) as MatDateRangeInputPartBase < D > | undefined ;
@@ -261,6 +239,10 @@ export class MatStartDate<D> extends MatDateRangeInputPartBase<D> {
261
239
262
240
protected _validator = Validators . compose ( [ ...super . _getValidators ( ) , this . _startValidator ] ) ;
263
241
242
+ protected override _register ( ) : void {
243
+ this . _rangeInput . _startInput = this ;
244
+ }
245
+
264
246
protected _getValueFromModel ( modelValue : DateRange < D > ) {
265
247
return modelValue . start ;
266
248
}
@@ -349,6 +331,10 @@ export class MatEndDate<D> extends MatDateRangeInputPartBase<D> {
349
331
: { 'matEndDateInvalid' : { 'start' : start , 'actual' : end } } ;
350
332
} ;
351
333
334
+ protected override _register ( ) : void {
335
+ this . _rangeInput . _endInput = this ;
336
+ }
337
+
352
338
protected _validator = Validators . compose ( [ ...super . _getValidators ( ) , this . _endValidator ] ) ;
353
339
354
340
protected _getValueFromModel ( modelValue : DateRange < D > ) {
0 commit comments