Skip to content

Commit

Permalink
fix(): adding aria-hidden no longer disables automatic rtl switching (i…
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdebeasi authored Mar 22, 2021
1 parent 0d7f507 commit c76f2a2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"version": "npm run build"
},
"dependencies": {
"@stencil/core": "^2.4.0"
"@stencil/core": "^2.5.0"
},
"devDependencies": {
"@types/fs-extra": "^9.0.6",
Expand Down
9 changes: 6 additions & 3 deletions src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getName, getUrl } from './utils';
})
export class Icon {
private io?: IntersectionObserver;
private iconName: string | null = null;

@Element() el!: HTMLElement;

Expand Down Expand Up @@ -143,8 +144,9 @@ export class Icon {
}
}

const label = this.iconName = getName(this.name, this.icon, this.mode, this.ios, this.md);

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

render() {
const { iconName } = this;
const mode = this.mode || 'md';
const flipRtl =
this.flipRtl ||
(this.ariaLabel &&
(this.ariaLabel.indexOf('arrow') > -1 || this.ariaLabel.indexOf('chevron') > -1) &&
(iconName &&
(iconName.indexOf('arrow') > -1 || iconName.indexOf('chevron') > -1) &&
this.flipRtl !== false);

return (
Expand Down
16 changes: 16 additions & 0 deletions src/components/icon/test/icon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,20 @@ describe('icon', () => {
</ion-icon>
`);
});

it('renders rtl with aria-hidden', async () => {
const { root } = await newSpecPage({
components: [Icon],
direction: 'rtl',
html: `<ion-icon name="chevron-forward" aria-hidden="true"></ion-icon>`,
});

expect(root).toEqualHtml(`
<ion-icon class="md flip-rtl" name="chevron-forward" role="img" aria-hidden="true">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
</ion-icon>
`);
});
});

0 comments on commit c76f2a2

Please sign in to comment.