Skip to content

Commit

Permalink
Make elements keyboard accessible
Browse files Browse the repository at this point in the history
Work in progress
  • Loading branch information
Gabriel Ramirez committed May 24, 2017
1 parent 3783be1 commit 0aec9b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Pager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ const Pager = (props) => {
}

return (
<li title={props.showTitle ? props.page : null} className={cls} onClick={props.onClick}>
<li
title={props.showTitle ? props.page : null}
className={cls} onClick={props.onClick}
onKeyPress={props.onKeyPress}
tabIndex="0"
>
<a>{props.page}</a>
</li>
);
Expand All @@ -29,6 +34,7 @@ Pager.propTypes = {
showTitle: PropTypes.bool,
rootPrefixCls: PropTypes.string,
onClick: PropTypes.func,
onKeyPress: PropTypes.func,
};

export default Pager;
20 changes: 20 additions & 0 deletions src/Pagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class Pagination extends React.Component {
return this.state.current < this._calcPage();
}

_runIfEnter(event, callback) {
if (event.key === 'Enter') {
callback();
}
}

render() {
const props = this.props;
const locale = props.locale;
Expand All @@ -211,6 +217,8 @@ class Pagination extends React.Component {
<li
title={props.showTitle ? locale.prev_page : null}
onClick={this._prev}
tabIndex="0"
onKeyPress={(evt) => this._runIfEnter(evt, this._prev)}
className={`${this._hasPrev() ? '' : `${prefixCls}-disabled`} ${prefixCls}-prev`}
aria-disabled={!this._hasPrev()}
>
Expand All @@ -233,6 +241,8 @@ class Pagination extends React.Component {
<li
title={props.showTitle ? locale.next_page : null}
onClick={this._next}
tabIndex="0"
onKeyPress={(evt) => this._runIfEnter(evt, this._next)}
className={`${this._hasNext() ? '' : `${prefixCls}-disabled`} ${prefixCls}-next`}
aria-disabled={!this._hasNext()}
>
Expand All @@ -250,6 +260,7 @@ class Pagination extends React.Component {
locale={locale}
rootPrefixCls={prefixCls}
onClick={this._handleChange.bind(this, i)}
onKeyPress={(evt) => this._runIfEnter(evt, this._handleChange.bind(this, i))}
key={i}
page={i}
active={active}
Expand All @@ -265,6 +276,7 @@ class Pagination extends React.Component {
title={props.showTitle ? prevItemTitle : null}
key="prev"
onClick={this._jumpPrev}
onKeyPress={(evt) => this._runIfEnter(evt, this._jumpPrev)}
className={`${prefixCls}-jump-prev`}
>
<a />
Expand All @@ -275,6 +287,7 @@ class Pagination extends React.Component {
title={props.showTitle ? nextItemTitle : null}
key="next"
onClick={this._jumpNext}
onKeyPress={(evt) => this._runIfEnter(evt, this._jumpNext)}
className={`${prefixCls}-jump-next`}
>
<a />
Expand All @@ -286,6 +299,7 @@ class Pagination extends React.Component {
last
rootPrefixCls={prefixCls}
onClick={this._handleChange.bind(this, allPages)}
onKeyPress={(evt) => this._runIfEnter(evt, this._handleChange.bind(this, allPages))}
key={allPages}
page={allPages}
active={false}
Expand All @@ -297,6 +311,7 @@ class Pagination extends React.Component {
locale={props.locale}
rootPrefixCls={prefixCls}
onClick={this._handleChange.bind(this, 1)}
onKeyPress={(evt) => this._runIfEnter(evt, this._handleChange.bind(this, 1))}
key={1}
page={1}
active={false}
Expand All @@ -322,6 +337,7 @@ class Pagination extends React.Component {
locale={props.locale}
rootPrefixCls={prefixCls}
onClick={this._handleChange.bind(this, i)}
onKeyPress={(evt) => this._runIfEnter(evt, this._handleChange.bind(this, i))}
key={i}
page={i}
active={active}
Expand Down Expand Up @@ -378,6 +394,8 @@ class Pagination extends React.Component {
<li
title={props.showTitle ? locale.prev_page : null}
onClick={this._prev}
tabIndex="0"
onKeyPress={(evt) => this._runIfEnter(evt, this._prev)}
className={`${!prevDisabled ? '' : `${prefixCls}-disabled`} ${prefixCls}-prev`}
aria-disabled={prevDisabled}
>
Expand All @@ -387,6 +405,8 @@ class Pagination extends React.Component {
<li
title={props.showTitle ? locale.next_page : null}
onClick={this._next}
tabIndex="0"
onKeyPress={(evt) => this._runIfEnter(evt, this._next)}
className={`${!nextDisabled ? '' : `${prefixCls}-disabled`} ${prefixCls}-next`}
aria-disabled={nextDisabled}
>
Expand Down

0 comments on commit 0aec9b6

Please sign in to comment.