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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One request: the spec tests only check the attribute on the anchor, and the button added to the a11y page only runs through axe, which passes whether or not the button can take focus. Please add a test to test/a11y/tab-button.e2e.ts that presses Tab. Something like this, modeled on the button: tabindex test in button/test/a11y/button.e2e.ts:

/**
 * Tab order does not vary across modes or directions
 */
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
  test.describe(title('tab-button: tabindex'), () => {
    test('should reach tab buttons without href and skip a host tabindex of -1', async ({ page, pageUtils }) => {
      test.info().annotations.push({
        type: 'issue',
        description: 'https://github.com/ionic-team/ionic-framework/issues/30648',
      });

      await page.setContent(
        `
        <input id="before" />
        <ion-tabs>
          <ion-tab tab="one">One</ion-tab>
          <ion-tab tab="two">Two</ion-tab>
          <ion-tab tab="three">Three</ion-tab>
          <ion-tab-bar slot="bottom">
            <ion-tab-button tab="one">One</ion-tab-button>
            <ion-tab-button tab="two" tabindex="-1">Two</ion-tab-button>
            <ion-tab-button tab="three">Three</ion-tab-button>
          </ion-tab-bar>
        </ion-tabs>
      `,
        config
      );

      const three = page.locator('ion-tab-button[tab="three"]');

      await page.locator('#before').focus();

      await pageUtils.pressKeys('Tab');
      await expect(page.locator('ion-tab-button[tab="one"] a')).toBeFocused();

      await pageUtils.pressKeys('Tab');
      await expect(three.locator('a')).toBeFocused();

      await page.keyboard.press('Enter');
      await expect(three).toHaveClass(/tab-selected/);
    });
  });
});

Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class TabButton implements ComponentInterface, AnchorInterface {
role="tab"
aria-selected={selected ? 'true' : null}
aria-disabled={disabled ? 'true' : null}
tabindex={disabled ? '-1' : tabindex}
tabindex={disabled ? '-1' : tabindex ?? '0'}
{...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
44 changes: 44 additions & 0 deletions core/src/components/tab-button/test/a11y/tab-button.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,47 @@ configs().forEach(({ title, config }) => {
});
});
});

/**
* Tab order does not vary across modes or directions
*/
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('tab-button: tabindex'), () => {
test('should reach tab buttons without href and skip a host tabindex of -1', async ({ page, pageUtils }) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30648',
});

await page.setContent(
`
<input id="before" />
<ion-tabs>
<ion-tab tab="one">One</ion-tab>
<ion-tab tab="two">Two</ion-tab>
<ion-tab tab="three">Three</ion-tab>
<ion-tab-bar slot="bottom">
<ion-tab-button tab="one">One</ion-tab-button>
<ion-tab-button tab="two" tabindex="-1">Two</ion-tab-button>
<ion-tab-button tab="three">Three</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
`,
config
);

const three = page.locator('ion-tab-button[tab="three"]');

await page.locator('#before').focus();

await pageUtils.pressKeys('Tab');
await expect(page.locator('ion-tab-button[tab="one"] a')).toBeFocused();

await pageUtils.pressKeys('Tab');
await expect(three.locator('a')).toBeFocused();

await page.keyboard.press('Enter');
await expect(three).toHaveClass(/tab-selected/);
});
});
});
24 changes: 24 additions & 0 deletions core/src/components/tab-button/test/tab-button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ import { newSpecPage } from '@stencil/core/testing';
import { TabButton } from '../tab-button';

describe('tab button: tabindex', () => {
// https://github.com/ionic-team/ionic-framework/issues/30648
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');
});

// https://github.com/ionic-team/ionic-framework/issues/30648
it('should render tabindex="0" on the native element when href is defined', 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('0');
});

it('should move tabindex from the host to the native anchor', async () => {
const page = await newSpecPage({
components: [TabButton],
Expand Down