File tree Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments