Skip to content

Commit ecd046b

Browse files
committed
Close search when the overlay is clicked
1 parent fba330b commit ecd046b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

app/components/SearchBar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export function SearchBar() {
4141
</div>
4242
</DialogTrigger>
4343
<DialogContent
44+
onOverlayClick={() => setIsOpen(false)}
4445
className={classnames(
4546
"fixed z-50",
4647
"w-[95vw] max-w-xl rounded-lg",

app/components/UI/Dialog.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import React, { ComponentPropsWithoutRef } from "react";
33

44
export const DialogContent = React.forwardRef<
55
React.ElementRef<typeof DialogPrimitive.Content>,
6-
ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
6+
ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
7+
onOverlayClick?: () => void;
8+
}
79
>(({ children, ...props }, forwardedRef) => (
810
<DialogPrimitive.Portal>
911
<DialogPrimitive.Overlay
1012
forceMount
1113
className="fixed inset-0 z-20 bg-black/60"
14+
onClick={() => {
15+
props.onOverlayClick && props.onOverlayClick();
16+
}}
1217
/>
1318
<DialogPrimitive.Content forceMount {...props} ref={forwardedRef}>
1419
{children}

0 commit comments

Comments
 (0)