Skip to content

fix(datepicker): make sure _datepickerInput exists before accessing its #7033

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 2 commits into from
Sep 29, 2017
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
4 changes: 4 additions & 0 deletions src/lib/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ describe('MdDatepicker', () => {
fixture.detectChanges();
}));

it('should not throw when accessing disabled property', () => {
expect(() => testComponent.datepicker.disabled).not.toThrow();
});

it('should throw when opened with no registered inputs', async(() => {
expect(() => testComponent.datepicker.open()).toThrow();
}));
Expand Down
3 changes: 2 additions & 1 deletion src/lib/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export class MdDatepicker<D> implements OnDestroy {
/** Whether the datepicker pop-up should be disabled. */
@Input()
get disabled() {
return this._disabled === undefined ? this._datepickerInput.disabled : this._disabled;
return this._disabled === undefined && this._datepickerInput ?
this._datepickerInput.disabled : this._disabled;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write a unit test that captures the situation in which this._datepickerInput would be undefined?

}
set disabled(value: any) {
const newValue = coerceBooleanProperty(value);
Expand Down