Skip to content

Commit

Permalink
feat(Tab): tab a11y
Browse files Browse the repository at this point in the history
  • Loading branch information
guanpu committed Jan 24, 2019
1 parent c68bb3e commit 7a47360
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
6 changes: 3 additions & 3 deletions docs/tab/demo/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { Tab } from '@alifd/next';

ReactDOM.render(
<Tab>
<Tab.Item title="Home">Home content</Tab.Item>
<Tab.Item title="Documentation">Doc content</Tab.Item>
<Tab.Item title="Help">Help Content</Tab.Item>
<Tab.Item title="Home" key="1">Home content</Tab.Item>
<Tab.Item title="Documentation" key="2">Doc content</Tab.Item>
<Tab.Item title="Help" key="3">Help Content</Tab.Item>
</Tab>
, mountNode);
````
Expand Down
6 changes: 3 additions & 3 deletions docs/tab/demo/disabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { Tab } from '@alifd/next';

ReactDOM.render(
<Tab>
<Tab.Item title="Tab 1" disabled>Tab 1 content</Tab.Item>
<Tab.Item title="Tab 2">Tab 2 content</Tab.Item>
<Tab.Item title="Tab 3">Tab 3 content</Tab.Item>
<Tab.Item title="Tab 1" disabled key="1">Tab 1 content</Tab.Item>
<Tab.Item title="Tab 2" key="2">Tab 2 content</Tab.Item>
<Tab.Item title="Tab 3" key="3">Tab 3 content</Tab.Item>
</Tab>
, mountNode);
````
Expand Down
7 changes: 6 additions & 1 deletion src/tab/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
display: inline-block;
position: relative;
transition: all .4s $ease-out-quint;

list-style: none;
padding: 0;
margin: 0;
&-enter,
&-appear {
animation: fadeInLeft .4s cubic-bezier(.78, .14, .15, .86);
Expand Down Expand Up @@ -74,6 +76,9 @@
$tab-close-icon-color-disabled
);
}
&-tab:focus {
outline: none;
}

&-tabpane {
display: none;
Expand Down
18 changes: 11 additions & 7 deletions src/tab/tabs/nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Animate from '../../animate';
import { events } from '../../util';
import { triggerEvents, getOffsetLT, getOffsetWH, isTransformSupported } from './utils';

const noop = () => {};
const noop = () => { };
const floatRight = { float: 'right' };
const floatLeft = { float: 'left' };
const { Popup } = Overlay;
Expand Down Expand Up @@ -64,6 +64,9 @@ class Nav extends React.Component {
ctx.slideTimer = setTimeout(() => {
ctx.setSlideBtn();
}, 200);
if (this.activeTab) {
this.activeTab.focus();
}
}

componentWillUnmount() {
Expand Down Expand Up @@ -231,16 +234,17 @@ class Nav extends React.Component {
}

rst.push(
<div
<li
role="tab"
key={child.key}
ref={active ? this.activeTabRefHandler : null}
aria-disabled={disabled ? 'true' : 'false'}
aria-hidden={disabled ? 'true' : 'false'}
aria-selected={active ? 'true' : 'false'}
tabIndex={active ? 0 : -1}
className={cls}
style={style}
{...events}>{tabTemplateFn(child.key, child.props)}
</div>
</li>
);
});
return rst;
Expand Down Expand Up @@ -424,8 +428,8 @@ class Nav extends React.Component {
<div className={`${prefix}tabs-nav-scroll`}>
{
animation ?
<Animate className={navCls} animation={navCls} singleMode={false} ref={this.navRefHandler}>{tabList}</Animate> :
<div className={navCls} ref={this.navRefHandler}>{tabList}</div>
<Animate role="tablist" aria-multiselectable={false} component="ul" className={navCls} animation={navCls} singleMode={false} ref={this.navRefHandler}>{tabList}</Animate> :
<ul className={navCls} ref={this.navRefHandler}>{tabList}</ul>
}
</div>
</div>
Expand Down Expand Up @@ -455,7 +459,7 @@ class Nav extends React.Component {
}, className);

return (
<div role="tablist" className={navbarCls} style={style} onKeyDown={onKeyDown} tabIndex="0" ref={this.navbarRefHandler}>
<div className={navbarCls} style={style} onKeyDown={onKeyDown} ref={this.navbarRefHandler}>
{navChildren}
</div>
);
Expand Down

0 comments on commit 7a47360

Please sign in to comment.