# click-outside-element

> Trigger event when click outside element or component

Latest version **0.0.3** (published 2023-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install click-outside-element
pnpm add click-outside-element
yarn add click-outside-element
bun add click-outside-element
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2023-04-02 |
| First published | 2023-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Baskara Febrianto |
| Maintainers | bas_baskara |

## Links

- npm: https://www.npmjs.com/package/click-outside-element
- Repository: https://github.com/bas-baskara/click-outside
- Homepage: https://github.com/bas-baskara/click-outside#readme
- Issues: https://github.com/bas-baskara/click-outside/issues
- npm.io page: https://npm.io/package/click-outside-element

## Recent versions

- 0.0.3 (latest) — 2023-04-02
- 0.0.2 — 2023-04-02
- 0.0.1 — 2023-04-02
- 0.0.0 — 2023-04-02

## README

This is a very simple function that I use in most of all the project. Usually I create it inside utils directory in my project, but I decide to put it in the npmjs package.

# How to use it:

### Vanila JS

```html
...
  <div id="container-wrapper">
      ...
    </div>
...
```

```javascript
import clickOutside from 'click-outside-element'


function handler() {
  // handle event
}

clickOutside(document.getElementById("container-wrapper"), handler)


```

### React JS

```javascript
import clickOutside from 'click-outside-element'


function App() {
  const wrapperRef = useRef(null);

  const handler = () => {
    console.log('Clicked outside of the element!');
  };

  clickOutside(wrapperRef, handler);

  return (
    <div ref={wrapperRef}>
      <p>Click outside of this element to trigger the handler function.</p>
    </div>
  );
}

```

### Svelte JS

```javascript
import clickOutside from 'click-outside-element'


  const handler = () => {
    console.log('Clicked outside of the element!');
  };

<div use:clickOutside={handler}>
      <p>Click outside of this element to trigger the handler function.</p>
    </div>


```

---
_Source: https://npm.io/package/click-outside-element · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
