-
-
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] Implement useControlState hook, and add control state on selectionModel #1823
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.
Changing a controlled prop should directly trigger a render. Instead, it seems to be passive (wait for somebody to re-render to update). If this is true (I could have missed something in the review), then I think that we need to change the approach. found it, we have kept the effect based on the prop.
packages/grid/_modules_/grid/hooks/features/selection/useGridSelection.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/core/useGridState.ts
Outdated
Show resolved
Hide resolved
docs/src/pages/components/data-grid/selection/ControlledSelectionGrid.tsx
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/core/useGridState.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/core/useGridState.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/selection/useGridSelection.ts
Outdated
Show resolved
Hide resolved
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.
We have to manually call setGridState
to update the state when the prop changes. Should we update the hook to also handle this update: prop -> state? I think we're gonna need a mapModelToState
for that to sanitize the values that go to the state (e.g. to unselect invisible rows).
packages/grid/_modules_/grid/hooks/features/core/useGridState.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/core/useGridState.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/selection/useGridSelection.ts
Show resolved
Hide resolved
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
create single issue for the next todos |
@dtassone Could you update the PR to document the breaking changes? We are going to need it for the next release's changelog and for developers landing here. BTW, it has been your turn for the next release for the last 16 days. Are you up for making one Monday? :) |
@dtassone @oliviertassinari It would have been nice to write that the multiple selection (selectionModel as array input) now requires XGrid component in the release notes Edit: Included in build v4.0.0-alpha.34 |
Why is the error for multiple selections a thing? It's not mentioned anywhere in the docs or release notes, and it doesn't even stop multiple selections from working. |
Note that multiple row selections has always been documented under the Pro plan in https://material-ui.com/components/data-grid/selection/#multiple-row-selection. If it was possible to make work in Speaking of surprises, this might be also be one, not sure #1821; |
It was directly documented as being an option in the Controlled Selection example here: https://material-ui.com/components/data-grid/selection/#controlled-selection |
Yeah, with Previously, there was no warning and the validation was done inside the hook. |
Breaking changes
[DataGrid] Implement useControlState hook, and add control state on selectionModel ([DataGrid] Implement useControlState hook, and add control state on selectionModel #1823) @dtassone
Normalize the controlled prop signature:
Replace
onRowSelected
with the existing API:https://deploy-preview-1823--material-ui-x.netlify.app/storybook/?path=/story/x-grid-tests-filter--control-selection
This PR allows integrating the concept of control state, within the grid state management by registering the controlled prop, the on-change handler and the state selector which allows retrieving where the prop model is stored in state.
Below is how you can register the prop
selectionModel
and itsonSelectionModelChange
as a controlled state prop.At this stage, the architecture seems to be working, and performing well.
Breaking Change
- props.onRowSelected
Use
onSelectionChange
.Next
mapStateToModel
enough 🤔