Skip to content

Commit

Permalink
Use keydown for all keyboard events
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed May 12, 2023
1 parent 920a67a commit 6bcb9a8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions srcts/src/components/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Card {
this.exitFullScreen()
);

document.addEventListener("keyup", this._exitFullScreenOnEscape, false);
document.addEventListener("keydown", this._exitFullScreenOnEscape, false);

// trap focus in the fullscreen container, listening for Tab key on the
// capture phase so we have a better chance of preventing other handlers
Expand All @@ -96,7 +96,11 @@ class Card {
this.exitFullScreen()
);

document.removeEventListener("keyup", this._exitFullScreenOnEscape, false);
document.removeEventListener(
"keydown",
this._exitFullScreenOnEscape,
false
);
document.removeEventListener("keydown", this._trapFocusExit, true);

// Remove overlay and remove full screen classes from card
Expand Down Expand Up @@ -218,7 +222,7 @@ class Card {
anchor.classList.add(Card.attr.CLASS_FULL_SCREEN_EXIT);
anchor.tabIndex = 0;
anchor.onclick = () => this.exitFullScreen();
anchor.onkeyup = (ev) => {
anchor.onkeydown = (ev) => {
if (ev.key === "Enter" || ev.key === " ") {
this.exitFullScreen();
}
Expand Down

0 comments on commit 6bcb9a8

Please sign in to comment.