--- url: /reference/items/ClickOutside.md --- # ClickOutside The `ClickOutside` primitive dispatches a native `click-outside` event on its element whenever the user clicks anywhere outside of it. ## Usage `ClickOutside` defines no behaviour of its own beyond emitting the event, so it is meant to be paired with the [`Action`](/reference/items/Action/index.html) component on the same element. Add both components to an element and listen to the emitted event with the [`on:` option](/reference/items/Action/js-api.html#on-event-modifier): `data-on:click-outside="..."`. In the following example, a dropdown menu is toggled by a button and closes as soon as a click lands outside of it. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, ClickOutside, Target } from '@studiometa/ui'; registerComponent(Action); registerComponent(ClickOutside); registerComponent(Target); ``` :::