Skip to content

Commit 5969523

Browse files
crisbetojelbourn
authored andcommitted
fix(button-toggle): set aria-disabled based on group disabled state (#12828)
Based on the [ARIA spec](https://www.w3.org/TR/wai-aria-1.1/#group) elements with a `group` role can have `aria-disabled`. These changes set the attribute, based on whether the group is disabled.
1 parent e18a99f commit 5969523

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ describe('MatButtonToggle without forms', () => {
277277
expect(buttonToggleInstances[0].checked).toBe(true);
278278
});
279279

280+
it('should set aria-disabled based on whether the group is disabled', () => {
281+
expect(groupNativeElement.getAttribute('aria-disabled')).toBe('false');
282+
283+
testComponent.isGroupDisabled = true;
284+
fixture.detectChanges();
285+
286+
expect(groupNativeElement.getAttribute('aria-disabled')).toBe('true');
287+
});
288+
280289
it('should update the group value when one of the toggles changes', () => {
281290
expect(groupInstance.value).toBeFalsy();
282291
buttonToggleLabelElements[0].click();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class MatButtonToggleChange {
8585
host: {
8686
'role': 'group',
8787
'class': 'mat-button-toggle-group',
88+
'[attr.aria-disabled]': 'disabled',
8889
'[class.mat-button-toggle-vertical]': 'vertical'
8990
},
9091
exportAs: 'matButtonToggleGroup',
@@ -98,7 +99,7 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase impleme
9899

99100
/**
100101
* Reference to the raw value that the consumer tried to assign. The real
101-
* value will exaclude any values from this one that don't correspond to a
102+
* value will exclude any values from this one that don't correspond to a
102103
* toggle. Useful for the cases where the value is assigned before the toggles
103104
* have been initialized or at the same that they're being swapped out.
104105
*/

0 commit comments

Comments
 (0)