Skip to content

Commit 436f2d2

Browse files
committed
fix: make dialog error about application already open unclosable
1 parent d7aea08 commit 436f2d2

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/domains/_core/components/alone-dialog/alone-dialog.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Component, createEffect } from "solid-js";
1+
import { type Component, createEffect, onMount } from "solid-js";
22
import { Dialog, type DialogRef } from "../../../ui/components/dialog/dialog";
33
import { useAlone } from "./use-alone";
44

@@ -12,6 +12,12 @@ export const AloneDialog: Component = () => {
1212
}
1313
});
1414

15+
onMount(() => {
16+
dialog.ref.addEventListener("cancel", (event) => {
17+
event.preventDefault();
18+
});
19+
});
20+
1521
return (
1622
<Dialog ref={dialog} title="Application already open !">
1723
<p>The application is open in several tabs, and it is not meant to be open in several tabs.</p>

src/domains/ui/components/dialog/dialog.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Component, type JSX, type Ref, Show, onMount } from "solid-js";
1+
import { type Component, type JSX, type Ref, Show } from "solid-js";
22
import { DialogContent } from "./dialog-content";
33
import { DialogContext } from "./dialog-context";
44
import { Portal } from "solid-js/web";
@@ -15,6 +15,7 @@ const sDialog = css({
1515
});
1616

1717
export interface DialogRef {
18+
ref: HTMLDialogElement;
1819
open: () => void;
1920
close: () => void;
2021
}
@@ -28,9 +29,11 @@ interface DialogProps {
2829
export const Dialog: Component<DialogProps> = (props) => {
2930
let dialog!: HTMLDialogElement; // oxlint-disable-line init-declarations no-unassigned-vars
3031

31-
onMount(() => {
32+
const setDialog = (ref: HTMLDialogElement): void => {
33+
dialog = ref;
3234
if (isFunction(props.ref)) {
3335
props.ref({
36+
ref: dialog,
3437
open: () => {
3538
dialog.showModal();
3639
},
@@ -39,11 +42,11 @@ export const Dialog: Component<DialogProps> = (props) => {
3942
},
4043
});
4144
}
42-
});
45+
};
4346

4447
return (
4548
<Portal>
46-
<dialog ref={dialog} class={sDialog}>
49+
<dialog ref={setDialog} class={sDialog}>
4750
<DialogContext.Provider value={dialog}>
4851
<Show when={props.title}>
4952
<h3>{props.title}</h3>

0 commit comments

Comments
 (0)