From f914784c9a8f571d932c1ad35cd6044ed26e01c4 Mon Sep 17 00:00:00 2001 From: bhavathi Date: Sat, 1 Aug 2020 11:46:29 +0530 Subject: [PATCH 1/2] Fixed error when using chrome autofill --- .../react-shortcuts/src/ShortcutManager/ShortcutManager.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-shortcuts/src/ShortcutManager/ShortcutManager.tsx b/packages/react-shortcuts/src/ShortcutManager/ShortcutManager.tsx index b873be7a87..d767ec7a74 100644 --- a/packages/react-shortcuts/src/ShortcutManager/ShortcutManager.tsx +++ b/packages/react-shortcuts/src/ShortcutManager/ShortcutManager.tsx @@ -67,7 +67,10 @@ export default class ShortcutManager { } function keyGroupIsHeld(keyGroup: ModifierKey[]) { - return keyGroup.every((key: ModifierKey) => event.getModifierState(key)); + return keyGroup.every( + (key: ModifierKey) => + event.getModifierState && event.getModifierState(key), + ); } return hasKeyGroups(heldKeys) From 7ea896ef4b879d2109851138e57d5b01613e1d9c Mon Sep 17 00:00:00 2001 From: bhavathi Date: Wed, 7 Oct 2020 20:06:41 +0530 Subject: [PATCH 2/2] Added test case and change log --- packages/react-shortcuts/CHANGELOG.md | 4 ++++ .../src/tests/ShortcutManager.test.tsx | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/react-shortcuts/CHANGELOG.md b/packages/react-shortcuts/CHANGELOG.md index dc9021437f..e371a267fc 100644 --- a/packages/react-shortcuts/CHANGELOG.md +++ b/packages/react-shortcuts/CHANGELOG.md @@ -16,3 +16,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ### Added - This CHANGELOG [(#508)](https://github.com/Shopify/quilt/pull/508) + +### Fixed + +- Added a check for event.getModifierState method before calling it. ([#1578](https://github.com/Shopify/quilt/pull/1578)) diff --git a/packages/react-shortcuts/src/tests/ShortcutManager.test.tsx b/packages/react-shortcuts/src/tests/ShortcutManager.test.tsx index 6f97a612cc..3fd6ca439a 100644 --- a/packages/react-shortcuts/src/tests/ShortcutManager.test.tsx +++ b/packages/react-shortcuts/src/tests/ShortcutManager.test.tsx @@ -297,6 +297,22 @@ describe('ShortcutManager', () => { expect(fooSpy).not.toHaveBeenCalled(); }); + + it('doesn’t fire on non-keyboard events', () => { + const matchSpy = jest.fn(); + const heldGroup: ModifierKey[] = ['Control', 'Shift']; + const heldToCheck: HeldKey = [[...heldGroup], ['Alt', 'Meta']]; + + mount( + + + , + ); + + document.dispatchEvent(new UIEvent('keydown')); + + expect(matchSpy).not.toHaveBeenCalled(); + }); }); });