Update button toggle group disabled (#6991)

This commit is contained in:
tinayuangao
2017-09-29 13:16:12 -07:00
committed by Andrew Seguin
parent 6f487100fd
commit b1ceeecd88
2 changed files with 29 additions and 0 deletions
@@ -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', () => {
+18
View File
@@ -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();
}
}