Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/components/tab-button/tab-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class TabButton implements ComponentInterface, AnchorInterface {
role="tab"
aria-selected={selected ? 'true' : null}
aria-disabled={disabled ? 'true' : null}
tabindex={disabled ? '-1' : undefined}
tabindex={disabled ? '-1' : href === undefined || href === null ? '0' : undefined}
{...inheritedAttributes}
>
<span class="button-inner">
Expand Down
5 changes: 5 additions & 0 deletions core/src/components/tab-button/test/a11y/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ <h1>Tab Button</h1>
<ion-badge aria-hidden="true" color="primary">6</ion-badge>
</ion-tab-button>

<ion-tab-button tab="search">
<ion-label>Search</ion-label>
<ion-icon aria-hidden="true" name="search"></ion-icon>
</ion-tab-button>

<ion-tab-button hidden>
<ion-label>Hidden</ion-label>
<ion-icon aria-hidden="true" name="alert"></ion-icon>
Expand Down
43 changes: 43 additions & 0 deletions core/src/components/tab-button/test/tab-button.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { newSpecPage } from '@stencil/core/testing';

import { TabButton } from '../tab-button';

describe('tab-button: rendering', () => {
it('should render tabindex="0" on the native element when href is not defined', async () => {
const page = await newSpecPage({
components: [TabButton],
html: `<ion-tab-button tab="schedule"></ion-tab-button>`,
});

const nativeEl = page.body.querySelector('ion-tab-button')!.shadowRoot!.querySelector('a')!;

expect(nativeEl.getAttribute('tabindex')).toBe('0');
});

it('should update tabindex when href is removed', async () => {
const page = await newSpecPage({
components: [TabButton],
html: `<ion-tab-button tab="schedule" href="/schedule"></ion-tab-button>`,
});

const nativeEl = page.body.querySelector('ion-tab-button')!.shadowRoot!.querySelector('a')!;

expect(nativeEl.getAttribute('tabindex')).toBe(null);

page.root!.removeAttribute('href');
await page.waitForChanges();

expect(nativeEl.getAttribute('tabindex')).toBe('0');
});

it('should render tabindex="-1" on the native element when disabled', async () => {
const page = await newSpecPage({
components: [TabButton],
html: `<ion-tab-button tab="schedule" disabled="true"></ion-tab-button>`,
});

const nativeEl = page.body.querySelector('ion-tab-button')!.shadowRoot!.querySelector('a')!;

expect(nativeEl.getAttribute('tabindex')).toBe('-1');
});
});
Loading