Skip to content

Commit 98975ec

Browse files
fix(icon): remove auto-generated aria-label (#1170)
1 parent 93b4fa4 commit 98975ec

File tree

2 files changed

+2
-84
lines changed

2 files changed

+2
-84
lines changed

src/components/icon/icon.tsx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export class Icon {
1919

2020
@State() private svgContent?: string;
2121
@State() private isVisible = false;
22-
@State() private ariaLabel?: string;
2322

2423
/**
2524
* The mode determines which platform styles to use.
@@ -124,12 +123,6 @@ export class Icon {
124123
cb();
125124
}
126125
}
127-
128-
private hasAriaHidden = () => {
129-
const { el } = this;
130-
131-
return el.hasAttribute('aria-hidden') && el.getAttribute('aria-hidden') === 'true';
132-
}
133126

134127
@Watch('name')
135128
@Watch('src')
@@ -164,36 +157,20 @@ export class Icon {
164157
}
165158
}
166159

167-
const label = this.iconName = getName(this.name, this.icon, this.mode, this.ios, this.md);
168-
169-
/**
170-
* Come up with a default label
171-
* in case user does not provide their own.
172-
*/
173-
if (label) {
174-
this.ariaLabel = label.replace(/\-/g, ' ');
175-
}
160+
this.iconName = getName(this.name, this.icon, this.mode, this.ios, this.md);
176161
}
177162

178163
render() {
179-
const { iconName, ariaLabel, el, inheritedAttributes } = this;
164+
const { iconName, el, inheritedAttributes } = this;
180165
const mode = this.mode || 'md';
181166
const flipRtl =
182167
this.flipRtl ||
183168
(iconName &&
184169
(iconName.indexOf('arrow') > -1 || iconName.indexOf('chevron') > -1) &&
185170
this.flipRtl !== false);
186171

187-
/**
188-
* Only set the aria-label if a) we have generated
189-
* one for the icon and if aria-hidden is not set to "true".
190-
* If developer wants to set their own aria-label, then
191-
* inheritedAttributes down below will override whatever
192-
* default label we have set.
193-
*/
194172
return (
195173
<Host
196-
aria-label={ariaLabel !== undefined && !this.hasAriaHidden() ? ariaLabel : null}
197174
role="img"
198175
class={{
199176
[mode]: true,

src/components/icon/test/icon.spec.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ describe('icon', () => {
1616
`);
1717
});
1818

19-
it('renders aria-hidden and no aria-label', async () => {
20-
const { root } = await newSpecPage({
21-
components: [Icon],
22-
html: `<ion-icon aria-hidden="true"></ion-icon>`,
23-
});
24-
expect(root).toEqualHtml(`
25-
<ion-icon class="md" role="img" aria-hidden="true">
26-
<mock:shadow-root>
27-
<div class="icon-inner"></div>
28-
</mock:shadow-root>
29-
</ion-icon>
30-
`);
31-
});
32-
3319
it('renders rtl with aria-hidden', async () => {
3420
const { root } = await newSpecPage({
3521
components: [Icon],
@@ -46,21 +32,6 @@ describe('icon', () => {
4632
`);
4733
});
4834

49-
it('renders default aria-label', async () => {
50-
const { root } = await newSpecPage({
51-
components: [Icon],
52-
html: `<ion-icon name="chevron-forward"></ion-icon>`,
53-
});
54-
55-
expect(root).toEqualHtml(`
56-
<ion-icon class="md" name="chevron-forward" role="img" aria-label="chevron forward">
57-
<mock:shadow-root>
58-
<div class="icon-inner"></div>
59-
</mock:shadow-root>
60-
</ion-icon>
61-
`);
62-
});
63-
6435
it('renders custom aria-label', async () => {
6536
const { root } = await newSpecPage({
6637
components: [Icon],
@@ -105,34 +76,4 @@ describe('icon', () => {
10576
</ion-icon>
10677
`);
10778
});
108-
109-
it('renders default label after changing source', async () => {
110-
const page = await newSpecPage({
111-
components: [Icon],
112-
html: `<ion-icon name="chevron-forward"></ion-icon>`,
113-
});
114-
115-
const icon = page.root;
116-
117-
expect(icon).toEqualHtml(`
118-
<ion-icon class="md" name="chevron-forward" role="img" aria-label="chevron forward">
119-
<mock:shadow-root>
120-
<div class="icon-inner"></div>
121-
</mock:shadow-root>
122-
</ion-icon>
123-
`);
124-
125-
if (icon) {
126-
icon.name = 'trash';
127-
}
128-
await page.waitForChanges();
129-
130-
expect(icon).toEqualHtml(`
131-
<ion-icon class="md" name="trash" role="img" aria-label="trash">
132-
<mock:shadow-root>
133-
<div class="icon-inner"></div>
134-
</mock:shadow-root>
135-
</ion-icon>
136-
`);
137-
});
13879
});

0 commit comments

Comments
 (0)