$ rezi
Widgets

Button

An interactive widget that can receive focus and be activated by pressing Enter, Space, or clicking.

An interactive widget that can receive focus and be activated by pressing Enter, Space, or clicking.

Usage

ui.button({ id: "save", label: "Save" })
ui.button({ id: "delete", label: "Delete", disabled: true })
ui.button({
  id: "submit",
  label: "Submit",
  onPress: () => handleSubmit(),
})

Props

PropTypeDefaultDescription
idstringrequiredUnique identifier for focus and event routing
labelstringrequiredButton text
accessibleLabelstring-Optional semantic label for focus announcements and debugging
disabledbooleanfalseDisable interaction and dim appearance
pxnumber1Horizontal padding in cells
styleTextStyle-Custom styling (merged with focus/disabled state)
onPress() => void-Callback when button is activated
keystring-Reconciliation key for dynamic lists

Behavior

Buttons are focusable when enabled. They can be activated by keyboard or mouse:

  • Enter or Space activates the button
  • Mouse click focuses and activates the button (press down + release on the same button)
  • Tab moves focus to the next focusable widget
  • Shift+Tab moves focus to the previous focusable widget

The onPress callback fires regardless of whether the button was activated by keyboard or mouse. Buttons can be handled either via callback props or in a global app.onEvent handler.

Examples

ui.button({
  id: "inc",
  label: "+1",
  onPress: () => app.update((s) => ({ count: s.count + 1 })),
})

Global event handler

app.onEvent((ev) => {
  if (ev.kind === "action" && ev.id === "save" && ev.action === "press") {
    handleSave();
  }
});

Styling

import { rgb } from "@rezi-ui/core";

ui.button({
  id: "danger",
  label: "Delete",
  style: {
    fg: rgb(255, 100, 100),
    bold: true,
  },
})

The button's focus and disabled states are automatically applied and merged with custom styles.

On this page