Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TableBody] Why componentWillReceiveProps set only the last item selected when I deselect an item? #3980

Closed
akosk opened this issue Apr 14, 2016 · 5 comments
Labels
component: table This is the name of the generic UI component, not the React module! v0.x

Comments

@akosk
Copy link

akosk commented Apr 14, 2016

The issue:

  1. I click on select all checkbox in the header of the table -> all items selected.
  2. I deselect a random item.
  3. All the items deselected in the table except the last one.

I found the following code in table-body.js / componentWillReceiveProps:

if (this.props.allRowsSelected && !nextProps.allRowsSelected) {
      newState.selectedRows = this.state.selectedRows.length > 0 ? [this.state.selectedRows[this.state.selectedRows.length - 1]] : [];
} else {
     newState.selectedRows = this._calculatePreselectedRows(nextProps);
}

What is the purpose of [this.state.selectedRows[this.state.selectedRows.length - 1]]?
Why should deselect all items but the last one when select all was checked before?
If I remove the true branch it works as expected: the clicked item and the select all checkbox in header becomes unchecked.

Versions

Material-UI: 0.15.0-alpha2 & 0.14.4
React: 0.14.8
Browser: Chrome (49.0.2623.112 m)

@akosk akosk changed the title [TableBody] Why componentWillReceiveProps set last item selected when I deselect an item? [TableBody] Why componentWillReceiveProps set only the last item selected when I deselect an item? Apr 14, 2016
@nathanmarks
Copy link
Member

@akosk how are you using 0.15.0-alpha2 and 0.14.4 with React 15? They aren't compatible.

@akosk
Copy link
Author

akosk commented Apr 15, 2016

@nathanmarks I use React 0.14.8, I corrected the version number. Sorry for my mistake.

@alan-kleiman-ingressorapido

Repeating @akosk's question, is there a reason for [this.state.selectedRows[this.state.selectedRows.length - 1]]? Would you guys accept a PR that removes it?

@ghost
Copy link

ghost commented Jul 28, 2016

+1

@aahan96
Copy link
Contributor

aahan96 commented Aug 16, 2016

@akosk: @nathanmarks is working on the 0.16.0 release, which will address many issues with the table component. Have a look at issue #2251. I think we can close this issue for now as it's being addressed in the new release

@aahan96 aahan96 closed this as completed Aug 16, 2016
@oliviertassinari oliviertassinari added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 21, 2022
@zannager zannager added component: table This is the name of the generic UI component, not the React module! v0.x and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: table This is the name of the generic UI component, not the React module! v0.x
Projects
None yet
Development

No branches or pull requests

6 participants