Skip to content

Commit

Permalink
Fix for Copy&Paste events not working properly in non-English keyboar…
Browse files Browse the repository at this point in the history
…d event (#2097)

* Update DataGrid.tsx

* Update DataGrid.tsx

* Update DataGrid.tsx

* Update DataGrid.tsx

Co-authored-by: Nicolas Stepien <[email protected]>
  • Loading branch information
Yaron24 and nstepien authored Oct 21, 2020
1 parent 0ce660f commit 132ebb6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function DataGrid<R, K extends keyof R, SR>({
* event handlers
*/
function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
const { key } = event;
const { key, keyCode } = event;
const row = rows[selectedPosition.rowIdx];

if (
Expand All @@ -393,13 +393,15 @@ function DataGrid<R, K extends keyof R, SR>({
&& !isGroupRow(row)
&& selectedPosition.idx !== -1
) {
// key may be uppercase `C` or `V`
const lowerCaseKey = key.toLowerCase();
if (lowerCaseKey === 'c') {
// event.key may differ by keyboard input language, so we use event.keyCode instead
// event.nativeEvent.code cannot be used either as it would break copy/paste for the DVORAK layout
const cKey = 67;
const vKey = 86;
if (keyCode === cKey) {
handleCopy();
return;
}
if (lowerCaseKey === 'v') {
if (keyCode === vKey) {
handlePaste();
return;
}
Expand Down

0 comments on commit 132ebb6

Please sign in to comment.