Skip to content

Commit c76f2a2

Browse files
authored
fix(): adding aria-hidden no longer disables automatic rtl switching (#954)
1 parent 0d7f507 commit c76f2a2

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"version": "npm run build"
2525
},
2626
"dependencies": {
27-
"@stencil/core": "^2.4.0"
27+
"@stencil/core": "^2.5.0"
2828
},
2929
"devDependencies": {
3030
"@types/fs-extra": "^9.0.6",

src/components/icon/icon.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getName, getUrl } from './utils';
1010
})
1111
export class Icon {
1212
private io?: IntersectionObserver;
13+
private iconName: string | null = null;
1314

1415
@Element() el!: HTMLElement;
1516

@@ -143,8 +144,9 @@ export class Icon {
143144
}
144145
}
145146

147+
const label = this.iconName = getName(this.name, this.icon, this.mode, this.ios, this.md);
148+
146149
if (!this.ariaLabel && this.ariaHidden !== 'true') {
147-
const label = getName(this.name, this.icon, this.mode, this.ios, this.md);
148150
// user did not provide a label
149151
// come up with the label based on the icon name
150152
if (label) {
@@ -154,11 +156,12 @@ export class Icon {
154156
}
155157

156158
render() {
159+
const { iconName } = this;
157160
const mode = this.mode || 'md';
158161
const flipRtl =
159162
this.flipRtl ||
160-
(this.ariaLabel &&
161-
(this.ariaLabel.indexOf('arrow') > -1 || this.ariaLabel.indexOf('chevron') > -1) &&
163+
(iconName &&
164+
(iconName.indexOf('arrow') > -1 || iconName.indexOf('chevron') > -1) &&
162165
this.flipRtl !== false);
163166

164167
return (

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

+16
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,20 @@ describe('icon', () => {
2929
</ion-icon>
3030
`);
3131
});
32+
33+
it('renders rtl with aria-hidden', async () => {
34+
const { root } = await newSpecPage({
35+
components: [Icon],
36+
direction: 'rtl',
37+
html: `<ion-icon name="chevron-forward" aria-hidden="true"></ion-icon>`,
38+
});
39+
40+
expect(root).toEqualHtml(`
41+
<ion-icon class="md flip-rtl" name="chevron-forward" role="img" aria-hidden="true">
42+
<mock:shadow-root>
43+
<div class="icon-inner"></div>
44+
</mock:shadow-root>
45+
</ion-icon>
46+
`);
47+
});
3248
});

0 commit comments

Comments
 (0)