Skip to content

Commit

Permalink
fix(button-toggle): emit change event when button is clicked (angular…
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao authored Jun 22, 2018
1 parent d96adbe commit c276e26
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/lib/button-toggle/button-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,8 @@ describe('MatButtonToggle without forms', () => {
fixture.detectChanges();
tick();

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

it('should emit a change event from the button toggle group', fakeAsync(() => {
Expand Down
5 changes: 2 additions & 3 deletions src/lib/button-toggle/button-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,9 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
this.buttonToggleGroup._syncButtonToggle(this, this._checked, true);
this.buttonToggleGroup._onTouched();
}

// Emit a change event when the native button does.
this.change.emit(new MatButtonToggleChange(this, this.value));
}
// Emit a change event when it's the single selector
this.change.emit(new MatButtonToggleChange(this, this.value));
}

/**
Expand Down

0 comments on commit c276e26

Please sign in to comment.