Skip to content

fix(material/datepicker): unable to pass in errorStateMatcher through binding on range input #21210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/material/datepicker/date-range-input-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ const _MatDateRangeInputBase:
],
// These need to be specified explicitly, because some tooling doesn't
// seem to pick them up from the base class. See #20932.
outputs: ['dateChange', 'dateInput']
outputs: ['dateChange', 'dateInput'],
inputs: ['errorStateMatcher']
})
export class MatStartDate<D> extends _MatDateRangeInputBase<D> implements
CanUpdateErrorState, DoCheck, OnInit {
Expand Down Expand Up @@ -307,7 +308,8 @@ export class MatStartDate<D> extends _MatDateRangeInputBase<D> implements
],
// These need to be specified explicitly, because some tooling doesn't
// seem to pick them up from the base class. See #20932.
outputs: ['dateChange', 'dateInput']
outputs: ['dateChange', 'dateInput'],
inputs: ['errorStateMatcher']
})
export class MatEndDate<D> extends _MatDateRangeInputBase<D> implements
CanUpdateErrorState, DoCheck, OnInit {
Expand Down
30 changes: 29 additions & 1 deletion src/material/datepicker/date-range-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@angular/forms';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {OverlayContainer} from '@angular/cdk/overlay';
import {MatNativeDateModule} from '@angular/material/core';
import {ErrorStateMatcher, MatNativeDateModule} from '@angular/material/core';
import {MatDatepickerModule} from './datepicker-module';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';
Expand Down Expand Up @@ -759,6 +759,15 @@ describe('MatDateRangeInput', () => {
subscription.unsubscribe();
});

it('should be able to pass in a different error state matcher through an input', () => {
const fixture = createComponent(RangePickerErrorStateMatcher);
fixture.detectChanges();
const {startInput, endInput, matcher} = fixture.componentInstance;

expect(startInput.errorStateMatcher).toBe(matcher);
expect(endInput.errorStateMatcher).toBe(matcher);
});

});

@Component({
Expand Down Expand Up @@ -903,3 +912,22 @@ class RangePickerWithCustomValidator {
min: Date;
max: Date;
}


@Component({
template: `
<mat-form-field>
<mat-date-range-input [rangePicker]="rangePicker">
<input matStartDate [errorStateMatcher]="matcher"/>
<input matEndDate [errorStateMatcher]="matcher"/>
</mat-date-range-input>

<mat-date-range-picker #rangePicker></mat-date-range-picker>
</mat-form-field>
`
})
class RangePickerErrorStateMatcher {
@ViewChild(MatStartDate) startInput: MatStartDate<Date>;
@ViewChild(MatEndDate) endInput: MatEndDate<Date>;
matcher: ErrorStateMatcher = {isErrorState: () => false};
}
4 changes: 2 additions & 2 deletions tools/public_api_guard/material/datepicker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export declare class MatEndDate<D> extends _MatDateRangeInputBase<D> implements
ngDoCheck(): void;
ngOnInit(): void;
static ngAcceptInputType_disabled: BooleanInput;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MatEndDate<any>, "input[matEndDate]", never, {}, { "dateChange": "dateChange"; "dateInput": "dateInput"; }, never>;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MatEndDate<any>, "input[matEndDate]", never, { "errorStateMatcher": "errorStateMatcher"; }, { "dateChange": "dateChange"; "dateInput": "dateInput"; }, never>;
static ɵfac: i0.ɵɵFactoryDef<MatEndDate<any>, [null, null, null, null, { optional: true; }, { optional: true; }, { optional: true; }, { optional: true; }]>;
}

Expand Down Expand Up @@ -492,7 +492,7 @@ export declare class MatStartDate<D> extends _MatDateRangeInputBase<D> implement
ngDoCheck(): void;
ngOnInit(): void;
static ngAcceptInputType_disabled: BooleanInput;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MatStartDate<any>, "input[matStartDate]", never, {}, { "dateChange": "dateChange"; "dateInput": "dateInput"; }, never>;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MatStartDate<any>, "input[matStartDate]", never, { "errorStateMatcher": "errorStateMatcher"; }, { "dateChange": "dateChange"; "dateInput": "dateInput"; }, never>;
static ɵfac: i0.ɵɵFactoryDef<MatStartDate<any>, [null, null, null, null, { optional: true; }, { optional: true; }, { optional: true; }, { optional: true; }]>;
}

Expand Down