listenWindow()
ts
function listenWindow(name: keyof WindowEventMap, options?: AddEventListenerOptions): MethodDecorator;Decorator to listen to window events within a lit component. Adds the listener when the component connects and removes it when it disconnects.
Parameters
name
keyof WindowEventMap
the window event to listen for, e.g. resize or offline
options?
AddEventListenerOptions
optional event listener options, e.g. { passive: true }
Returns
MethodDecorator
Example
ts
class MyComponent extends LitElement {
@listenWindow('resize', { passive: true })
handleResize(event: UIEvent) {}
}