Skip to content

Commit 0454035

Browse files
committed
fix: close on select
1 parent baba3b7 commit 0454035

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/components/Search/SearchModalContainer.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { ComponentProps } from 'react'
1010
import type { SearchResult } from './SearchItem'
1111
import SearchItem from './SearchItem'
1212

13-
export const SearchModalContainer = ({ className }: ComponentProps<'search'>) => {
13+
export const SearchModalContainer = ({
14+
className,
15+
close,
16+
}: ComponentProps<'search'> & { close: () => void }) => {
1417
const router = useRouter()
1518
const { docs } = useDocs()
1619
const [query, setQuery] = React.useState('')
@@ -84,7 +87,10 @@ export const SearchModalContainer = ({ className }: ComponentProps<'search'>) =>
8487
<Command.Item
8588
key={`search-item-${index}`}
8689
value={result.url}
87-
onSelect={router.push}
90+
onSelect={(value) => {
91+
router.push(value)
92+
close()
93+
}}
8894
className="rounded-md transition-colors data-[selected=true]:bg-surface-container-high"
8995
>
9096
<SearchItem search={query} result={result} tabIndex={-1} />

src/components/Search/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ function Search({ className }: ComponentProps<typeof Dialog.Trigger>) {
3636
<Dialog.Close className="size-full" />
3737
</Dialog.Overlay>
3838

39-
<SearchModalContainer className="relative mx-auto max-w-3xl rounded-md px-4 shadow-sm [--Search-Input-top:theme(spacing.8)] lg:[--Search-Input-top:theme(spacing.24)]" />
39+
<SearchModalContainer
40+
className="relative mx-auto max-w-3xl rounded-md px-4 shadow-sm [--Search-Input-top:theme(spacing.8)] lg:[--Search-Input-top:theme(spacing.24)]"
41+
close={() => setShowSearchModal(false)}
42+
/>
4043
</Dialog.Content>
4144
</Dialog.Portal>
4245
</Dialog.Root>

0 commit comments

Comments
 (0)