-
-
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] Rework keyboard navigation #3193
[DataGrid] Rework keyboard navigation #3193
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.
Much more simple to understand. 👍
On v6 I think we should replace the cellNavigationKeyDown and columnHeaderNavigationKeyDown with apiRef methods.
Yeah, it's weird to have a keyboard event that is published only when a specific set of keys are pressed but even when these keys are pressed it's ignored, e.g. on cell editing. This is one reason I made it private in #1572. I think cellKeyDown
should be used for everything.
packages/grid/_modules_/grid/hooks/features/keyboard/useGridKeyboardNavigation.ts
Outdated
Show resolved
Hide resolved
if (colIdx === 0) { | ||
newRowIndex = currentPage.range.firstRowIndex; | ||
const viewportPageSize = apiRef.current.unstable_getViewportPageSize(); | ||
const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0; |
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.
Why the ternary operator?
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.
Because there is one case where this event is triggered after comiting a row edit and we don't have a field.
It was working because getColumnIndex
returned -1
and the clamp behavior set it back to 0, but it's not great calling it that way.
I was one of the inconsistencies I found while typing the event system.
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.
Makes sense. The event below shouldn't be published.
Goals
Remove abstractions whenever possible to make the code easier to read
viewportPageSize
/firstRowIndexInPage
/lastRowIndexInPage
/firstColIndex
/lastColIndex
to make the switch statement as clear as possiblegoToCell
andgoToHeader
method to abstract the scroll and focus behaviorsFollow up
On v6 I think we should replace the
cellNavigationKeyDown
andcolumnHeaderNavigationKeyDown
withapiRef
methods.For me events should be "hey I did X, do whatever you want with this information" not "hey, could someone listen to me and do X".