Skip to content

Commit e426d07

Browse files
committed
fix: Close edit modal when backdrop clicked
1 parent 7bd4ee9 commit e426d07

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/itemContent/createDialog.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const createDialog = ({
1616
const dialog = document.createElement("dialog");
1717

1818
dialog.style.maxWidth = "960px";
19+
// Make be not able to click inner
20+
dialog.style.padding = "0";
1921
dialog.style.top = "32px";
2022
dialog.style.width = "calc(100% - 64px)";
2123

@@ -32,11 +34,22 @@ const createDialog = ({
3234
data,
3335
});
3436

37+
const handleDialogClick = (event: MouseEvent) => {
38+
if (!(event.target instanceof Node) || !event.target.isEqualNode(dialog)) {
39+
return;
40+
}
41+
42+
dialog.close();
43+
};
44+
45+
dialog.addEventListener("click", handleDialogClick);
46+
3547
const handleDialogClose = async () => {
3648
const editorJSData = await editorJS.save();
3749

3850
editorJS.destroy();
3951

52+
dialog.removeEventListener("click", handleDialogClick);
4053
dialog.removeEventListener("close", handleDialogClose);
4154
dialog.remove();
4255

0 commit comments

Comments
 (0)