Skip to content

Commit 48c34ef

Browse files
committed
fix: Prevent reset progress dialog from closing before action completes
The click-outside handler was using mousedown which fires before click. When clicking the confirm button, the handler would close the dialog before the click event could trigger handleConfirmReset, preventing the reset from executing. Added a ref to the confirmation dialog and updated the click-outside handler to also check if clicks occur inside the dialog.
1 parent 44faac1 commit 48c34ef

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

components/Navbar.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ export default function Navbar() {
1212
const [settingsOpen, setSettingsOpen] = useState(false);
1313
const [showResetConfirm, setShowResetConfirm] = useState(false);
1414
const settingsRef = useRef<HTMLDivElement>(null);
15+
const confirmDialogRef = useRef<HTMLDivElement>(null);
1516

1617
// Close settings menu when clicking outside
1718
useEffect(() => {
1819
function handleClickOutside(event: MouseEvent) {
19-
if (settingsRef.current && !settingsRef.current.contains(event.target as Node)) {
20+
const target = event.target as Node;
21+
const isInsideSettings = settingsRef.current?.contains(target);
22+
const isInsideConfirmDialog = confirmDialogRef.current?.contains(target);
23+
24+
if (!isInsideSettings && !isInsideConfirmDialog) {
2025
setSettingsOpen(false);
2126
setShowResetConfirm(false);
2227
}
@@ -202,6 +207,7 @@ export default function Navbar() {
202207
{/* Reset Progress Confirmation Dialog */}
203208
{showResetConfirm && (
204209
<div
210+
ref={confirmDialogRef}
205211
className="fixed inset-0 z-[100] flex items-center justify-center"
206212
role="dialog"
207213
aria-modal="true"

0 commit comments

Comments
 (0)