Skip to content

Commit

Permalink
fix(checkbox): support OnPush for disabled with forms module (#4087)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao authored and jelbourn committed Apr 14, 2017
1 parent 02b2cc9 commit efb39da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
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

0 comments on commit efb39da

Please sign in to comment.