Actions
use:clickoutside Adds a click handler that only fires whenever the click is not the element passed in.Example
<script>
import { clickoutside } from "svaria";
let text;
</script>
<div
on:click={() => (text = "Clicked inside!")}
use:clickoutside={() => (text = "Clicked outside!")}
>
{text ?? "Waiting for clicks..."}
</div>
Waiting for clicks...
Paramaters
Name | Type | Required | Description |
---|---|---|---|
callback |
(target: EventTarget & HTMLElement) => void |
true |
Callback to run when clicked outside. The clicked HTML element is passed through |