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

[DataGrid] Rework keyboard navigation #3193

Merged
merged 3 commits into from
Nov 19, 2021

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Nov 16, 2021

Goals

Remove abstractions whenever possible to make the code easier to read

  • No key mapping
  • No clamping afterwards, we are doing the checks during the switch
  • Explicit variables viewportPageSize / firstRowIndexInPage / lastRowIndexInPage / firstColIndex / lastColIndex to make the switch statement as clear as possible
  • A single goToCell and goToHeader method to abstract the scroll and focus behaviors

Follow up

On v6 I think we should replace the cellNavigationKeyDown and columnHeaderNavigationKeyDown with apiRef 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".

@flaviendelangle flaviendelangle added core Infrastructure work going on behind the scenes component: data grid This is the name of the generic UI component, not the React module! labels Nov 16, 2021
@flaviendelangle flaviendelangle self-assigned this Nov 16, 2021
Copy link
Member

@m4theushw m4theushw left a 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.

if (colIdx === 0) {
newRowIndex = currentPage.range.firstRowIndex;
const viewportPageSize = apiRef.current.unstable_getViewportPageSize();
const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why the ternary operator?

Copy link
Member Author

@flaviendelangle flaviendelangle Nov 18, 2021

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.

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! core Infrastructure work going on behind the scenes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants