Skip to content

Commit

Permalink
fix: modal outside click only on mouse down (#1160)
Browse files Browse the repository at this point in the history
* modal outside click only on mouse down

* rename function

---------

Co-authored-by: tommygiesbrecht <[email protected]>
  • Loading branch information
tommygiesbrecht and tommygiesbrecht authored Dec 3, 2023
1 parent 38d0220 commit 96e4d4b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/modal/Modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
const onAutoClose = (e: MouseEvent) => {
const target: Element = e.target as Element;
if (autoclose && target?.tagName === 'BUTTON') hide(e); // close on any button click
};
const onOutsideClose = (e: MouseEvent) => {
const target: Element = e.target as Element;
if (outsideclose && target === e.currentTarget) hide(e); // close on click outside
};
Expand All @@ -117,7 +121,7 @@
<div class={backdropCls} />
<!-- dialog -->
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<div on:keydown={handleKeys} on:wheel|preventDefault|nonpassive use:prepareFocus use:focusTrap on:click={onAutoClose} class={twMerge(dialogClass, $$props.classDialog, ...getPlacementClasses())} tabindex="-1" aria-modal="true" role="dialog">
<div on:keydown={handleKeys} on:wheel|preventDefault|nonpassive use:prepareFocus use:focusTrap on:click={onAutoClose} on:mousedown={onOutsideClose} class={twMerge(dialogClass, $$props.classDialog, ...getPlacementClasses())} tabindex="-1" aria-modal="true" role="dialog">
<div class="flex relative {sizes[size]} w-full max-h-full">
<!-- Modal content -->
<Frame rounded shadow {...$$restProps} class={frameClass}>
Expand Down

2 comments on commit 96e4d4b

@vercel
Copy link

@vercel vercel bot commented on 96e4d4b Dec 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 96e4d4b Dec 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.