> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Element events

The type of `$event` on every Lynx element event. Angular infers it in your templates, so a misspelt `detail` field fails the build. `import type { LynxEvent, ImageLoadDetail } from '@blotch/angular-lynx';`

## Usage

```typescript title="src/app/photo.ts"
import { Component, signal } from '@angular/core';
import {
  type ImageLoadDetail,
  LYNX_ELEMENTS,
  type LynxEvent,
} from '@blotch/angular-lynx';

@Component({
  selector: 'app-photo',
  imports: [LYNX_ELEMENTS],
  template: `
    <image [src]="url" (bindload)="loaded($event)" />
    <text>{{ size()?.width }} × {{ size()?.height }}</text>
  `,
})
export class Photo {
  readonly url = 'https://example.com/photo.jpg';
  readonly size = signal<ImageLoadDetail | null>(null);

  loaded({ detail }: LynxEvent<ImageLoadDetail>): void {
    this.size.set(detail);
  }
}
```

- **In a template, write nothing.** Angular knows each element's events: in `(bindload)="size.set($event.detail)"`, `$event` is already `LynxEvent<ImageLoadDetail>`.
- **For a handler declared in the class,** type its parameter with `LynxEvent` and the event's detail type, from the tables below.
- **Every prefix has the same type.** `(catchtap)`, `(capture-bindtap)` and `(global-bindtap)` get what `(bindtap)` gets, and so on for every event.
- **An event the element doesn't fire** stays the DOM `Event`, such as `(bindload)` on a `<view>`.
- **`$event` isn't a DOM `Event`.** A handler that takes `Event` no longer compiles: change its parameter to the type below.

## API

### `LynxEvent`

```typescript
type LynxEvent<Detail = unknown> = {
  readonly type: string;
  readonly timestamp: number;
  readonly target: LynxEventTarget;
  readonly currentTarget: LynxEventTarget;
  readonly detail: Detail;
  stopPropagation(): void;
  preventDefault(): void;
};
```

| Field                                   | Description                                                                                                                                          |
| --------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type`                                  | The event's name without its prefix, such as `'load'`.                                                                                               |
| `timestamp`                             | When the event fired, in milliseconds. It's `timestamp`, not the DOM's `timeStamp`.                                                                  |
| `target`                                | The element the event started on.                                                                                                                    |
| `currentTarget`                         | The element whose handler is running.                                                                                                                |
| `detail`                                | The event's own data. `LynxEvent` with no `Detail` has `detail: unknown`: for events with none, such as `bindstartplay`.                             |
| `stopPropagation()`, `preventDefault()` | Do nothing. Use the `catch` prefix to stop an event (see [Handling taps and events](/guide/elements/event-handling.md#stop-an-event-from-bubbling)). |

### `LynxEventTarget`

```typescript
type LynxEventTarget = {
  readonly id: string;
  readonly uid: number;
  readonly dataset: Readonly<Record<string, unknown>>;
};
```

Plain data, not the element: it has no methods. `id` is the element's `id` attribute, `uid` Lynx's internal number for it, and `dataset` its `data-*` attributes without the `data-` prefix. A `dataset` value is `unknown` because a property binding, such as `[data-item]="item"`, keeps its value's type.

## Events every element fires

| Event                                                                                            | `$event`                                |
| ------------------------------------------------------------------------------------------------ | --------------------------------------- |
| `bindtap`, `bindlongpress`, `bindtouchstart`, `bindtouchmove`, `bindtouchend`, `bindtouchcancel` | `TouchEvent` from `@lynx-js/types`      |
| `bindmousedown`, `bindmouseup`, `bindmousemove`, `bindmouseenter`, `bindmouseleave`              | `MouseEvent` from `@lynx-js/types`      |
| `bindlayoutchange`                                                                               | `LynxEvent<LayoutChangeDetail>`         |
| `binduiappear`, `binduidisappear`                                                                | `LynxEvent<UIAppearanceDetail>`         |
| `bindanimationstart`, `bindanimationiteration`, `bindanimationend`, `bindanimationcancel`        | `AnimationEvent` from `@lynx-js/types`  |
| `bindtransitionstart`, `bindtransitionend`, `bindtransitioncancel`                               | `TransitionEvent` from `@lynx-js/types` |
| `bindaccessibilityaction`                                                                        | `LynxEvent<AccessibilityActionDetail>`  |

`TouchEvent` has the same fields as `LynxEvent<{ x: number; y: number }>`, plus `touches` and `changedTouches`. Import it, and the other `@lynx-js/types` events, by name: without the import, TypeScript uses the DOM's `TouchEvent`. The detail types are on [`<view>`](/api/elements/view.md#events).

### Pointer events

`(pointerdown)`, `(pointermove)`, `(pointerup)`, `(pointercancel)`, `(pointerover)`, `(pointerout)`, `(pointerenter)`, `(pointerleave)`, `(gotpointercapture)` and `(lostpointercapture)` work on every element, without a `bind` prefix, as in a browser. Lynx sends only touches, so AngularLynx makes each touch into the pointer events a browser fires for one, in the same order, and `$event` is a DOM `PointerEvent`: each finger is a pointer (`pointerId`), `pointerType` is `'touch'`, and `offsetX`/`offsetY` are relative to the element. Libraries written for the web listen for these, such as angular-three for taps on a 3D scene.

A touch's events go to the element it started on, wherever the finger moves, as if every pointer were captured; `setPointerCapture()` changes only `hasPointerCapture()` and the capture events. In the web preview, they're the browser's own pointer events, including a mouse's. A `(click)`, which is Lynx's `bindtap`, has the `offsetX` and `offsetY` of where the pointer lifted, on an element with pointer listeners.

A finger keeps its `pointerId` until it lifts, at the element and at the [document](#document-window-and-body-listeners). With multi-touch off, the LynxView's default, there's one touch at a time, and its `pointerId` is `0`.

`(mouseover)`, `(mouseenter)`, `(mouseout)` and `(mouseleave)` come from the first finger too, as a phone's browser makes them from a tap: `mouseover` and `mouseenter` when it touches the element, after `pointerenter`, and `mouseout` and `mouseleave` when it lifts, after `pointerleave`. Code written for a mouse's hover, such as Angular's [`@defer (on hover)`](/guide/defer.md#triggers), runs when a finger touches the element. Only the element hears them: `document:mouseover` never runs on iOS or Android. In the web preview, they're the browser's own.

### `document:`, `window:` and `body:` listeners

Host listeners on the document, the window and the body work as in a browser, and so do the libraries written for the browser that use them:

```typescript
@Component({
  selector: 'app-tilt',
  host: { '(document:pointermove)': 'tilt($event)' },
  template: `…`,
})
export class Tilt {
  readonly angle = signal(0);

