on: Event handlers

View source: R/bindings.R

onR Documentation

Event handlers

Description

on() creates an event handler that can be passed to app() together with the widgets. It is equivalent to calling app$on().

Usage

on(type, selector = NULL, handler)

Arguments

type

Event type such as "button.pressed", "input.submitted", "key", "resize", "focus" or "mount". "*" matches any type.

selector

Optional selector (e.g. "#hello", ".danger", "Button") matched against the sender (for key and mouse events: the widget the event was sent to).

handler

⁠function(event, app)⁠.

Details

The handler runs when an event of the given type reaches the app and, if a selector is given, the widget that sent the event matches it.

Value

An object of class termr_handler.

Examples

on("button.pressed", "#hello", function(event, app) {
  app$query_one("#output")$update("Hello!")
})

termr documentation built on Oct. 21, 2026, 5:13 p.m.