Svelte clickOutside
action, with support for multiple elements.
npm i -D svelte-clicko
<script>
import clickOutside from 'svelte-clicko';
const onClickOutside = () => {
// event handler
}
</script>
<div use:clickOutside on:clickOutside={onClickOutside} />
clickOutside
event will only fire if the click was outside every given element.
<script>
import clickOutside from 'svelte-clicko';
let elementOne, elementTwo;
const onClickOutside = () => {
// event handler
}
</script>
<div bind:this={elementOne}></div>
<div bind:this={elementTwo}></div>
<div
use:clickOutside={[elementOne, elementTwo]}
on:clickOutside={onClickOutside}>
</div>