fix search dialog opening multiple times via the keybind

Took 5 minutes
This commit is contained in:
Braydon 2024-10-07 12:01:38 -04:00
parent 83ea83bd18
commit fe56169874
2 changed files with 6 additions and 1 deletions

View File

@ -30,7 +30,7 @@ const Navbar = (): ReactElement => {
<div className="flex gap-5 sm:gap-7 items-center transition-all transform-gpu">
{/* Search */}
<div className="hidden xs:flex">
<QuickSearchDialog pages={pages} />
<QuickSearchDialog pages={pages} bindKeybind />
</div>
{/* Social */}

View File

@ -21,14 +21,19 @@ import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.share
*/
const QuickSearchDialog = ({
pages,
bindKeybind = false,
}: {
pages: DocsContentMetadata[];
bindKeybind?: boolean;
}): ReactElement => {
const [open, setOpen] = useState<boolean>(false);
const router: AppRouterInstance = useRouter();
// Listen for CTRL + K keybinds to open this dialog
useEffect(() => {
if (!bindKeybind) {
return;
}
const handleKeyDown = (event: KeyboardEvent): void => {
if ((event.ctrlKey || event.metaKey) && event.key === "k") {
event.preventDefault();