"use client"; import { useEffect } from "react"; // `/` focuses the page's search box (canvas Work: "Find a piece /"), unless // something is being typed in already. Renders nothing. export default function SlashFocus({ target }: { target: string }) { useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key !== "/" || e.metaKey || e.ctrlKey || e.altKey) return; const t = e.target as HTMLElement | null; if (t?.closest?.("input, textarea, select, [contenteditable=''], [contenteditable='true']")) return; const el = document.querySelector(target); if (!el) return; e.preventDefault(); el.focus(); el.select(); }; document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [target]); return null; }