Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Fixed error when using chrome autofill #1578

Merged
merged 3 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react-shortcuts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -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),
gmcgibbon marked this conversation as resolved.
Show resolved Hide resolved
);
}

return hasKeyGroups(heldKeys)
Expand Down
16 changes: 16 additions & 0 deletions packages/react-shortcuts/src/tests/ShortcutManager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<ShortcutProvider>
<Shortcut held={heldToCheck} ordered={['/']} onMatch={matchSpy} />
</ShortcutProvider>,
);

document.dispatchEvent(new UIEvent('keydown'));

expect(matchSpy).not.toHaveBeenCalled();
});
});
});

Expand Down