Skip to content

Commit 08ef775

Browse files
crisbetowagnermaciel
authored andcommitted
fix(material/checkbox): hide svg from assistive technology (#23340)
Fixes that the `svg` node inside of the checkbox might be read out by some screen readers. Fixes #23338. (cherry picked from commit 8bd8f75)
1 parent 8919a1e commit 08ef775

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

src/material-experimental/mdc-checkbox/checkbox.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
<div class="mdc-checkbox__background">
2525
<svg class="mdc-checkbox__checkmark"
2626
focusable="false"
27-
viewBox="0 0 24 24">
27+
viewBox="0 0 24 24"
28+
aria-hidden="true">
2829
<path class="mdc-checkbox__checkmark-path"
2930
fill="none"
3031
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>

src/material-experimental/mdc-checkbox/checkbox.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ describe('MDC-based MatCheckbox', () => {
7575
expect(checkboxInstance.ripple).toBeTruthy();
7676
});
7777

78+
it('should hide the internal SVG', () => {
79+
const svg = checkboxNativeElement.querySelector('svg')!;
80+
expect(svg.getAttribute('aria-hidden')).toBe('true');
81+
});
82+
7883
it('should toggle checkbox ripple disabledness correctly', fakeAsync(() => {
7984
const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)';
8085

src/material-experimental/mdc-list/list-option.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
[checked]="selected" [disabled]="disabled"/>
1515
<div class="mdc-checkbox__background">
1616
<svg class="mdc-checkbox__checkmark"
17-
viewBox="0 0 24 24">
17+
viewBox="0 0 24 24"
18+
aria-hidden="true">
1819
<path class="mdc-checkbox__checkmark-path"
1920
fill="none"
2021
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>

src/material-experimental/mdc-list/selection-list.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,13 @@ describe('MDC-based MatSelectionList without forms', () => {
570570
.every(element => element.querySelector('.mat-mdc-focus-indicator') !== null)).toBe(true);
571571
});
572572

573+
it('should hide the internal SVG', () => {
574+
listOptions.forEach(option => {
575+
const svg = option.nativeElement.querySelector('.mdc-checkbox svg');
576+
expect(svg.getAttribute('aria-hidden')).toBe('true');
577+
});
578+
});
579+
573580
});
574581

575582
describe('with list option selected', () => {

src/material/checkbox/checkbox.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
focusable="false"
3131
class="mat-checkbox-checkmark"
3232
viewBox="0 0 24 24"
33-
xml:space="preserve">
33+
xml:space="preserve"
34+
aria-hidden="true">
3435
<path class="mat-checkbox-checkmark-path"
3536
fill="none"
3637
stroke="white"

src/material/checkbox/checkbox.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ describe('MatCheckbox', () => {
7676
expect(checkboxInstance.ripple).toBeTruthy();
7777
});
7878

79+
it('should hide the internal SVG', () => {
80+
const svg = checkboxNativeElement.querySelector('svg')!;
81+
expect(svg.getAttribute('aria-hidden')).toBe('true');
82+
});
83+
7984
it('should add and remove indeterminate state', () => {
8085
expect(checkboxNativeElement.classList).not.toContain('mat-checkbox-checked');
8186
expect(inputElement.checked).toBe(false);

0 commit comments

Comments
 (0)