Skip to content

Commit

Permalink
improve keyboard accessibility when the input is not focused
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Dec 7, 2024
1 parent 39ff32b commit 3f20b0c
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ const DesktopCommand = forwardRef<HTMLDivElement, DesktopCommandProps & Componen
return;
}

// if input is alphanumeric, focus input
// if input is alphanumeric, space, backspace, delete, arrow left, arrow right, then focus input
// note: this func is onKeyDownCapture so it will fire before the input
// which is important so that the first character typed isn't swallowed
if (/^[a-zA-Z0-9]$/.test(e.key)) {
if (
/^[a-zA-Z0-9]$/.test(e.key) ||
e.key === " " ||
e.key === "Backspace" ||
e.key === "Delete" ||
e.key === "ArrowLeft" ||
e.key === "ArrowRight"
) {
// focus input _immediately_:
inputRef.current?.focus();
// scrollToTop();c
Expand Down

0 comments on commit 3f20b0c

Please sign in to comment.