Skip to content

Commit 2129b7a

Browse files
mmalerbaandrewseguin
authored andcommitted
fix(datepicker): make sure _datepickerInput exists before accessing its (#7033)
* fix(datepicker): make sure _datepickerInput exists before accessing its disabled property. * add test
1 parent 2dcb76c commit 2129b7a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/lib/datepicker/datepicker.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ describe('MatDatepicker', () => {
304304
fixture.detectChanges();
305305
}));
306306

307+
it('should not throw when accessing disabled property', () => {
308+
expect(() => testComponent.datepicker.disabled).not.toThrow();
309+
});
310+
307311
it('should throw when opened with no registered inputs', async(() => {
308312
expect(() => testComponent.datepicker.open()).toThrow();
309313
}));

src/lib/datepicker/datepicker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ export class MatDatepicker<D> implements OnDestroy {
147147
/** Whether the datepicker pop-up should be disabled. */
148148
@Input()
149149
get disabled() {
150-
return this._disabled === undefined ? this._datepickerInput.disabled : this._disabled;
150+
return this._disabled === undefined && this._datepickerInput ?
151+
this._datepickerInput.disabled : this._disabled;
151152
}
152153
set disabled(value: any) {
153154
const newValue = coerceBooleanProperty(value);

0 commit comments

Comments
 (0)