Skip to content
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
11 changes: 11 additions & 0 deletions src/material-experimental/mdc-checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,17 @@ describe('MatCheckbox', () => {
expect(checkboxInstance.checked).toBe(false);
expect(ngModel.valid).toBe(false);
}));

it('should update the ngModel value when using the `toggle` method', fakeAsync(() => {
const checkbox = fixture.debugElement.query(By.directive(MatCheckbox)).componentInstance;

expect(fixture.componentInstance.isGood).toBe(false);

checkbox.toggle();
fixture.detectChanges();

expect(fixture.componentInstance.isGood).toBe(true);
}));
});

describe('with name attribute', () => {
Expand Down
1 change: 1 addition & 0 deletions src/material-experimental/mdc-checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
/** Toggles the `checked` state of the checkbox. */
toggle() {
this.checked = !this.checked;
this._cvaOnChange(this.checked);
}

/** Handles blur events on the native input. */
Expand Down