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 1a46f9b commit aa3d55f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/EditorJSInlineElement/createDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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: editorJSData,
});

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 aa3d55f

Please sign in to comment.