Skip to content

Commit

Permalink
[fixed] disabled pagination buttons should not fire 'onSelect'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKVal committed Aug 4, 2015
1 parent 9403a81 commit 47bd7f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/PaginationButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const PaginationButton = React.createClass({
},

handleClick(event) {
if (this.props.disabled) {
return;
}

if (this.props.onSelect) {
let selectedEvent = createSelectedEvent(this.props.eventKey);
this.props.onSelect(event, selectedEvent);
Expand Down
29 changes: 29 additions & 0 deletions test/PaginationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,33 @@ describe('Pagination', function () {
ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'div')[2]
);
});

it('should not fire "onSelect" event on disabled buttons', function () {
function onSelect() {
throw Error('this event should not happen');
}

const instance = ReactTestUtils.renderIntoDocument(
<Pagination
onSelect={onSelect}
last
next
ellipsis
maxButtons={1}
activePage={1}
items={0} />
);
const liElements = ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'li');

// buttons are disabled
assert.include(React.findDOMNode(liElements[0]).className, 'disabled');
assert.include(React.findDOMNode(liElements[1]).className, 'disabled');

const pageButtons = ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'a');
const nextButton = pageButtons[0];
const lastButton = pageButtons[1];

ReactTestUtils.Simulate.click( nextButton );
ReactTestUtils.Simulate.click( lastButton );
});
});

0 comments on commit 47bd7f6

Please sign in to comment.