Skip to content

Commit efb39da

Browse files
tinayuangaojelbourn
authored andcommitted
fix(checkbox): support OnPush for disabled with forms module (#4087)
1 parent 02b2cc9 commit efb39da

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/lib/checkbox/checkbox.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ describe('MdCheckbox', () => {
710710
let checkboxDebugElement: DebugElement;
711711
let checkboxInstance: MdCheckbox;
712712
let testComponent: CheckboxWithFormControl;
713+
let inputElement: HTMLInputElement;
713714

714715
beforeEach(() => {
715716
fixture = TestBed.createComponent(CheckboxWithFormControl);
@@ -718,6 +719,7 @@ describe('MdCheckbox', () => {
718719
checkboxDebugElement = fixture.debugElement.query(By.directive(MdCheckbox));
719720
checkboxInstance = checkboxDebugElement.componentInstance;
720721
testComponent = fixture.debugElement.componentInstance;
722+
inputElement = <HTMLInputElement>checkboxDebugElement.nativeElement.querySelector('input');
721723
});
722724

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

729731
expect(checkboxInstance.disabled).toBe(true);
732+
expect(inputElement.disabled).toBe(true);
730733

731734
testComponent.formControl.enable();
732735
fixture.detectChanges();
733736

734737
expect(checkboxInstance.disabled).toBe(false);
738+
expect(inputElement.disabled).toBe(false);
735739
});
736740
});
737741
});

src/lib/checkbox/checkbox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro
304304
*/
305305
setDisabledState(isDisabled: boolean) {
306306
this.disabled = isDisabled;
307+
this._changeDetectorRef.markForCheck();
307308
}
308309

309310
private _transitionCheckState(newState: TransitionCheckState) {

0 commit comments

Comments
 (0)