Skip to content

Commit 3248ad6

Browse files
authored
Merge pull request glittershark#296 from Widen/master
checking for undefined in nextProps so we don't clear out the current page
2 parents aa8554c + 1ed9d85 commit 3248ad6

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

build/reactable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ window.ReactDOM["default"] = window.ReactDOM;
12501250
}, {
12511251
key: 'updateCurrentPage',
12521252
value: function updateCurrentPage(nextPage) {
1253-
if (nextPage !== this.state.currentPage) {
1253+
if (typeof nextPage !== 'undefined' && nextPage !== this.state.currentPage) {
12541254
this.setState({ currentPage: nextPage });
12551255
}
12561256
}

lib/reactable/table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ var Table = (function (_React$Component) {
281281
}, {
282282
key: 'updateCurrentPage',
283283
value: function updateCurrentPage(nextPage) {
284-
if (nextPage !== this.state.currentPage) {
284+
if (typeof nextPage !== 'undefined' && nextPage !== this.state.currentPage) {
285285
this.setState({ currentPage: nextPage });
286286
}
287287
}

src/reactable/table.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export class Table extends React.Component {
240240
}
241241

242242
updateCurrentPage(nextPage) {
243-
if (nextPage !== this.state.currentPage) {
243+
if (typeof(nextPage) !== 'undefined' && nextPage !== this.state.currentPage) {
244244
this.setState({ currentPage: nextPage});
245245
}
246246
}

tests/reactable_test.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,4 +2580,35 @@ describe('Reactable', function() {
25802580
});
25812581
});
25822582
})
2583+
2584+
describe('receive props with no currentPage', () => {
2585+
let parent;
2586+
2587+
before(function () {
2588+
//create a wrapper component so we can update its state and trigger componentWillReceiveProps in the table
2589+
var TestParent = React.createFactory(React.createClass({
2590+
render() {
2591+
return (<Reactable.Table className="table" id="table" ref="table">
2592+
<Reactable.Tr>
2593+
<Reactable.Td column="Name">
2594+
<b>Griffin Smith</b>
2595+
</Reactable.Td>
2596+
</Reactable.Tr>
2597+
</Reactable.Table>);
2598+
}
2599+
}));
2600+
2601+
parent = ReactDOM.render(TestParent(), ReactableTestUtils.testNode());
2602+
});
2603+
2604+
after(ReactableTestUtils.resetTestEnvironment);
2605+
2606+
it('keeps the same currentPage and does not set it to undefined', function() {
2607+
const preUpdateCurrentPage = parent.refs.table.state.currentPage;
2608+
parent.setState({testState: "this state update will trigger componentWillReceiveProps in the Reactable.Table"});
2609+
const postUpdateCurrentPage = parent.refs.table.state.currentPage;
2610+
expect(postUpdateCurrentPage).to.not.eq(undefined);
2611+
expect(postUpdateCurrentPage).to.eq(preUpdateCurrentPage);
2612+
});
2613+
});
25832614
});

0 commit comments

Comments
 (0)