[DataGrid] ALT+C
keyboard shortcut doesn't work
#3658
Labels
bug 🐛
Something doesn't work
component: data grid
This is the name of the generic UI component, not the React module!
Current behavior 😯
Alt+C
(Option+C
) on selected rows does nothing (at least on MacOS).Expected behavior 🤔
Alt+C
(Option+C
) should copy currently selected rows with headers (as per https://mui.com/components/data-grid/accessibility/#selection)Steps to reproduce 🕹
Steps:
Alt+C
(Option+C
)Context 🔦
The problem
On Mac,
Option
is a modifier key that allows to type modified letters (e.g. letters with accent) depending on keyboards layout.For example, on British keyboard layout
Option+c
would printç
, and on Ukrainian layout -≠
.This is how
Alt+C
shortcut is handled:https://github.com/mui-org/material-ui-x/blob/85c16c1d240fc5741bdc1fd8bf2325dfe6d59793/packages/grid/_modules_/grid/hooks/features/clipboard/useGridClipboard.ts#L57-L60
In this case,
event.key.toLowerCase()
returnsç
, notc
and condition won't pass.Proposed solution
For this specific case I would propose to use
event.code
.It represents a physical key rather than an actual letter, so
event.code
would have a valueKeyC
.You can use https://w3c.github.io/uievents/tools/key-event-viewer.html for experiments.
It's not ideal though, because:
So the solution would be to check
event.code
in addition toevent.key
:I'm pretty sure this problem doesn't exist on Windows, because left ALT doesn't alter the letter pressed.
Would love to get some feedback on this, especially from people using different keyboard layouts and operating system.
Your environment 🌎
`npx @mui/envinfo`
Order ID 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: