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 native checked is not true when MdCheckbox initial checked value is true #2055

Merged
merged 3 commits into from
Dec 2, 2016
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
9 changes: 9 additions & 0 deletions src/lib/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ describe('MdCheckbox', () => {
expect(inputElement.indeterminate).toBe(false);
});

it('should change native element checked when check programmatically', () => {
expect(inputElement.checked).toBe(false);

checkboxInstance.checked = true;
fixture.detectChanges();

expect(inputElement.checked).toBe(true);
});

it('should toggle checked state on click', () => {
expect(checkboxInstance.checked).toBe(false);

Expand Down
6 changes: 5 additions & 1 deletion src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ChangeDetectorRef,
ChangeDetectionStrategy,
Component,
ElementRef,
Expand Down Expand Up @@ -151,7 +152,9 @@ export class MdCheckbox implements ControlValueAccessor {

hasFocus: boolean = false;

constructor(private _renderer: Renderer, private _elementRef: ElementRef) {
constructor(private _renderer: Renderer,
private _elementRef: ElementRef,
private _changeDetectorRef: ChangeDetectorRef) {
this.color = 'accent';
}

Expand All @@ -169,6 +172,7 @@ export class MdCheckbox implements ControlValueAccessor {
this._checked = checked;
this._transitionCheckState(
this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
this._changeDetectorRef.markForCheck();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test. PTAL, thanks!

}
}

Expand Down