tleunen / react-mdl

React Components for Material Design Lite
https://tleunen.github.io/react-mdl/
MIT License
1.76k stars 255 forks source link

Selectable Table sets headerSelected even with zero rows #443

Open mikol-styra opened 7 years ago

mikol-styra commented 7 years ago

When headerSelected is computed in Selectable.prototype.componentWillReceiveProps(), the computation doesn’t factor in selectedRows (or rrows) with 0 length. This means that if, for example, I select all of the rows in a table and delete them, then the header checkbox will remain checked even though there are no rows selected (and none to be selected).

The code in componentWillReceiveProps() is currently:

                    this.setState({
                        headerSelected: selectedRows.length === rrows.length,
                        selectedRows
                    });

It probably should be something like:

                    const n = selectedRows.length;
                    this.setState({
                        headerSelected: n > 0 && n === rrows.length,
                        selectedRows
                    });

For tables with no rows, it probably also makes sense to disable the header checkbox since “select all” with an empty table isn’t really possible (at least it doesn’t mean much in practice).