Skip to content

Commit

Permalink
fix(pagination): set focus only for explicitly clicked pages
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Jul 11, 2018
1 parent 9a025c7 commit 9c656f2
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Pagination/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Pagination extends React.Component {

this.state = {
currentPage: this.props.currentPage,
previousNextButtonClicked: false,
pageButtonSelected: false,
};
}

Expand All @@ -39,19 +39,24 @@ class Pagination extends React.Component {
}

componentDidUpdate() {
const { currentPage, previousNextButtonClicked } = this.state;
const { currentPage, pageButtonSelected } = this.state;
const currentPageRef = this.pageRefs[currentPage];

if (currentPageRef && !previousNextButtonClicked) {
if (currentPageRef && pageButtonSelected) {
currentPageRef.focus();
this.setPageButtonSelectedState(false);
}
}

setPageButtonSelectedState(value) {
this.setState({ pageButtonSelected: value });
}

handlePageSelect(page) {
if (page !== this.state.currentPage) {
this.setState({
currentPage: page,
previousNextButtonClicked: false,
pageButtonSelected: true,
});
this.props.onPageSelect(page);
}
Expand All @@ -60,17 +65,12 @@ class Pagination extends React.Component {
handlePreviousNextButtonClick(page) {
const { pageCount } = this.props;

this.setState({
currentPage: page,
previousNextButtonClicked: true,
});

if (page === 1) {
this.nextButtonRef.focus();
} else if (page === pageCount) {
this.previousButtonRef.focus();
}

this.setState({ currentPage: page });
this.props.onPageSelect(page);
}

Expand Down

0 comments on commit 9c656f2

Please sign in to comment.