From 47bd7f679e87ae507218fb3aaaba46d648378305 Mon Sep 17 00:00:00 2001 From: AlexKVal Date: Tue, 4 Aug 2015 21:39:57 +0300 Subject: [PATCH] [fixed] disabled pagination buttons should not fire 'onSelect' --- src/PaginationButton.js | 4 ++++ test/PaginationSpec.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/PaginationButton.js b/src/PaginationButton.js index df1f2054f2..917ad79fdc 100644 --- a/src/PaginationButton.js +++ b/src/PaginationButton.js @@ -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); diff --git a/test/PaginationSpec.js b/test/PaginationSpec.js index 9666a54cc5..1dcf72b873 100644 --- a/test/PaginationSpec.js +++ b/test/PaginationSpec.js @@ -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( + + ); + 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 ); + }); });