Skip to content

Commit

Permalink
fix(tabs): Fix focusability of the More button (#1350)
Browse files Browse the repository at this point in the history
The "More" button in tabs should be focusable so that keyboard users and screen reader users can access it.

[category:Components]
  • Loading branch information
NicholasBoll authored Nov 23, 2021
1 parent 9ad89e3 commit 277b5c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions cypress/integration/Tabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,24 @@ describe('Tabs', () => {
cy.findByRole('button', {name: 'More'}).should('not.exist');
});

context('when the "First Tab" is focused', () => {
beforeEach(() => {
cy.findByRole('tab', {name: 'First Tab'})
.click()
.focus();
});

context('when the Tab key is pressed', () => {
beforeEach(() => {
cy.focused().tab();
});

it('should focus on the tab panel', () => {
cy.findByRole('tabpanel', {name: 'First Tab'}).should('have.focus');
});
});
});

context('when tab list container is only 500px wide', () => {
beforeEach(() => {
cy.findByRole('button', {name: '500px'}).click();
Expand All @@ -510,6 +528,24 @@ describe('Tabs', () => {
cy.findByRole('button', {name: 'More'}).should('exist');
});

context('when the "First Tab" is focused', () => {
beforeEach(() => {
cy.findByRole('tab', {name: 'First Tab'})
.click()
.focus();
});

context('when the Tab key is pressed', () => {
beforeEach(() => {
cy.focused().tab();
});

it('should focus on the "More" button', () => {
cy.findByRole('button', {name: 'More'}).should('have.focus');
});
});
});

context('when the "More" button is clicked', () => {
beforeEach(() => {
cy.findByRole('button', {name: 'More'}).click();
Expand Down
2 changes: 1 addition & 1 deletion modules/react/tabs/lib/overflow/useOverflowTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useOverflowTarget = createHook(
return {
ref: elementRef,
'aria-hidden': isHidden,
tabIndex: -1,
tabIndex: isHidden ? -1 : 0,
style: isHidden ? hiddenStyle : {},
};
}
Expand Down

0 comments on commit 277b5c9

Please sign in to comment.