Skip to content

Commit 4b80d22

Browse files
committed
close drawer on command action
1 parent c56935a commit 4b80d22

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

www/src/components/mobile-nav.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import React from "react";
34
import Link from "next/link";
45
import type { PageTree } from "fumadocs-core/server";
56
import { AlignLeftIcon, PanelLeftCloseIcon, SearchIcon } from "lucide-react";
@@ -21,6 +22,7 @@ export const MobileNav = ({
2122
className?: string;
2223
items: PageTree.Node[];
2324
}) => {
25+
const [isOpen, setOpen] = React.useState(false);
2426
return (
2527
<header
2628
className={cn(
@@ -29,7 +31,7 @@ export const MobileNav = ({
2931
)}
3032
>
3133
<div className="max-w-(--breakpoint-2xl) container flex h-14 w-full items-center justify-between">
32-
<DialogRoot>
34+
<DialogRoot isOpen={isOpen} onOpenChange={setOpen}>
3335
<Button variant="quiet" size="sm" shape="square">
3436
<AlignLeftIcon />
3537
</Button>
@@ -65,7 +67,11 @@ export const MobileNav = ({
6567
</Button>
6668
</div>
6769
<div className="p-2">
68-
<SearchCommand>
70+
<SearchCommand
71+
onAction={() => {
72+
setOpen(false);
73+
}}
74+
>
6975
<Button
7076
prefix={<SearchIcon />}
7177
variant="outline"

www/src/components/search-command.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ import { searchConfig } from "@/config";
2323
interface SearchCommandProps {
2424
keyboardShortcut?: boolean;
2525
children: React.ReactNode;
26+
onAction?: () => void;
2627
}
2728

2829
export function SearchCommand({
2930
keyboardShortcut,
3031
children,
32+
onAction,
3133
}: SearchCommandProps) {
3234
const { search, setSearch, query } = useDocsSearch({ type: "fetch" });
3335
const results =
@@ -48,7 +50,11 @@ export function SearchCommand({
4850

4951
return (
5052
<SearchCommandDialog keyboardShortcut={keyboardShortcut} trigger={children}>
51-
<Command inputValue={search} onInputChange={setSearch} className="h-72">
53+
<Command
54+
inputValue={search}
55+
onInputChange={setSearch}
56+
className="h-72"
57+
>
5258
<div className="p-1">
5359
<SearchFieldRoot placeholder="Search" autoFocus className="w-full">
5460
<InputRoot className="focus-within:ring-1">
@@ -57,7 +63,13 @@ export function SearchCommand({
5763
</InputRoot>
5864
</SearchFieldRoot>
5965
</div>
60-
<MenuContent className="h-full overflow-y-scroll py-1">
66+
<MenuContent
67+
onAction={() => {
68+
setSearch("");
69+
onAction?.();
70+
}}
71+
className="h-full overflow-y-scroll py-1"
72+
>
6173
{results.map((group) => (
6274
<MenuSection key={group.id} title={group.name}>
6375
{group.results.map((item) => (

0 commit comments

Comments
 (0)