Skip to content

Commit

Permalink
fix(playground): slash key would open search box
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA committed Dec 12, 2024
1 parent 8c4d1e1 commit 684c2d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions client/src/search-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ export function useFocusViaKeyboard(
useEffect(() => {
function focusOnSearchMaybe(event: KeyboardEvent) {
const input = inputRef.current;
const target = event.target as HTMLElement;
const target = event.composedPath()?.[0] || event.target;
const keyPressed = event.key;
const ctrlOrMetaPressed = event.ctrlKey || event.metaKey;
const isSlash = keyPressed === "/" && !ctrlOrMetaPressed;
const isCtrlK =
keyPressed === "k" && ctrlOrMetaPressed && !event.shiftKey;
const isTextField =
["TEXTAREA", "INPUT"].includes(target.tagName) ||
target.isContentEditable;
target instanceof HTMLElement &&
(["TEXTAREA", "INPUT"].includes(target.tagName) ||
target.isContentEditable);
if ((isSlash || isCtrlK) && !isTextField) {
if (input && document.activeElement !== input) {
event.preventDefault();
Expand Down

0 comments on commit 684c2d6

Please sign in to comment.