From c359154214b1a2647d8dff34cb58f9e63c83e5af Mon Sep 17 00:00:00 2001 From: Patrick Oyarzun Date: Thu, 25 May 2017 10:30:51 -0400 Subject: [PATCH] Add ability to navigate using keyboard Signed-off-by: Gabriel Ramirez --- src/Pager.jsx | 9 ++++++++- src/Pagination.jsx | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Pager.jsx b/src/Pager.jsx index bb623763..d471c2e8 100644 --- a/src/Pager.jsx +++ b/src/Pager.jsx @@ -14,7 +14,13 @@ const Pager = (props) => { } return ( -
  • +
  • {props.page}
  • ); @@ -29,6 +35,7 @@ Pager.propTypes = { showTitle: PropTypes.bool, rootPrefixCls: PropTypes.string, onClick: PropTypes.func, + onKeyPress: PropTypes.func, }; export default Pager; diff --git a/src/Pagination.jsx b/src/Pagination.jsx index 07bc0e87..02f7852c 100644 --- a/src/Pagination.jsx +++ b/src/Pagination.jsx @@ -190,6 +190,12 @@ class Pagination extends React.Component { return this.state.current < this._calcPage(); } + _runIfEnter(event, callback) { + if (event.keyCode === 'Enter') { + callback(); + } + } + render() { const props = this.props; const locale = props.locale; @@ -211,6 +217,8 @@ class Pagination extends React.Component {
  • this._runIfEnter(evt, this._prev)} className={`${this._hasPrev() ? '' : `${prefixCls}-disabled`} ${prefixCls}-prev`} aria-disabled={!this._hasPrev()} > @@ -233,6 +241,8 @@ class Pagination extends React.Component {
  • this._runIfEnter(evt, this._next)} className={`${this._hasNext() ? '' : `${prefixCls}-disabled`} ${prefixCls}-next`} aria-disabled={!this._hasNext()} > @@ -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} @@ -265,6 +276,8 @@ class Pagination extends React.Component { title={props.showTitle ? prevItemTitle : null} key="prev" onClick={this._jumpPrev} + tabIndex="0" + onKeyPress={(evt) => this._runIfEnter(evt, this._jumpPrev)} className={`${prefixCls}-jump-prev`} > @@ -274,7 +287,9 @@ class Pagination extends React.Component {
  • this._runIfEnter(evt, this._jumpNext)} className={`${prefixCls}-jump-next`} > @@ -286,6 +301,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} @@ -297,6 +313,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} @@ -322,6 +339,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} @@ -378,6 +396,8 @@ class Pagination extends React.Component {
  • this._runIfEnter(evt, this._prev)} className={`${!prevDisabled ? '' : `${prefixCls}-disabled`} ${prefixCls}-prev`} aria-disabled={prevDisabled} > @@ -387,6 +407,8 @@ class Pagination extends React.Component {
  • this._runIfEnter(evt, this._next)} className={`${!nextDisabled ? '' : `${prefixCls}-disabled`} ${prefixCls}-next`} aria-disabled={nextDisabled} >