  tilt(event: PointerEvent): void {
    this.angle.set((event.clientX / window.innerWidth - 0.5) * 30);
  }
}
```

An element's `ownerDocument` is a `document` that hears the screen's events, and `inject(DOCUMENT)` is the same object. Its `defaultView` is `window`. So `document.addEventListener()`, `window.addEventListener()` and RxJS's `fromEvent(document, 'click')` hear them too.

| Target                 | Events                                                                                                                                                                                           |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `document:`, `window:` | `pointerdown`, `pointermove`, `pointerup`, `pointercancel`, `pointerover` and `pointerout`, `touchstart`, `touchmove`, `touchend` and `touchcancel`, and `click`, for a touch anywhere on screen |
| `window:`              | `resize`, when the LynxView changes size, as when the device rotates                                                                                                                             |
| `body:`                | Those of the page element, which every element is in: the events that bubble up to it                                                                                                            |

- **They run after the touched element's listeners and the body's**, as in a browser. A capturing listener, `{ capture: true }`, runs before them.
- **They hear a touch that a `(catchtap)` or another `catch` handler stopped.** In a browser, `stopPropagation()` hides an event from the document. On Lynx they still hear it, on the next timer, after every listener of that touch.
- **A pointer event's `target` is the element touched**, the `nativeElement` of its `ElementRef`, and its `offsetX`/`offsetY` are relative to that element. A touch event and a `click` are Lynx's own event objects, as an element's listeners get them.
- **`window.innerWidth` and `window.innerHeight` are the LynxView's size** in CSS pixels. Until its first layout, they're the screen's, from `SystemInfo`.
- **iOS and Android send no mouse events**, so `document:mousemove` never runs there: listen for `pointermove`.
- **In the web preview**, they're the browser's own events inside the `<lynx-view>`, a mouse's included, and the size is the `<lynx-view>`'s. Key events are the page's.

## Each element's own events

The fields of each detail type are in its element's Events table.

### `<image>` and `<svg>`

| Event                                                                           | `$event`                      |
| ------------------------------------------------------------------------------- | ----------------------------- |
| `bindload`                                                                      | `LynxEvent<ImageLoadDetail>`  |
| `binderror` (`<image>`)                                                         | `LynxEvent<ImageErrorDetail>` |
| `bindstartplay`, `bindcurrentloopcomplete`, `bindfinalloopcomplete` (`<image>`) | `LynxEvent`                   |

See [`<image>`](/api/elements/image.md#events) and [`<svg>`](/api/elements/svg.md#events).

### `<text>`

| Event                 | `$event`                               |
| --------------------- | -------------------------------------- |
| `bindlayout`          | `LynxEvent<TextLayoutDetail>`          |
| `bindselectionchange` | `LynxEvent<TextSelectionChangeDetail>` |

See [`<text>`](/api/elements/text.md#events).

### `<input>` and `<textarea>`

| Event                                  | `$event`                          |
| -------------------------------------- | --------------------------------- |
| `bindinput`                            | `LynxEvent<InputDetail>`          |
| `bindfocus`, `bindblur`, `bindconfirm` | `LynxEvent<InputValueDetail>`     |
| `bindselection`                        | `LynxEvent<InputSelectionDetail>` |
| `bindbeforeinput`                      | `LynxEvent<BeforeInputDetail>`    |
| `bindkeyboardheightchange`             | `LynxEvent<KeyboardHeightDetail>` |
| `bindkeyboard`                         | `LynxEvent<KeyboardDetail>`       |
| `bindline` (`<textarea>`)              | `LynxEvent<TextareaLineDetail>`   |

See [`<input>`](/api/elements/input.md#events) and [`<textarea>`](/api/elements/textarea.md#events).

### `<scroll-view>`

| Event                                                                                                                                                                          | `$event`                  |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------- |
| `bindscroll`, `bindscrollend`, `bindscrolltoupper`, `bindscrolltolower`, `bindscrolltoupperedge`, `bindscrolltoloweredge`, `bindscrolltonormalstate`, `bindcontentsizechanged` | `LynxEvent<ScrollDetail>` |

See [`<scroll-view>`](/api/elements/scroll-view.md#events).

### `<list>`

| Event                                                  | `$event`                                 |
| ------------------------------------------------------ | ---------------------------------------- |
| `bindscroll`, `bindscrolltoupper`, `bindscrolltolower` | `LynxEvent<ListScrollDetail>`            |
| `bindscrollstatechange`                                | `LynxEvent<ListScrollStateChangeDetail>` |
| `bindlayoutcomplete`                                   | `LynxEvent<ListLayoutCompleteDetail>`    |
| `bindsnap`                                             | `LynxEvent<ListSnapDetail>`              |

`ListScrollDetail` adds `<list>`'s fields to `ScrollDetail`. `ListAttachedCell` and `ListItemInfo` are the types of its item arrays. See [`<list>`](/api/elements/list.md#events).

### Other elements

| Element                | Event                                                                 | `$event`                                   |
| ---------------------- | --------------------------------------------------------------------- | ------------------------------------------ |
| `<frame>`              | `bindload`                                                            | `LynxEvent<FrameLoadDetail>`               |
| `<frame>`              | `bindloadmetrics`                                                     | `LynxEvent<FrameLoadMetricsDetail>`        |
| `<overlay>`            | `bindshowoverlay`, `binddismissoverlay`, `bindrequestclose`           | `LynxEvent`                                |
| `<overlay>`            | `bindoverlaytouch`                                                    | `LynxEvent<OverlayTouchDetail>`            |
| `<overlay>`            | `binderror`                                                           | `LynxEvent<OverlayErrorDetail>`            |
| `<refresh>`            | `bindstartrefresh`                                                    | `LynxEvent<RefreshStartDetail>`            |
| `<refresh>`            | `bindheaderoffset`                                                    | `LynxEvent<RefreshHeaderOffsetDetail>`     |
| `<refresh>`            | `bindrefreshstatechange`                                              | `LynxEvent<RefreshStateChangeDetail>`      |
| `<scroll-coordinator>` | `bindoffset`                                                          | `LynxEvent<ScrollCoordinatorOffsetDetail>` |
| `<video>`              | `bindfirstframe`                                                      | `LynxEvent<VideoFirstFrameDetail>`         |
| `<video>`              | `bindtimeupdate`                                                      | `LynxEvent<VideoTimeUpdateDetail>`         |
| `<video>`              | `bindbuffering`                                                       | `LynxEvent<VideoBufferingDetail>`          |
| `<video>`              | `binderror`                                                           | `LynxEvent<VideoErrorDetail>`              |
| `<video>`              | `bindplaying`, `bindpaused`, `bindstopped`, `bindended`, `bindlooped` | `LynxEvent`                                |
| `<viewpager>`          | `bindchange`, `bindwillchange`                                        | `LynxEvent<ViewPagerChangeDetail>`         |
| `<viewpager>`          | `bindoffsetchange`                                                    | `LynxEvent<ViewPagerOffsetChangeDetail>`   |
| `<webview>`            | `bindload`                                                            | `LynxEvent`                                |
| `<webview>`            | `binderror`                                                           | `LynxEvent<WebViewErrorDetail>`            |
| `<webview>`            | `bindmessage`                                                         | `LynxEvent<WebViewMessageDetail>`          |
| `<webview>`            | `bindopenwindow`, `bindlocationchange`                                | `LynxEvent<WebViewUrlDetail>`              |

- **The other elements fire only the common events,** such as `<view>`, `<blur-view>` and `<list-item>`.

## Related

- [Handling taps and events](/guide/elements/event-handling.md)
- [Elements](/api/angular-lynx/elements.md): `LYNX_ELEMENTS`
- [Testing event reference](/api/testing-library/event-reference.md): firing these events in tests
