@svelte-bin/clickoutside
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@svelte-bin/clickoutside

With the clickoutside action, a callback function will be fired whenever the user clicks outside of the DOM node the action is applied to.

Installation

npm  i @svelte-bin/clickoutside

Usage

<script>
	import { clickoutside } from '@svelte-bin/clickoutside';
	let enabled = false;
</script>

<div
	use:clickoutside={{
		enabled,
		callback: () => {
			alert('outside clicked');
		}
	}}
>
	<button type="button" on:click={() => (enabled = !enabled)}>
		Click Outside: {enabled ? 'on' : 'off'}
	</button>
	<div>Click outside</div>
</div>

Params

Param Description
enabled Sets the action to an enabled state if true, if false, action will not trigger
callback The callback to be fired once the user clicks outside of the DOM node

Definition

import type { Action } from 'svelte/action';

export interface ClickOutSideConfig {
	enabled: boolean;
	callback: (any) => unknown;
}

export interface ClickOutSideAttribute {}
export type clickoutsideAction = Action<HTMLElement, ClickOutSideConfig, ClickOutSideAttribute>;

Package Sidebar

Install

npm i @svelte-bin/clickoutside

Weekly Downloads

0

Version

0.0.2

License

none

Unpacked Size

3.9 kB

Total Files

7

Last publish

Collaborators

  • binsarjr