mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(datepicker): toggle throwing an error if datepicker is not defined on init (#15256)
Fixes the `mat-datepicker-toggle` throwing an error if the `datepicker` undefined on init. We already have guards for this in all of the other cases, but it was missing in this one.
This commit is contained in:
committed by
Joey Perrott
parent
4ff1c95ae7
commit
1c503ff705
@@ -66,7 +66,11 @@ export class MatDatepickerToggle<D> implements AfterContentInit, OnChanges, OnDe
|
||||
/** Whether the toggle button is disabled. */
|
||||
@Input()
|
||||
get disabled(): boolean {
|
||||
return this._disabled === undefined ? this.datepicker.disabled : !!this._disabled;
|
||||
if (this._disabled === undefined && this.datepicker) {
|
||||
return this.datepicker.disabled;
|
||||
}
|
||||
|
||||
return !!this._disabled;
|
||||
}
|
||||
set disabled(value: boolean) {
|
||||
this._disabled = coerceBooleanProperty(value);
|
||||
|
||||
@@ -1538,6 +1538,15 @@ describe('MatDatepicker', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('datepicker toggle without a datepicker', () => {
|
||||
it('should not throw on init if toggle does not have a datepicker', () => {
|
||||
expect(() => {
|
||||
const fixture = createComponent(DatepickerToggleWithNoDatepicker, [MatNativeDateModule]);
|
||||
fixture.detectChanges();
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('popup positioning', () => {
|
||||
let fixture: ComponentFixture<StandardDatepicker>;
|
||||
let testComponent: StandardDatepicker;
|
||||
@@ -1963,7 +1972,6 @@ class DelayedDatepicker {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<input [matDatepicker]="d">
|
||||
@@ -1974,3 +1982,11 @@ class DelayedDatepicker {
|
||||
`,
|
||||
})
|
||||
class DatepickerWithTabindexOnToggle {}
|
||||
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<mat-datepicker-toggle></mat-datepicker-toggle>
|
||||
`,
|
||||
})
|
||||
class DatepickerToggleWithNoDatepicker {}
|
||||
|
||||
Reference in New Issue
Block a user