--- url: /reference/items/Action/examples.md --- # Examples ## Close several dialogs at once A single `Action` can target several components at once. Here one button closes both a centered [`Dialog`](/reference/items/Dialog/) and a drawer by targeting every `Dialog` matching the `[data-can-be-closed]` attribute selector. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, Dialog, Transition } from '@studiometa/ui'; registerComponent(Action); registerComponent(Dialog); registerComponent(Transition); ``` ::: ## Prevent default :::code-group ```js import { Base, registerComponent } from '@studiometa/js-toolkit'; import { Action } from '@studiometa/ui'; class Foo extends Base { static config = { name: 'Foo', }; } registerComponent(Action); registerComponent(Foo); ``` ::: ## Debounce modifier Use the `debounce` modifier to prevent firing the action's effect too often. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action } from '@studiometa/ui'; registerComponent(Action); ``` ::: ## Side effects on a popover `Action` listens to real DOM events, so it can react to native ones too. Here a `` uses the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) for the whole modal mechanics — open, close, Esc, click-outside, focus and top-layer stacking — with no JavaScript. `Action` only wires the one thing the platform does not provide: locking the body scroll, by listening to the popover's `toggle` event and reading its `newState`. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action } from '@studiometa/ui'; // No open/close logic: the Popover API handles it. Action only wires the // scroll-lock side effect to the native `toggle` event. registerComponent(Action); ``` :::