From efb39da3772ddbe523d147d208500dc06ed8393a Mon Sep 17 00:00:00 2001 From: tinayuangao Date: Fri, 14 Apr 2017 15:02:49 -0600 Subject: [PATCH] fix(checkbox): support OnPush for disabled with forms module (#4087) --- src/lib/checkbox/checkbox.spec.ts | 4 ++++ src/lib/checkbox/checkbox.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/src/lib/checkbox/checkbox.spec.ts b/src/lib/checkbox/checkbox.spec.ts index 180a4003fa7..297307b40e9 100644 --- a/src/lib/checkbox/checkbox.spec.ts +++ b/src/lib/checkbox/checkbox.spec.ts @@ -710,6 +710,7 @@ describe('MdCheckbox', () => { let checkboxDebugElement: DebugElement; let checkboxInstance: MdCheckbox; let testComponent: CheckboxWithFormControl; + let inputElement: HTMLInputElement; beforeEach(() => { fixture = TestBed.createComponent(CheckboxWithFormControl); @@ -718,6 +719,7 @@ describe('MdCheckbox', () => { checkboxDebugElement = fixture.debugElement.query(By.directive(MdCheckbox)); checkboxInstance = checkboxDebugElement.componentInstance; testComponent = fixture.debugElement.componentInstance; + inputElement = checkboxDebugElement.nativeElement.querySelector('input'); }); it('should toggle the disabled state', () => { @@ -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); }); }); }); diff --git a/src/lib/checkbox/checkbox.ts b/src/lib/checkbox/checkbox.ts index e7a69a41216..ef0d34d5e5c 100644 --- a/src/lib/checkbox/checkbox.ts +++ b/src/lib/checkbox/checkbox.ts @@ -304,6 +304,7 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro */ setDisabledState(isDisabled: boolean) { this.disabled = isDisabled; + this._changeDetectorRef.markForCheck(); } private _transitionCheckState(newState: TransitionCheckState) {