Skip to content

Commit

Permalink
[TableBody] Fix row selection re-render
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jan 10, 2017
1 parent 653edea commit 6b3ca64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Table/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ class TableBody extends Component {
}

componentWillReceiveProps(nextProps) {
if (this.props.allRowsSelected && !nextProps.allRowsSelected) {
this.setState({
selectedRows: [],
});
// TODO: should else be conditional, not run any time props other than allRowsSelected change?
} else {
this.setState({
selectedRows: this.calculatePreselectedRows(nextProps),
});
if (this.props.allRowsSelected !== nextProps.allRowsSelected) {
if (!nextProps.allRowsSelected) {
this.setState({
selectedRows: [],
});
} else {
this.setState({
selectedRows: this.calculatePreselectedRows(nextProps),
});
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions test/integration/Table/MultiSelectTable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,17 @@ describe('<MultiSelectTable />', () => {
],
'should uncheck all the checkboxes'
);

wrapper.update();
assert.deepEqual(
wrapper.find('Checkbox').map((checkbox) => checkbox.props().checked),
[
false,
false,
false,
false,
],
'should be invariant to update'
);
});
});

1 comment on commit 6b3ca64

@ricardo-cantu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change broke the ability to programmatically select and deselect rows after first render.

Please sign in to comment.