Skip to content

Commit 55ee988

Browse files
crisbetommalerba
authored andcommitted
fix(material-experimental/mdc-chips): remove aria-hidden from… (#18054)
The MDC-based `MatChipRemove` extends the `MatChipTrailingIcon` which has `aria-hidden`, however the `MatChipRemove` is focusable which is invalid. These changes clear the `aria-hidden` from the remove icon.
1 parent c36466c commit 55ee988

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/material-experimental/mdc-chips/chip-icons.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const _MatChipRemoveMixinBase:
8484
CanDisableCtor &
8585
HasTabIndexCtor &
8686
typeof MatChipRemoveBase =
87-
mixinTabIndex(mixinDisabled(MatChipRemoveBase));
87+
mixinTabIndex(mixinDisabled(MatChipRemoveBase), 0);
8888

8989
/**
9090
* Directive to remove the parent chip when the trailing icon is clicked or
@@ -95,9 +95,11 @@ const _MatChipRemoveMixinBase:
9595
*
9696
* Example:
9797
*
98-
* `<mat-chip>
99-
* <mat-icon matChipRemove>cancel</mat-icon>
100-
* </mat-chip>`
98+
* ```
99+
* <mat-chip>
100+
* <mat-icon matChipRemove>cancel</mat-icon>
101+
* </mat-chip>
102+
* ```
101103
*/
102104
@Directive({
103105
selector: '[matChipRemove]',
@@ -109,6 +111,9 @@ const _MatChipRemoveMixinBase:
109111
'role': 'button',
110112
'(click)': 'interaction.next($event)',
111113
'(keydown)': 'interaction.next($event)',
114+
115+
// We need to remove this explicitly, because it gets inherited from MatChipTrailingIcon.
116+
'[attr.aria-hidden]': 'null',
112117
}
113118
})
114119
export class MatChipRemove extends _MatChipRemoveMixinBase implements CanDisable, HasTabIndex {

src/material-experimental/mdc-chips/chip-remove.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ describe('MDC-based Chip Remove', () => {
7878

7979
expect(chipNativeElement.classList.contains('mdc-chip--exit')).toBe(false);
8080
});
81+
82+
it('should not make the element aria-hidden when it is focusable', () => {
83+
const buttonElement = chipNativeElement.querySelector('button')!;
84+
85+
expect(buttonElement.getAttribute('tabindex')).toBe('0');
86+
expect(buttonElement.hasAttribute('aria-hidden')).toBe(false);
87+
});
88+
8189
});
8290
});
8391

0 commit comments

Comments
 (0)