forge
Explore
Log in

Don't you dare go Hollow

📱 Şablon seç closes without reopening on mobile

Browse files at this commit

b411f4ea1ecd73620a08c4076f6d540418e5e83aBurak BoduroğluParent: f45dd35
  • fix
    • 📱 Şablon seç closes without reopening on mobile
Show full message
fix: 📱 Şablon seç closes without reopening on mobile
- FormDialog: dismissable=false (X/Cancel only) and defer onOpenChange(false)
  so the closing tap cannot fall through onto the trigger underneath
- move bank "Pick a template" from FormDialog to SidePanel (wide), matching
  short picker work and giving a reliable header close on phones
- defer SidePanel/Cancel/insert closes the same way in exam-questions-panel
- add FormDialog tests for backdrop stay-open and deferred header close
src/components/exams/exam-questions-panel.tsxmodified+21 -7
@@ -19,6 +19,7 @@ import { Badge } from "@/components/ui/badge";
19 import { Button } from "@/components/ui/button";19 import { Button } from "@/components/ui/button";
20 import { ConfirmDialog } from "@/components/ui/confirm-dialog";20 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
21 import { FormDialog } from "@/components/ui/form-dialog";21 import { FormDialog } from "@/components/ui/form-dialog";
22+import { SidePanel } from "@/components/ui/side-panel";
22 import { BankQuestionPicker } from "@/components/exams/bank-question-picker";23 import { BankQuestionPicker } from "@/components/exams/bank-question-picker";
23 import { QuestionForm, type QuestionValues } from "@/components/exams/question-form";24 import { QuestionForm, type QuestionValues } from "@/components/exams/question-form";
24 import { IconArchive, IconChevronLeft, IconChevronRight, IconPlus, IconRefresh, IconTrash } from "@/components/ui/icons";25 import { IconArchive, IconChevronLeft, IconChevronRight, IconPlus, IconRefresh, IconTrash } from "@/components/ui/icons";
@@ -28,6 +29,11 @@ import { hasMinRole } from "@/lib/roles";
28 import { useAuth } from "@/stores/auth-context";29 import { useAuth } from "@/stores/auth-context";
29 import { useT } from "@/stores/preferences-context";30 import { useT } from "@/stores/preferences-context";
30 31
32+/** Close after the current pointer gesture so the tap cannot reopen the surface. */
33+const closeAfterGesture = (close: () => void) => {
34+ setTimeout(close, 0);
35+};
36+
31 const QUESTION_PAGE_SIZE = 1;37 const QUESTION_PAGE_SIZE = 1;
32 38
33 export function ExamQuestionsPanel(props: {39 export function ExamQuestionsPanel(props: {
@@ -136,7 +142,7 @@ export function ExamQuestionsPanel(props: {
136 142
137 const insertFromBank = async (bankQuestionId: string, subjectId: string) => {143 const insertFromBank = async (bankQuestionId: string, subjectId: string) => {
138 await postExamQuestionFromBank(props.examId, bankQuestionId, subjectId);144 await postExamQuestionFromBank(props.examId, bankQuestionId, subjectId);
139- setBankOpen(false);145+ closeAfterGesture(() => setBankOpen(false));
140 setFlash(t("bank.inserted"));146 setFlash(t("bank.inserted"));
141 await refetch();147 await refetch();
142 };148 };
@@ -249,18 +255,22 @@ export function ExamQuestionsPanel(props: {
249 </Show>255 </Show>
250 </div>256 </div>
251 257
252- <FormDialog258+ <SidePanel
253 open={bankOpen() && !props.readOnly}259 open={bankOpen() && !props.readOnly}
254- onOpenChange={setBankOpen}260+ onOpenChange={(open) => {
261+ if (open) setBankOpen(true);
262+ else closeAfterGesture(() => setBankOpen(false));
263+ }}
255 title={t("bank.pickTemplate")}264 title={t("bank.pickTemplate")}
256 description={t("bank.title")}265 description={t("bank.title")}
266+ size="wide"
257 >267 >
258 <BankQuestionPicker268 <BankQuestionPicker
259 subjects={subjects() ?? []}269 subjects={subjects() ?? []}
260 onInsert={insertFromBank}270 onInsert={insertFromBank}
261- onCancel={() => setBankOpen(false)}271+ onCancel={() => closeAfterGesture(() => setBankOpen(false))}
262 />272 />
263- </FormDialog>273+ </SidePanel>
264 274
265 <FormDialog275 <FormDialog
266 open={formOpen() || editing() != null}276 open={formOpen() || editing() != null}
@@ -281,8 +291,12 @@ export function ExamQuestionsPanel(props: {
281 choiceImageSrc={(choiceId) => `/api/exams/${props.examId}/questions/${editing()?.id}/choices/${choiceId}/image`}291 choiceImageSrc={(choiceId) => `/api/exams/${props.examId}/questions/${editing()?.id}/choices/${choiceId}/image`}
282 loadImageBlob={editing() ? () => getExamQuestionImageBlob(props.examId, editing()!.id) : undefined}292 loadImageBlob={editing() ? () => getExamQuestionImageBlob(props.examId, editing()!.id) : undefined}
283 onCancel={() => {293 onCancel={() => {
284- setEditing(null);294+ // In-body Cancel bypasses FormDialog's deferred onOpenChange, so
285- setFormOpen(false);295+ // defer here too — otherwise the same tap can reopen the form.
296+ closeAfterGesture(() => {
297+ setEditing(null);
298+ setFormOpen(false);
299+ });
286 }}300 }}
287 onSubmit={submit}301 onSubmit={submit}
288 />302 />
src/components/ui/form-dialog.test.tsxadded+54 -0
@@ -0,0 +1,54 @@
1+import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library";
2+import { createSignal } from "solid-js";
3+import { FormDialog } from "@/components/ui/form-dialog";
4+
5+beforeEach(() => vi.spyOn(window, "scrollTo").mockImplementation(() => {}));
6+afterEach(() => {
7+ cleanup();
8+ vi.restoreAllMocks();
9+});
10+
11+test("form dialog stays open when the backdrop is pressed", async () => {
12+ function TestFormDialog() {
13+ const [open, setOpen] = createSignal(true);
14+ return (
15+ <>
16+ <span>{open() ? "open" : "closed"}</span>
17+ <FormDialog open={open()} onOpenChange={setOpen} title="Edit item">
18+ <p>Body</p>
19+ </FormDialog>
20+ </>
21+ );
22+ }
23+
24+ render(() => <TestFormDialog />);
25+ await new Promise((resolve) => setTimeout(resolve, 0));
26+ fireEvent.pointerDown(document.querySelector("[data-expanded]")!);
27+ await new Promise((resolve) => setTimeout(resolve, 0));
28+
29+ expect(screen.getByText("open")).toBeTruthy();
30+});
31+
32+test("form dialog closes from the header close button after the gesture", async () => {
33+ function TestFormDialog() {
34+ const [open, setOpen] = createSignal(true);
35+ return (
36+ <>
37+ <span>{open() ? "open" : "closed"}</span>
38+ <button type="button" onClick={() => setOpen(true)}>
39+ Open
40+ </button>
41+ <FormDialog open={open()} onOpenChange={setOpen} title="Edit item">
42+ <p>Body</p>
43+ </FormDialog>
44+ </>
45+ );
46+ }
47+
48+ render(() => <TestFormDialog />);
49+ await new Promise((resolve) => setTimeout(resolve, 0));
50+ fireEvent.click(screen.getByLabelText("Close"));
51+ expect(screen.getByText("open")).toBeTruthy();
52+ await new Promise((resolve) => setTimeout(resolve, 0));
53+ expect(screen.getByText("closed")).toBeTruthy();
54+});
src/components/ui/form-dialog.tsxmodified+19 -2
@@ -8,6 +8,12 @@ import {
8 DialogTitle,8 DialogTitle,
9 } from "@/components/ui/dialog";9 } from "@/components/ui/dialog";
10 10
11+/**
12+ * Form surface in a dialog. Closes only via the header X (or an in-body
13+ * Cancel that calls onOpenChange(false)) — backdrop/ESC are off so a
14+ * dismiss gesture cannot fall through onto the trigger and reopen the
15+ * same dialog on mobile.
16+ */
11 export function FormDialog(props: {17 export function FormDialog(props: {
12 open: boolean;18 open: boolean;
13 onOpenChange: (open: boolean) => void;19 onOpenChange: (open: boolean) => void;
@@ -16,9 +22,20 @@ export function FormDialog(props: {
16 children: JSX.Element;22 children: JSX.Element;
17 class?: string;23 class?: string;
18 }) {24 }) {
25+ const handleOpenChange = (open: boolean) => {
26+ if (open) {
27+ props.onOpenChange(true);
28+ return;
29+ }
30+ // Defer the close until after the current pointer/click finishes. Otherwise
31+ // removing the dialog mid-gesture lets the same tap land on the trigger
32+ // underneath (e.g. "From bank") and the dialog pops straight back open.
33+ setTimeout(() => props.onOpenChange(false), 0);
34+ };
35+
19 return (36 return (
20- <Dialog open={props.open} onOpenChange={props.onOpenChange}>37+ <Dialog open={props.open} onOpenChange={handleOpenChange}>
21- <DialogContent class={props.class}>38+ <DialogContent dismissable={false} class={props.class}>
22 <DialogHeader>39 <DialogHeader>
23 <DialogTitle>{props.title}</DialogTitle>40 <DialogTitle>{props.title}</DialogTitle>
24 {props.description && <DialogDescription>{props.description}</DialogDescription>}41 {props.description && <DialogDescription>{props.description}</DialogDescription>}