Skip to content

Commit ca3e687

Browse files
committed
feat: implemented clicking outside modals closes them
1 parent 3a28f5a commit ca3e687

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

public/favicon.ico

4.19 KB
Binary file not shown.

src/components/modals/ShareEmailModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ const ShareEmailModal: React.FC<{ onClose: () => void }> = ({ onClose }) => {
129129
margin: '-8px',
130130
background: '#f9f9f9',
131131
}}
132+
onClick={(e) => e.stopPropagation()}
132133
>
133134
{/* Postal stamp decoration */}
134135
<div className='absolute top-4 right-4 w-16 h-20 border-2 border-gray-400 border-dashed rounded-sm opacity-20 flex items-center justify-center pointer-events-none'>

src/components/modals/UserDataModal.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,23 @@ const UserDataModal: React.FC<UserDataModalProps> = ({ onOpenChange }) => {
7272
setIsEditingUsername(false);
7373
};
7474

75+
// Handler for clicks outside the modal
76+
const handleOutsideClick = (e: React.MouseEvent<HTMLDivElement>) => {
77+
// Only close if the click was directly on the overlay (not on the modal content)
78+
if (e.target === e.currentTarget) {
79+
onOpenChange(false);
80+
}
81+
};
82+
7583
return (
76-
<div className='fixed inset-0 z-50 flex items-center justify-center overflow-hidden bg-black/50'>
77-
<div className='bg-white m-2 sm:m-5 max-w-3xl w-full min-w-[280px] rounded-lg p-0 overflow-hidden shadow-xl'>
84+
<div
85+
className='fixed inset-0 z-50 flex items-center justify-center overflow-hidden bg-black/50'
86+
onClick={handleOutsideClick}
87+
>
88+
<div
89+
className='bg-white m-2 sm:m-5 max-w-3xl w-full min-w-[280px] rounded-lg p-0 overflow-hidden shadow-xl'
90+
onClick={(e) => e.stopPropagation()} // Prevent clicks inside from closing
91+
>
7892
<div className='bg-brand-pink p-2 flex items-center justify-between sm:rounded-t-lg'>
7993
<h2 className='text-xl font-semibold text-white'>User's Data</h2>
8094
<button

src/components/ui/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Input = React.forwardRef<
1010
<input
1111
type={type}
1212
className={cn(
13-
'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
13+
'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm text-gray-900 ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
1414
className
1515
)}
1616
ref={ref}

src/components/ui/simple-dialog.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ const SimpleDialogPortal: React.FC<{ children: React.ReactNode }> = ({ children
3737
return <>{children}</>;
3838
};
3939

40-
const SimpleDialogOverlay: React.FC<{ className?: string }> = ({ className }) => {
40+
const SimpleDialogOverlay: React.FC<{ className?: string; onClick?: () => void }> = ({
41+
className,
42+
onClick
43+
}) => {
4144
return (
4245
<div
4346
className={cn(
4447
'fixed inset-0 z-50 bg-black/80',
4548
className
46-
)}
49+
)}
50+
onClick={onClick}
4751
/>
4852
);
4953
};
@@ -61,13 +65,19 @@ const SimpleDialogContent = React.forwardRef<HTMLDivElement, SimpleDialogContent
6165
}, [onOpenAutoFocus]);
6266
}
6367

68+
// Stop click propagation to prevent closing the dialog when clicking content
69+
const handleContentClick = (e: React.MouseEvent) => {
70+
e.stopPropagation();
71+
};
72+
6473
return (
6574
<div
6675
ref={ref}
6776
className={cn(
6877
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border-0 bg-background p-0 shadow-lg duration-200',
6978
className
7079
)}
80+
onClick={handleContentClick}
7181
{...props}
7282
>
7383
{children}
@@ -162,7 +172,7 @@ const SimpleDialog: React.FC<SimpleDialogProps> = ({
162172
<SimpleDialogContext.Provider value={{ isOpen: isDialogOpen, onOpenChange }}>
163173
{isDialogOpen ? (
164174
<div className={cn('fixed inset-0 z-50', className)}>
165-
<SimpleDialogOverlay />
175+
<SimpleDialogOverlay onClick={() => onOpenChange(false)} />
166176
{children}
167177
</div>
168178
) : (

0 commit comments

Comments
 (0)