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

[Table] wrapped table with onSelection listener doesn't allow select-all #1233

Open
seansfkelley opened this issue Jun 14, 2017 · 2 comments

Comments

@seansfkelley
Copy link

seansfkelley commented Jun 14, 2017

Bug report

  • Package version(s): core: 1.17.1, table: 1.17.0
  • Browser and OS versions: Chrome 58.0.3029.110, OS X 10.12.5

Steps to reproduce

Using this table-containing component:

interface State {
    selection: IRegion[];
}

export class BuggyTable extends React.PureComponent<{}, State> {
    public state: State = {
        selection: [],
    };

    public render() {
        return (
            <Table
                numRows={1}
                selectionModes={SelectionModes.ALL}
                onSelection={this.updateSelection}
            >
                <Column
                    name="foo"
                    renderCell={(rowIndex) => <Cell>bar</Cell>}
                />
            </Table>
        );
    }

    private updateSelection = (selection: IRegion[]) => {
        this.setState({ selection });
    };
}
  1. Click on the top-left-most header cell (the "select all" cell).

Actual behavior

  1. Selection does not change from it's current state.

Expected behavior

  1. Selection is set to "all cells".

Commenting out the this.setState line causes selection to behave as expected again. Wrapping this.setState in a zero-duration setTimeout also causes selection to behave as expected. Looks like some kind of synchronicity/deferral issue?

Confusingly, all other types of selection work (entire-row, entire-column, single-cell, multiple-cell).

@cmslewis
Copy link
Contributor

Oh this sounds interesting. Will dig in this week. 👍

@cmslewis cmslewis changed the title table: wrapped table with onSelection listener doesn't allow select-all [Table] wrapped table with onSelection listener doesn't allow select-all Jun 14, 2017
@tgreenwatts tgreenwatts added this to Bugs in Table Jun 26, 2017
@tgreenwatts tgreenwatts moved this from Bugs to Editable tables in Table Jun 26, 2017
@cmslewis
Copy link
Contributor

cmslewis commented Oct 2, 2017

Man, I'm just not seeing what's going on with this one. For some reason, when selectAll() invokes Table.handleSelection (a private helper), the state is not updated before componentWillReceiveProps is invoked.

Fortunately, passing the selectedRegions back into Table in a controlled fashion fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Table
Editable tables
Development

No branches or pull requests

3 participants