Skip to content

Commit

Permalink
Don't ignore keyboard events when the target is a Button or a Select (c…
Browse files Browse the repository at this point in the history
…ruise-automation#415)

* Don't ignore keyboard events when the target is a Button or a Select

Previously we'd ignore events if their target was a Button or a Select, but this breaks keyboard shortcuts once a Button has been focused. In order to keep keyboard shortcuts working all the time, we now allow events targeted at Button and Select elements.

* Bump version to 1.0.7

Co-authored-by: Chris Hasson <[email protected]>
  • Loading branch information
hassoncs and hassoncs authored May 5, 2020
1 parent feb4854 commit 73ff175
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/@cruise-automation/button/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cruise-automation/button",
"version": "0.0.7",
"version": "1.0.7",
"main": "lib/index.js",
"description": "Cruise button",
"license": "Apache-2.0",
Expand Down
12 changes: 4 additions & 8 deletions packages/react-key-listener/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,11 @@ export default class KeyListener extends React.Component<Props> {
handleEvent = (event: KeyboardEvent) => {
const { target, type } = event;
if (
// escape key should still work when a button is focused
event.key !== "Escape" &&
(target instanceof HTMLButtonElement ||
target instanceof HTMLInputElement ||
target instanceof HTMLSelectElement ||
target instanceof HTMLTextAreaElement ||
(target instanceof HTMLElement && target.isContentEditable))
target instanceof HTMLInputElement ||
target instanceof HTMLTextAreaElement ||
(target instanceof HTMLElement && target.isContentEditable)
) {
// the user is typing in an editable field; ignore the event.
// The user is typing in an editable field; ignore the event.
return;
}

Expand Down

0 comments on commit 73ff175

Please sign in to comment.