Skip to content

Commit

Permalink
replace rest of event.keyCode usages by event.code (#3136)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina authored May 27, 2023
1 parent 431b7fe commit 7bf9092
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-chairs-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphiql/react': patch
---

replace rest of `event.keyCode` usages by `event.code`
8 changes: 4 additions & 4 deletions packages/graphiql-react/src/editor/header-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ export function useHeaderEditor(
});

newEditor.on('keyup', (editorInstance, event) => {
const { keyCode, key, shiftKey } = event;
const isLetter = keyCode >= 65 && keyCode <= 90;
const isNumber = keyCode >= 48 && keyCode <= 57;
if (isLetter || (!shiftKey && isNumber) || key === '_' || key === '"') {
const { code, key, shiftKey } = event;
const isLetter = code.startsWith('Key');
const isNumber = !shiftKey && code.startsWith('Digit');
if (isLetter || isNumber || key === '_' || key === '"') {
editorInstance.execCommand('autocomplete');
}
});
Expand Down
8 changes: 4 additions & 4 deletions packages/graphiql-react/src/editor/variable-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ export function useVariableEditor(
});

newEditor.on('keyup', (editorInstance, event) => {
const { keyCode, key, shiftKey } = event;
const isLetter = keyCode >= 65 && keyCode <= 90;
const isNumber = keyCode >= 48 && keyCode <= 57;
if (isLetter || (!shiftKey && isNumber) || key === '_' || key === '"') {
const { code, key, shiftKey } = event;
const isLetter = code.startsWith('Key');
const isNumber = !shiftKey && code.startsWith('Digit');
if (isLetter || isNumber || key === '_' || key === '"') {
editorInstance.execCommand('autocomplete');
}
});
Expand Down

0 comments on commit 7bf9092

Please sign in to comment.