Skip to content

Commit

Permalink
fix: add aria-hidden="true" to ripple, focus ring, and elevation
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 562075778
  • Loading branch information
asyncLiz authored and copybara-github committed Sep 1, 2023
1 parent cdd2ea6 commit 2295f12
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
11 changes: 4 additions & 7 deletions chips/internal/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ export abstract class Chip extends LitElement {
}

protected renderContainerContent() {
// Note: add aria-hidden="true" to focus ring and ripple. For some reason
// they cause VoiceOver to get stuck inside filter chip sets without it.
// TODO(b/297428579): investigate and file VoiceOver bug
return html`
${this.renderOutline()}
<md-focus-ring part="focus-ring" for=${this.primaryId}
aria-hidden="true"></md-focus-ring>
<md-ripple for=${this.primaryId} ?disabled=${this.rippleDisabled}
aria-hidden="true"></md-ripple>
<md-focus-ring part="focus-ring"
for=${this.primaryId}></md-focus-ring>
<md-ripple for=${this.primaryId}
?disabled=${this.rippleDisabled}></md-ripple>
${this.renderPrimaryAction(this.renderPrimaryContent())}
`;
}
Expand Down
4 changes: 2 additions & 2 deletions docs/components/figures/fab/extended-fabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div>
<div class="fab-wrapper">
<md-fab label="navigate" variant="primary">
<md-icon slot="icon" aria-hidden="true">navigation</md-icon>
<md-icon slot="icon">navigation</md-icon>
</md-fab>
</div>
<span>1</span>
Expand All @@ -22,4 +22,4 @@
</div>
</div>
</figure>
</div>
</div>
7 changes: 7 additions & 0 deletions elevation/internal/elevation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import {html, LitElement} from 'lit';
* A component for elevation.
*/
export class Elevation extends LitElement {
override connectedCallback() {
super.connectedCallback();
// Needed for VoiceOver, which will create a "group" if the element is a
// sibling to other content.
this.setAttribute('aria-hidden', 'true');
}

protected override render() {
return html`<span class="shadow"></span>`;
}
Expand Down
7 changes: 7 additions & 0 deletions focus/internal/focus-ring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export class FocusRing extends LitElement implements Attachable {
this.attachableController.detach();
}

override connectedCallback() {
super.connectedCallback();
// Needed for VoiceOver, which will create a "group" if the element is a
// sibling to other content.
this.setAttribute('aria-hidden', 'true');
}

/** @private */
handleEvent(event: FocusRingEvent) {
if (event[HANDLED_BY_FOCUS_RING]) {
Expand Down
4 changes: 4 additions & 0 deletions icon/internal/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ export class Icon extends LitElement {
super.connectedCallback();
const ariaHidden = this.getAttribute('aria-hidden');
if (ariaHidden === 'false') {
// Allow the user to set `aria-hidden="false"` to create an icon that is
// announced by screenreaders.
this.removeAttribute('aria-hidden');
return;
}

// Needed for VoiceOver, which will create a "group" if the element is a
// sibling to other content.
this.setAttribute('aria-hidden', 'true');
}
}
7 changes: 7 additions & 0 deletions ripple/internal/ripple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ export class Ripple extends LitElement implements Attachable {
this.attachableController.detach();
}

override connectedCallback() {
super.connectedCallback();
// Needed for VoiceOver, which will create a "group" if the element is a
// sibling to other content.
this.setAttribute('aria-hidden', 'true');
}

protected override render() {
const classes = {
'hovered': this.hovered,
Expand Down
3 changes: 1 addition & 2 deletions tabs/demo/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ function getTabContentGenerator(knobs: StoryKnobs) {
const useIcon = contentKnob !== 'label';
const useLabel = contentKnob !== 'icon';
return (icon: string, label: string) => {
const iconTemplate =
html`<md-icon aria-hidden="true" slot="icon">${icon}</md-icon>`;
const iconTemplate = html`<md-icon slot="icon">${icon}</md-icon>`;
return html`
${useIcon ? iconTemplate : nothing}
${useLabel ? html`${label}` : nothing}
Expand Down

0 comments on commit 2295f12

Please sign in to comment.