mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
Update button toggle group disabled (#6991)
This commit is contained in:
committed by
Andrew Seguin
parent
6f487100fd
commit
b1ceeecd88
@@ -245,6 +245,17 @@ describe('MatButtonToggle without forms', () => {
|
||||
|
||||
buttonToggleNativeElements[0].click();
|
||||
expect(buttonToggleInstances[0].checked).toBe(false);
|
||||
expect(buttonToggleInstances[0].disabled).toBe(true);
|
||||
|
||||
testComponent.isGroupDisabled = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(buttonToggleInstances[0].disabled).toBe(false);
|
||||
|
||||
buttonToggleLabelElements[0].click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(buttonToggleInstances[0].checked).toBe(true);
|
||||
});
|
||||
|
||||
it('should update the group value when one of the toggles changes', () => {
|
||||
|
||||
@@ -224,6 +224,13 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
|
||||
*/
|
||||
setDisabledState(isDisabled: boolean): void {
|
||||
this.disabled = isDisabled;
|
||||
this._markButtonTogglesForCheck();
|
||||
}
|
||||
|
||||
private _markButtonTogglesForCheck() {
|
||||
if (this._buttonToggles) {
|
||||
this._buttonToggles.forEach((toggle) => toggle._markForCheck());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,4 +471,15 @@ export class MatButtonToggle implements OnInit, OnDestroy {
|
||||
ngOnDestroy(): void {
|
||||
this._removeUniqueSelectionListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the button toggle as needing checking for change detection.
|
||||
* This method is exposed because the parent button toggle group will directly
|
||||
* update bound properties of the radio button.
|
||||
*/
|
||||
_markForCheck() {
|
||||
// When group value changes, the button will not be notified. Use `markForCheck` to explicit
|
||||
// update button toggle's status
|
||||
this._changeDetectorRef.markForCheck();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user