fix(checkbox): support OnPush for disabled with forms module (#4087)

This commit is contained in:
tinayuangao
2017-04-14 15:02:49 -06:00
committed by Jeremy Elbourn
parent 02b2cc9210
commit efb39da377
2 changed files with 5 additions and 0 deletions
+4
View File
@@ -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 = <HTMLInputElement>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);
});
});
});
+1
View File
@@ -304,6 +304,7 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro
*/
setDisabledState(isDisabled: boolean) {
this.disabled = isDisabled;
this._changeDetectorRef.markForCheck();
}
private _transitionCheckState(newState: TransitionCheckState) {