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

[data grid] Check focus validity whenever the rows in state changes #4683

Merged
merged 4 commits into from
May 2, 2022

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Apr 28, 2022

Fixes #4678

Before this PR, we where listening to props.rows changes to check the focus validity.
Now I listen to GridEvents.rowsChange to also track changes with apiRef.current.updateRows or grouping changes.

I don't think we need to listen to sortedRowChange and pagination change. If the focus is on a non-visible row, it does not causes any crash.


I also removed unused unused props.rows from useGridDimensions typing
That way only useGridRows accesses directly props.rows, all other hooks should use the state.

@flaviendelangle flaviendelangle added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! plan: Premium Impact at least one Premium user feature: Row grouping Related to the data grid Row grouping feature labels Apr 28, 2022
@mui-bot
Copy link

mui-bot commented Apr 28, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 274.2 617.3 333.7 418.8 140.353
Sort 100k rows ms 538.5 1,000.1 562.1 760.58 182.938
Select 100k rows ms 119.1 203.3 202 185.44 33.189
Deselect 100k rows ms 103.6 212.5 182.9 168.36 39.044

Generated by 🚫 dangerJS against 9070a1f

@flaviendelangle flaviendelangle changed the title [data grid] Check focus validity whenever the rows changes [data grid] Check focus validity whenever the rows in state changes Apr 28, 2022
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 29, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 29, 2022
if (cell && !apiRef.current.getRow(cell.id)) {
apiRef.current.setState((state) => ({
...state,
focus: { cell: null, columnHeader: null },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, every time a cell loses focus it should publish cellFocusOut, but to publish it we call getCellParams which will crash because the row doesn't exist. It will be a bug if the removed row was also being edited. If we want to implement the option 3 from #4516 (comment) we will likely have to revisit this part. Maybe we change the params passed to cellFocusOut to not include the row object. Anyway, until someone complains about cellFocusOut not published we can keep the listener to rowsSet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in v6 we could pass the id instead of the params to allow to publish the focus out event on a destroyed cell.

@flaviendelangle flaviendelangle merged commit 5695e20 into mui:master May 2, 2022
@flaviendelangle flaviendelangle deleted the focus-row-grouping branch May 2, 2022 07:28
alexfauquette pushed a commit to alexfauquette/mui-x that referenced this pull request Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Row grouping Related to the data grid Row grouping feature plan: Premium Impact at least one Premium user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data grid] Focus is not reset when the rows changes due to a change in row grouping model
3 participants