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] Fix Space triggering edit mode #8180

Merged
merged 1 commit into from
Mar 13, 2023

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented Mar 8, 2023

Fixes #8171

Space is not a key that should trigger the edit mode.

@m4theushw m4theushw added the component: data grid This is the name of the generic UI component, not the React module! label Mar 8, 2023
@mui-bot
Copy link

mui-bot commented Mar 8, 2023

Netlify deploy preview

Netlify deploy preview: https://deploy-preview-8180--material-ui-x.netlify.app/

Updated pages

No updates.

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 627.5 1,390.4 642.9 909.5 277.254
Sort 100k rows ms 665.3 1,447 1,447 1,065.36 256.256
Select 100k rows ms 222.1 458 402.3 370.38 88.031
Deselect 100k rows ms 168.1 412.5 249.1 265.64 81.266

Generated by 🚫 dangerJS against 74daf61

Copy link
Member

@MBilalShafi MBilalShafi left a comment

Choose a reason for hiding this comment

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

When pressing space, the focus goes to last row of current or next visual page *, my natural expectation was that Shift + space would do the exact opposite (going to first row or first row of previous visual page) but instead it selects/unselects the row.

Do you think we should review this interaction to make keyboard navigation a bit more easier. 🤔

* By visual page I mean currently visible rows without scrolling

@m4theushw m4theushw merged commit bdbe836 into mui:master Mar 13, 2023
@m4theushw m4theushw deleted the fix-space-triggering-edit-mode branch March 13, 2023 17:47
@m4theushw
Copy link
Member Author

Do you think we should review this interaction to make keyboard navigation a bit more easier. 🤔

I don't know why this Space shortcut exists in the first place. I don't think someone uses it and it could be a candidate for removal in v7.

@shantanutheone
Copy link

How to add space in the text itself while in editing mode? It's currently scrolling.

@laikai0000
Copy link

@m4theushw

How to add space in the text itself while in editing mode? It's currently scrolling.

@MBilalShafi
Copy link
Member

How to add space in the text itself while in editing mode? It's currently scrolling.

It's working for me when in edit mode. Could you attach reproduction steps or a video maybe?

@laikai0000
Copy link

laikai0000 commented Sep 25, 2024 via email

@laikai0000
Copy link

laikai0000 commented Sep 25, 2024 via email

@laikai0000
Copy link

When I select that cell and click the spacebar, it starts scrolling.
How do I fix this?

<DataGridPremium
          apiRef={apiRef}
        /......
       onCellKeyDown={handleOnCellKeyDown}
 />
 
 const handleOnCellKeyDown: DataGridPremiumPropsWithoutDefaultValue["onCellKeyDown"] = async (params, event) => {
  if (event.code === "Space") {
            event.preventDefault();


    }
 }      

@MBilalShafi
Copy link
Member

MBilalShafi commented Sep 26, 2024

Hey @laikai0000,

You could use event.defaultMuiPrevented = "true" to stop the Space key from triggering the scroll.

const handleCellKeyDown = (_, event) => {
  if (event.key === " ") {
    event.defaultMuiPrevented = true;
  }
}

Here's a live example: https://codesandbox.io/p/sandbox/suspicious-payne-qt3wsw

Let me know if it solves your concern.

@laikai0000
Copy link

laikai0000 commented Sep 26, 2024

Hi @MBilalShafi
Thanks for your reply.
But it doesn't seem to solve the problem.
I would like to keep focus and not scroll.

@MBilalShafi
Copy link
Member

@laikai0000 I mistakenly attached a different example previously, sorry about that. I've updated the example, can you check again?

It's both keeping the focus and not scrolling

Focus.mp4

@laikai0000
Copy link

laikai0000 commented Sep 26, 2024

@MBilalShafi
thx
However, if you try to switch to edit mode, scrolling occurs.
How do I fix this?

if (event.key === " ") {
      event.defaultMuiPrevented = true;
           apiRef.current.startCellEditMode({id: rowId, field: field});

    }

@MBilalShafi
Copy link
Member

@laikai0000
Copy link

laikai0000 commented Sep 27, 2024 via email

@MBilalShafi
Copy link
Member

@laikai0000 I won't be able to properly assist you further unless you provide a live reproduction of the issue, kindly fork my codesandbox link, reproduce the problem, and share your updated fork here.

Mentioning the reproduction steps (if there's a particular sequence) would even be better.

I'd also request you to take any further discussion in a new or recent issue, since this issue is quite old.

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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Datagrid scrolls when pressing space bar if editing enabled
5 participants