-
-
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
[data grid] Check focus validity whenever the rows in state changes #4683
[data grid] Check focus validity whenever the rows in state changes #4683
Conversation
817684b
to
c623f3c
Compare
These are the results for the performance tests:
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
packages/grid/x-data-grid/src/hooks/features/focus/useGridFocus.ts
Outdated
Show resolved
Hide resolved
if (cell && !apiRef.current.getRow(cell.id)) { | ||
apiRef.current.setState((state) => ({ | ||
...state, | ||
focus: { cell: null, columnHeader: null }, |
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.
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
.
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.
Yes, in v6 we could pass the id instead of the params to allow to publish the focus out event on a destroyed cell.
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 withapiRef.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
fromuseGridDimensions
typingThat way only
useGridRows
accesses directlyprops.rows
, all other hooks should use the state.