diff --git a/src/components/CommandMenu/CommandMenu.tsx b/src/components/CommandMenu/CommandMenu.tsx index 4d4895578..220bfb439 100644 --- a/src/components/CommandMenu/CommandMenu.tsx +++ b/src/components/CommandMenu/CommandMenu.tsx @@ -8,6 +8,7 @@ import VideoIcon from '../../icons/video.svg'; import { httpGet } from '../../lib/http'; import { useKeydown } from '../../hooks/use-keydown'; import { isLoggedIn } from '../../lib/jwt'; +import { useOutsideClick } from '../../hooks/use-outside-click'; type PageType = { url: string; @@ -45,6 +46,7 @@ function shouldShowPage(page: PageType) { export function CommandMenu() { const inputRef = useRef(null); + const modalRef = useRef(null); const [isActive, setIsActive] = useState(false); const [allPages, setAllPages] = useState([]); const [searchResults, setSearchResults] = useState(defaultPages); @@ -55,6 +57,10 @@ export function CommandMenu() { setIsActive(true); }); + useOutsideClick(modalRef, () => { + setIsActive(false); + }); + useEffect(() => { if (!isActive || !inputRef.current) { return; @@ -105,7 +111,7 @@ export function CommandMenu() { return (
-
+
{page.group} )} {page.icon && ( - + )} {page.title} diff --git a/src/hooks/use-outside-click.ts b/src/hooks/use-outside-click.ts index f22b0130e..02b5d88d2 100644 --- a/src/hooks/use-outside-click.ts +++ b/src/hooks/use-outside-click.ts @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'preact/hooks'; +import { useEffect } from 'preact/hooks'; export function useOutsideClick(ref: any, callback: any) { useEffect(() => { diff --git a/src/pages/pages.json.ts b/src/pages/pages.json.ts index 523d1f8e1..40e7f8a00 100644 --- a/src/pages/pages.json.ts +++ b/src/pages/pages.json.ts @@ -22,12 +22,12 @@ export async function get() { group: 'Best Practices', })), ...guides.map((guide) => ({ - url: `/${guide.id}`, + url: `/guides/${guide.id}`, title: guide.frontmatter.title, group: 'Guides', })), ...videos.map((guide) => ({ - url: `/${guide.id}`, + url: `/videos/${guide.id}`, title: guide.frontmatter.title, group: 'Videos', })),