Skip to content

Commit c276e26

Browse files
authored
fix(button-toggle): emit change event when button is clicked (#11886)
1 parent d96adbe commit c276e26

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/lib/button-toggle/button-toggle.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,8 @@ describe('MatButtonToggle without forms', () => {
345345
fixture.detectChanges();
346346
tick();
347347

348-
// The default browser behavior is to not emit a change event, when the value was set
349-
// to false. That's because the current input type is set to `radio`
350-
expect(changeSpy).toHaveBeenCalledTimes(1);
348+
// Always emit change event when button toggle is clicked
349+
expect(changeSpy).toHaveBeenCalledTimes(2);
351350
}));
352351

353352
it('should emit a change event from the button toggle group', fakeAsync(() => {

src/lib/button-toggle/button-toggle.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,9 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
447447
this.buttonToggleGroup._syncButtonToggle(this, this._checked, true);
448448
this.buttonToggleGroup._onTouched();
449449
}
450-
451-
// Emit a change event when the native button does.
452-
this.change.emit(new MatButtonToggleChange(this, this.value));
453450
}
451+
// Emit a change event when it's the single selector
452+
this.change.emit(new MatButtonToggleChange(this, this.value));
454453
}
455454

456455
/**

0 commit comments

Comments
 (0)