fix search dialog opening multiple times via the keybind
Took 5 minutes
This commit is contained in:
parent
83ea83bd18
commit
fe56169874
@ -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 */}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user