@@ -24,7 +24,7 @@ import {
2424} from '@angular/core' ;
2525import { MatFormFieldControl , MAT_FORM_FIELD } from '@angular/material/form-field' ;
2626import { ThemePalette , DateAdapter } from '@angular/material/core' ;
27- import { NgControl , ControlContainer } from '@angular/forms' ;
27+ import { NgControl , ControlContainer , Validators } from '@angular/forms' ;
2828import { Subject , merge , Subscription } from 'rxjs' ;
2929import { FocusOrigin } from '@angular/cdk/a11y' ;
3030import { coerceBooleanProperty , BooleanInput } from '@angular/cdk/coercion' ;
@@ -130,12 +130,18 @@ export class MatDateRangeInput<D>
130130 /** Whether the input is required. */
131131 @Input ( )
132132 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+ ) ;
134140 }
135141 set required ( value : BooleanInput ) {
136142 this . _required = coerceBooleanProperty ( value ) ;
137143 }
138- private _required : boolean ;
144+ private _required : boolean | undefined ;
139145
140146 /** Function that can be used to filter out dates within the date range picker. */
141147 @Input ( )
@@ -422,4 +428,9 @@ export class MatDateRangeInput<D>
422428 this . _endInput . _registerModel ( model ) ;
423429 }
424430 }
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+ }
425436}
0 commit comments