Skip to content
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

fix(checkbox): Fix disabled checkbox throw error when clicked #4087

Merged
merged 6 commits into from
Apr 14, 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/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ describe('MdCheckbox', () => {
let checkboxDebugElement: DebugElement;
let checkboxInstance: MdCheckbox;
let testComponent: CheckboxWithFormControl;
let inputElement: HTMLInputElement;

beforeEach(() => {
fixture = TestBed.createComponent(CheckboxWithFormControl);
Expand All @@ -718,6 +719,7 @@ describe('MdCheckbox', () => {
checkboxDebugElement = fixture.debugElement.query(By.directive(MdCheckbox));
checkboxInstance = checkboxDebugElement.componentInstance;
testComponent = fixture.debugElement.componentInstance;
inputElement = <HTMLInputElement>checkboxDebugElement.nativeElement.querySelector('input');
});

it('should toggle the disabled state', () => {
Expand All @@ -727,11 +729,13 @@ describe('MdCheckbox', () => {
fixture.detectChanges();

expect(checkboxInstance.disabled).toBe(true);
expect(inputElement.disabled).toBe(true);

testComponent.formControl.enable();
fixture.detectChanges();

expect(checkboxInstance.disabled).toBe(false);
expect(inputElement.disabled).toBe(false);
});
});
});
Expand Down
1 change: 1 addition & 0 deletions src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro
*/
setDisabledState(isDisabled: boolean) {
this.disabled = isDisabled;
this._changeDetectorRef.markForCheck();
}

private _transitionCheckState(newState: TransitionCheckState) {
Expand Down