From b411f4ea1ecd73620a08c4076f6d540418e5e83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Tue, 15 Sep 2026 21:28:01 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=93=B1=20=C5=9Eablon=20se=C3=A7=20?= =?UTF-8?q?closes=20without=20reopening=20on=20mobile=20-=20FormDialog:=20?= =?UTF-8?q?dismissable=3Dfalse=20(X/Cancel=20only)=20and=20defer=20onOpenC?= =?UTF-8?q?hange(false)=20=20=20so=20the=20closing=20tap=20cannot=20fall?= =?UTF-8?q?=20through=20onto=20the=20trigger=20underneath=20-=20move=20ban?= =?UTF-8?q?k=20"Pick=20a=20template"=20from=20FormDialog=20to=20SidePanel?= =?UTF-8?q?=20(wide),=20matching=20=20=20short=20picker=20work=20and=20giv?= =?UTF-8?q?ing=20a=20reliable=20header=20close=20on=20phones=20-=20defer?= =?UTF-8?q?=20SidePanel/Cancel/insert=20closes=20the=20same=20way=20in=20e?= =?UTF-8?q?xam-questions-panel=20-=20add=20FormDialog=20tests=20for=20back?= =?UTF-8?q?drop=20stay-open=20and=20deferred=20header=20close?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/exams/exam-questions-panel.tsx | 28 +++++++--- src/components/ui/form-dialog.test.tsx | 54 +++++++++++++++++++ src/components/ui/form-dialog.tsx | 21 +++++++- 3 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 src/components/ui/form-dialog.test.tsx diff --git a/src/components/exams/exam-questions-panel.tsx b/src/components/exams/exam-questions-panel.tsx index 0d1c571..e6dfc9f 100644 --- a/src/components/exams/exam-questions-panel.tsx +++ b/src/components/exams/exam-questions-panel.tsx @@ -19,6 +19,7 @@ import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { FormDialog } from "@/components/ui/form-dialog"; +import { SidePanel } from "@/components/ui/side-panel"; import { BankQuestionPicker } from "@/components/exams/bank-question-picker"; import { QuestionForm, type QuestionValues } from "@/components/exams/question-form"; import { IconArchive, IconChevronLeft, IconChevronRight, IconPlus, IconRefresh, IconTrash } from "@/components/ui/icons"; @@ -28,6 +29,11 @@ import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; +/** Close after the current pointer gesture so the tap cannot reopen the surface. */ +const closeAfterGesture = (close: () => void) => { + setTimeout(close, 0); +}; + const QUESTION_PAGE_SIZE = 1; export function ExamQuestionsPanel(props: { @@ -136,7 +142,7 @@ export function ExamQuestionsPanel(props: { const insertFromBank = async (bankQuestionId: string, subjectId: string) => { await postExamQuestionFromBank(props.examId, bankQuestionId, subjectId); - setBankOpen(false); + closeAfterGesture(() => setBankOpen(false)); setFlash(t("bank.inserted")); await refetch(); }; @@ -249,18 +255,22 @@ export function ExamQuestionsPanel(props: { - { + if (open) setBankOpen(true); + else closeAfterGesture(() => setBankOpen(false)); + }} title={t("bank.pickTemplate")} description={t("bank.title")} + size="wide" > setBankOpen(false)} + onCancel={() => closeAfterGesture(() => setBankOpen(false))} /> - + `/api/exams/${props.examId}/questions/${editing()?.id}/choices/${choiceId}/image`} loadImageBlob={editing() ? () => getExamQuestionImageBlob(props.examId, editing()!.id) : undefined} onCancel={() => { - setEditing(null); - setFormOpen(false); + // In-body Cancel bypasses FormDialog's deferred onOpenChange, so + // defer here too — otherwise the same tap can reopen the form. + closeAfterGesture(() => { + setEditing(null); + setFormOpen(false); + }); }} onSubmit={submit} /> diff --git a/src/components/ui/form-dialog.test.tsx b/src/components/ui/form-dialog.test.tsx new file mode 100644 index 0000000..bceed4b --- /dev/null +++ b/src/components/ui/form-dialog.test.tsx @@ -0,0 +1,54 @@ +import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; +import { createSignal } from "solid-js"; +import { FormDialog } from "@/components/ui/form-dialog"; + +beforeEach(() => vi.spyOn(window, "scrollTo").mockImplementation(() => {})); +afterEach(() => { + cleanup(); + vi.restoreAllMocks(); +}); + +test("form dialog stays open when the backdrop is pressed", async () => { + function TestFormDialog() { + const [open, setOpen] = createSignal(true); + return ( + <> + {open() ? "open" : "closed"} + +

Body

+
+ + ); + } + + render(() => ); + await new Promise((resolve) => setTimeout(resolve, 0)); + fireEvent.pointerDown(document.querySelector("[data-expanded]")!); + await new Promise((resolve) => setTimeout(resolve, 0)); + + expect(screen.getByText("open")).toBeTruthy(); +}); + +test("form dialog closes from the header close button after the gesture", async () => { + function TestFormDialog() { + const [open, setOpen] = createSignal(true); + return ( + <> + {open() ? "open" : "closed"} + + +

Body

+
+ + ); + } + + render(() => ); + await new Promise((resolve) => setTimeout(resolve, 0)); + fireEvent.click(screen.getByLabelText("Close")); + expect(screen.getByText("open")).toBeTruthy(); + await new Promise((resolve) => setTimeout(resolve, 0)); + expect(screen.getByText("closed")).toBeTruthy(); +}); diff --git a/src/components/ui/form-dialog.tsx b/src/components/ui/form-dialog.tsx index 99e32ab..1378a23 100644 --- a/src/components/ui/form-dialog.tsx +++ b/src/components/ui/form-dialog.tsx @@ -8,6 +8,12 @@ import { DialogTitle, } from "@/components/ui/dialog"; +/** + * Form surface in a dialog. Closes only via the header X (or an in-body + * Cancel that calls onOpenChange(false)) — backdrop/ESC are off so a + * dismiss gesture cannot fall through onto the trigger and reopen the + * same dialog on mobile. + */ export function FormDialog(props: { open: boolean; onOpenChange: (open: boolean) => void; @@ -16,9 +22,20 @@ export function FormDialog(props: { children: JSX.Element; class?: string; }) { + const handleOpenChange = (open: boolean) => { + if (open) { + props.onOpenChange(true); + return; + } + // Defer the close until after the current pointer/click finishes. Otherwise + // removing the dialog mid-gesture lets the same tap land on the trigger + // underneath (e.g. "From bank") and the dialog pops straight back open. + setTimeout(() => props.onOpenChange(false), 0); + }; + return ( - - + + {props.title} {props.description && {props.description}}