Skip to content

Commit

Permalink
fix(material/checkbox): hide svg from assistive technology (#23340)
Browse files Browse the repository at this point in the history
Fixes that the `svg` node inside of the checkbox might be read out by some screen readers.

Fixes #23338.
  • Loading branch information
crisbeto committed Aug 18, 2021
1 parent 2789d8e commit 8bd8f75
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/material-experimental/mdc-checkbox/checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<div class="mdc-checkbox__background">
<svg class="mdc-checkbox__checkmark"
focusable="false"
viewBox="0 0 24 24">
viewBox="0 0 24 24"
aria-hidden="true">
<path class="mdc-checkbox__checkmark-path"
fill="none"
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
Expand Down
5 changes: 5 additions & 0 deletions src/material-experimental/mdc-checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ describe('MDC-based MatCheckbox', () => {
expect(checkboxInstance.ripple).toBeTruthy();
});

it('should hide the internal SVG', () => {
const svg = checkboxNativeElement.querySelector('svg')!;
expect(svg.getAttribute('aria-hidden')).toBe('true');
});

it('should toggle checkbox ripple disabledness correctly', fakeAsync(() => {
const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)';

Expand Down
3 changes: 2 additions & 1 deletion src/material-experimental/mdc-list/list-option.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
[checked]="selected" [disabled]="disabled"/>
<div class="mdc-checkbox__background">
<svg class="mdc-checkbox__checkmark"
viewBox="0 0 24 24">
viewBox="0 0 24 24"
aria-hidden="true">
<path class="mdc-checkbox__checkmark-path"
fill="none"
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
Expand Down
7 changes: 7 additions & 0 deletions src/material-experimental/mdc-list/selection-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,13 @@ describe('MDC-based MatSelectionList without forms', () => {
.every(element => element.querySelector('.mat-mdc-focus-indicator') !== null)).toBe(true);
});

it('should hide the internal SVG', () => {
listOptions.forEach(option => {
const svg = option.nativeElement.querySelector('.mdc-checkbox svg');
expect(svg.getAttribute('aria-hidden')).toBe('true');
});
});

});

describe('with list option selected', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/material/checkbox/checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
focusable="false"
class="mat-checkbox-checkmark"
viewBox="0 0 24 24"
xml:space="preserve">
xml:space="preserve"
aria-hidden="true">
<path class="mat-checkbox-checkmark-path"
fill="none"
stroke="white"
Expand Down
5 changes: 5 additions & 0 deletions src/material/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ describe('MatCheckbox', () => {
expect(checkboxInstance.ripple).toBeTruthy();
});

it('should hide the internal SVG', () => {
const svg = checkboxNativeElement.querySelector('svg')!;
expect(svg.getAttribute('aria-hidden')).toBe('true');
});

it('should add and remove indeterminate state', () => {
expect(checkboxNativeElement.classList).not.toContain('mat-checkbox-checked');
expect(inputElement.checked).toBe(false);
Expand Down

0 comments on commit 8bd8f75

Please sign in to comment.