From 0add8cc8ae888b7cf59394675e6edfb179d2f544 Mon Sep 17 00:00:00 2001 From: Akira Sudoh Date: Fri, 17 Jan 2020 07:45:56 +0900 Subject: [PATCH] fix(Tabs): add ARIA attributes (#4970) This change adds ARIA attributes to `` and `` to better describe their relationship. Fixes #4968. --- packages/react/src/components/Tab/Tab.js | 8 ++++++ .../src/components/TabContent/TabContent.js | 1 + .../react/src/components/Tabs/Tabs-story.js | 26 +++++++++++++------ packages/react/src/components/Tabs/Tabs.js | 11 ++++++-- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/react/src/components/Tab/Tab.js b/packages/react/src/components/Tab/Tab.js index dde7ce38914a..ead5751e62c3 100644 --- a/packages/react/src/components/Tab/Tab.js +++ b/packages/react/src/components/Tab/Tab.js @@ -15,6 +15,11 @@ const { prefix } = settings; export default class Tab extends React.Component { static propTypes = { + /** + * The element ID for the top-level element. + */ + id: PropTypes.string, + /** * Specify an optional className to be added to your Tab */ @@ -104,6 +109,7 @@ export default class Tab extends React.Component { render() { const { + id, className, handleTabClick, handleTabKeyDown, @@ -126,12 +132,14 @@ export default class Tab extends React.Component { }); const anchorProps = { + 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; }, diff --git a/packages/react/src/components/TabContent/TabContent.js b/packages/react/src/components/TabContent/TabContent.js index 4d942191f72d..d190b844dac6 100644 --- a/packages/react/src/components/TabContent/TabContent.js +++ b/packages/react/src/components/TabContent/TabContent.js @@ -19,6 +19,7 @@ const TabContent = props => { }); return (
- !selected ? null : ( + !selected ? ( +
+ ) : (
( - +
Content for first tab goes here.
- +
Content for second tab goes here.
- +
Content for third tab goes here.
Content for fourth tab goes here.
- }> + }>
Content for fifth tab goes here.
@@ -105,19 +111,23 @@ storiesOf('Tabs', module) 'Container', () => ( - +
Content for first tab goes here.
- +
Content for second tab goes here.
Content for third tab goes here.
- }> + }>
Content for fourth tab goes here.
diff --git a/packages/react/src/components/Tabs/Tabs.js b/packages/react/src/components/Tabs/Tabs.js index 0fa5845e9dd3..99d1325de9dd 100644 --- a/packages/react/src/components/Tabs/Tabs.js +++ b/packages/react/src/components/Tabs/Tabs.js @@ -252,14 +252,21 @@ export default class Tabs extends React.Component { }); const tabContentWithProps = React.Children.map(tabsWithProps, tab => { - const { children, selected, renderContent: TabContent } = tab.props; + const { + id: tabId, + children, + selected, + renderContent: TabContent, + } = tab.props; return ( );