-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Emit onSelectionModelChange
when selection state changes
#1966
[DataGrid] Emit onSelectionModelChange
when selection state changes
#1966
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for this behavior, it also fixes the uncontrolled behavior.
Co-authored-by: Olivier Tassinari <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Co-authored-by: Olivier Tassinari <[email protected]>
not sure how this fix is going to fit with my control state PR, it seems redundant, and we will have to clean these changes |
@dtassone It's not a fix per se but rather a missed interaction that should emit the |
Well if that is the case then why is the linked ticket assigned to me, we are essentially doing double work here... |
The PR looks solid, I would personally 👍 for a merge: to encourage moving one step at a time. The rebase in #1823 will likely be easy, and if the logic is correct, the test will still pass. If the test doesn't pass it should likely be #1823 responsibility to fix it. I would actually hope that an extra constraint from here will help #1823 tailor the solution to reality. |
@oliviertassinari @dtassone Ok, I applied the test to the control state PR #1823. This is what the test should look like taking into account the changes in the linked PR. The only part that is failing is the part of clearing the selection after loading rows with different IDs. it('should call onSelectionModelChange when selection state changes', () => {
const handleSelectionModelChange = spy();
const { setProps } = render(
<div style={{ width: 300, height: 300 }}>
<XGrid
columns={[{ field: 'brand' }]}
rows={[
{
id: 0,
brand: 'Nike',
},
]}
selectionModel={[0]}
onSelectionModelChange={handleSelectionModelChange} />
</div>
);
expect(getSelectedRows(apiRef)).to.deep.equal([0]);
setProps({
rows: [
{
id: 1,
brand: 'Nike',
},
],
});
expect(handleSelectionModelChange.callCount).to.equal(1);
expect(handleSelectionModelChange.getCall(0).args[0]).to.deep.equal([]);
// TODO: Fix - it should clear the selection because the newly loaded rows have different IDs
expect(getSelectedRows(apiRef)).to.deep.equal([]);
}); I can either push this directly to the control state PR or @dtassone you can add it manually. |
IMO we could merge #1823 and then reapply/fix this issue on top of it |
Great 👍 |
Fixes #1782