Skip to content

Commit

Permalink
fix: Close edit modal when backdrop clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
hata6502 committed Jan 28, 2021
1 parent 7bd4ee9 commit e426d07
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/itemContent/createDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const createDialog = ({
const dialog = document.createElement("dialog");

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

Expand All @@ -32,11 +34,22 @@ const createDialog = ({
data,
});

const handleDialogClick = (event: MouseEvent) => {
if (!(event.target instanceof Node) || !event.target.isEqualNode(dialog)) {
return;
}

dialog.close();
};

dialog.addEventListener("click", handleDialogClick);

const handleDialogClose = async () => {
const editorJSData = await editorJS.save();

editorJS.destroy();

dialog.removeEventListener("click", handleDialogClick);
dialog.removeEventListener("close", handleDialogClose);
dialog.remove();

Expand Down

0 comments on commit e426d07

Please sign in to comment.