Skip to content

Commit

Permalink
fix(Tab): hoist tab role to upper element (#5173)
Browse files Browse the repository at this point in the history
This change hoists `tab` role and its associated ARIA attributes from
`<a>` to `<li>`, given putting `tab` role to `<a>` makes VoiceOver
think it's a single tab in a container.

No new DAP error is observed by this change.

Fixes #5083.
  • Loading branch information
asudoh authored Jan 31, 2020
1 parent c5fddd1 commit d6a36a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 2 additions & 6 deletions packages/react/src/components/Tab/Tab-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ describe('Tab', () => {
);
});

it('renders <li> with [role="presentation"]', () => {
expect(wrapper.props().role).toEqual('presentation');
});

it('renders <a> with [role="tab"]', () => {
expect(wrapper.find('a').props().role).toEqual('tab');
it('renders <li> with [role="tab"]', () => {
expect(wrapper.props().role).toEqual('tab');
});

it('renders <a> with tabindex set to 0', () => {
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/components/Tab/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ export default class Tab extends React.Component {
id,
className: `${prefix}--tabs__nav-link`,
href,
role: 'tab',
tabIndex: !disabled ? tabIndex : -1,
['aria-selected']: selected,
['aria-disabled']: disabled,
['aria-controls']: id && `${id}__panel`,
ref: e => {
this.tabAnchor = e;
},
Expand All @@ -164,8 +160,10 @@ export default class Tab extends React.Component {
handleTabKeyDown(index, evt);
onKeyDown(evt);
}}
role="presentation"
selected={selected}>
role="tab"
aria-selected={selected}
aria-disabled={disabled}
aria-controls={`${id}__panel`}>
{renderAnchor ? (
renderAnchor(anchorProps)
) : (
Expand Down

0 comments on commit d6a36a9

Please sign in to comment.