Repository navigation
Conversation
|
@cpruijsen is attempting to deploy a commit to the Ionic Team on Vercel. A member of the Team first needs to authorize it. |
# Conflicts: # core/src/components/tab-button/tab-button.tsx # core/src/components/tab-button/test/tab-button.spec.ts
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
thetaPC
left a comment
There was a problem hiding this comment.
Congrats on your first PR to Ionic Framework, and thanks for picking this up!
The approach looks right: a tabindex set on the host still wins, and disabled still takes the button out of the tab order. I left a suggestion to extend the fix to tab buttons with an href.
| 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'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('tab button: tabindex', () => { |
There was a problem hiding this comment.
These belong in the existing tab button: tabindex describe:
- Keeping a separate
tab-button: renderingblock splits the tabindex tests across two describes with different name spellings. - The disabled test repeats "should keep a disabled tab button out of the tab order" below, and this PR doesn't change the
disabledbranch. - With the
'0'fallback, removinghrefno longer changes the result. A test with anhrefcovers the Safari case instead. - The tests verify bug: ion-tab-button isn't focusable when no href #30648, so they should link it, the way other spec files do.
| 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'); | |
| }); | |
| }); | |
| describe('tab button: tabindex', () => { | |
| 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'); | |
| }); | |
There was a problem hiding this comment.
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/);
});
});
});| aria-selected={selected ? 'true' : null} | ||
| aria-disabled={disabled ? 'true' : null} | ||
| tabindex={disabled ? '-1' : tabindex} | ||
| tabindex={disabled ? '-1' : tabindex ?? (href === undefined || href === null ? '0' : undefined)} |
There was a problem hiding this comment.
- Keeping the
hrefcheck leaves tab buttons with anhrefout of the tab order in Safari, which skips<a href>on Tab unless it has an explicittabindex. Apps that route their tab bar would keep the regression from bug: ion-tab-button isn't focusable when no href #30648 there. - An anchor with an
hrefis already focusable in other browsers, so an explicittabindex="0"changes nothing for them.
| tabindex={disabled ? '-1' : tabindex ?? (href === undefined || href === null ? '0' : undefined)} | |
| tabindex={disabled ? '-1' : tabindex ?? '0'} |
|
Thanks for the review! I applied all three: the tests are in the existing describe with the issue link, there's a Tab-press e2e test, and tab buttons with an |
Enabled
ion-tab-buttoncontrols can now receive keyboard focus, with or withouthref.Issue number: resolves #30648
What is the current behavior?
Tab navigation skips enabled
ion-tab-buttoncontrols withouthrefbecause the native anchor has notabindex. Safari also skips controls withhref, because it skips<a href>on Tab unless it has an explicittabindex.What is the new behavior?
core/src/components/tab-button/tab-button.tsxsetstabindex="0"on the native anchor of an enabled tab button when the host has notabindex. Atabindexset on the host still wins, and disabled controls keeptabindex="-1".tab button: tabindexdescribe cover a tab button with and withouthref.test/a11y/tab-button.e2e.tspresses Tab through a tab bar: it reaches a button withouthref, skips one with a hosttabindex="-1", and selects the next with Enter.Does this introduce a breaking change?
Other information
Other browsers already focus an anchor with
href, so the explicittabindex="0"changes nothing there.The new spec tests fail against the base source and pass with the change. The new e2e test fails against the base source in Mobile Chrome and passes with the change.