@@ -24,7 +24,7 @@ import {
24
24
} from '@angular/core' ;
25
25
import { MatFormFieldControl , MAT_FORM_FIELD } from '@angular/material/form-field' ;
26
26
import { ThemePalette , DateAdapter } from '@angular/material/core' ;
27
- import { NgControl , ControlContainer } from '@angular/forms' ;
27
+ import { NgControl , ControlContainer , Validators } from '@angular/forms' ;
28
28
import { Subject , merge , Subscription } from 'rxjs' ;
29
29
import { FocusOrigin } from '@angular/cdk/a11y' ;
30
30
import { coerceBooleanProperty , BooleanInput } from '@angular/cdk/coercion' ;
@@ -130,12 +130,18 @@ export class MatDateRangeInput<D>
130
130
/** Whether the input is required. */
131
131
@Input ( )
132
132
get required ( ) : boolean {
133
- return ! ! this . _required ;
133
+ return (
134
+ this . _required ??
135
+ ( this . _isTargetRequired ( this ) ||
136
+ this . _isTargetRequired ( this . _startInput ) ||
137
+ this . _isTargetRequired ( this . _endInput ) ) ??
138
+ false
139
+ ) ;
134
140
}
135
141
set required ( value : BooleanInput ) {
136
142
this . _required = coerceBooleanProperty ( value ) ;
137
143
}
138
- private _required : boolean ;
144
+ private _required : boolean | undefined ;
139
145
140
146
/** Function that can be used to filter out dates within the date range picker. */
141
147
@Input ( )
@@ -422,4 +428,9 @@ export class MatDateRangeInput<D>
422
428
this . _endInput . _registerModel ( model ) ;
423
429
}
424
430
}
431
+
432
+ /** Checks whether a specific range input directive is required. */
433
+ private _isTargetRequired ( target : { ngControl : NgControl | null } | null ) : boolean | undefined {
434
+ return target ?. ngControl ?. control ?. hasValidator ( Validators . required ) ;
435
+ }
425
436
}
0 commit comments