Skip to content

listenHost() ​

ts
function listenHost(name: keyof HTMLElementEventMap, options?: AddEventListenerOptions): MethodDecorator;

Decorator to listen to host element events within a lit component. Adds the listener when the component connects and removes it when it disconnects.

Parameters ​

name ​

keyof HTMLElementEventMap

the host element event to listen for, e.g. focusout or transitionend

options? ​

AddEventListenerOptions

optional event listener options, e.g. { passive: true }

Returns ​

MethodDecorator

Example ​

ts
class MyComponent extends LitElement {
  ⁠@listenHost('transitionend', { passive: true })
  handleTransitionEnd(event: TransitionEvent) {}
}