Skip to content

Events

Some stimulus-use modules will add new events. Events typically mirror the behavior they add to the controller.

Here is a list of all additional events:

All event names below are shown without their prefix. By default they are prefixed with the controller identifier (see Event Prefix).

EventModuleDescriptionevent.detail
appearuseIntersectionTriggered whenever the controller element appears within the viewport.{ entry, controller }
awayuseIdleTriggered whenever the user becomes idle on the page.{ controller, originalEvent }
backuseIdleTriggered whenever the user returns from an idle state.{ controller, originalEvent }
click:outsideuseClickOutsideTriggered whenever the user clicks outside of the controller element.{ controller, originalEvent }
disappearuseIntersectionTriggered whenever the controller element disappears from the viewport.{ entry, controller }
focususeWindowFocusTriggered whenever the window becomes focused.{ event, hasFocus }
invisibleuseVisibilityTriggered whenever the page visibility changes and the browser tab becomes invisible.{ event, isVisible }
mouseEnteruseHoverTriggered whenever the mouse enters the controller element.{ hover }
mouseLeaveuseHoverTriggered whenever the mouse leaves the controller element.{ hover }
mutateuseMutationTriggered whenever the observed mutations occur.{ entries }
resizeuseResizeTriggered whenever the observed element is resized.{ entry, controller }
unfocususeWindowFocusTriggered whenever the window loses focus.{ event, hasFocus }
visibleuseVisibilityTriggered whenever the page visibility changes and the browser tab becomes visible.{ event, isVisible }
[name]:changed / is:[name] / not:[name]useMatchMediaTriggered whenever a tracked media query changes / matches / stops matching. [name] is the key of the media query.{ name, media, matches, event }

Event Prefix

With the module options you can specify the event prefix. By default all module will emit events with the controller identifier as a prefix.

The eventPrefix option can be a boolean or a string.

js
// card_controller.js
export default class extends Controller {
  options = {
    eventPrefix: true,
  }

  connect() {
    useIntersection(this, this.options)
  }
}

Example for eventPrefix values:

  • true -> card:appear
  • false -> appear
  • "my-prefix" -> my-prefix:appear

Accessing source controller and details

The controller and the original event are provided within the details object of the event.

js
// get the emitting controller and original event for a click:outside event
const { controller, originalEvent } = event.detail
js
// get the emitting controller and entry object for an appear event
const { controller, entry } = event.detail