Skip to content

Commit

Permalink
[ui] fix modals closing unintentionally
Browse files Browse the repository at this point in the history
  • Loading branch information
ioj4 committed Aug 8, 2024
1 parent 2e3ddb6 commit c836466
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/shelter-ui/src/modals.tsx.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ $RADIUS: 4px;
}
}

.backdrop {
width: 100%;
height: 100%;
position: absolute;
}

.wrap {
transition-property: opacity, transform;
transition-duration: 250ms;
Expand Down
6 changes: 3 additions & 3 deletions packages/shelter-ui/src/openModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const ModalRoot: Component = () => {
ensureInternalStyle(css);

let dialogEl;
let backdropEl;

createEffect(() => {
dialogEl.showModal();
Expand All @@ -36,9 +37,7 @@ const ModalRoot: Component = () => {
dialogEl.addEventListener("keydown", (ev) => ev.stopImmediatePropagation());

// click outside dialog handler
dialogEl.addEventListener("click", (ev) => {
if (ev.target === dialogEl || ev.target.parentElement === dialogEl) popModal();
});
backdropEl.addEventListener("click", popModal);
});

return (
Expand All @@ -50,6 +49,7 @@ const ModalRoot: Component = () => {
[classes.active]: !bgAnimPrePost(),
}}
>
<div ref={backdropEl} class={classes.backdrop} />
<For each={currentModals()}>
{(M, idx) => (
<div
Expand Down

0 comments on commit c836466

Please sign in to comment.