Handling Actions
Process user interactions with action handlers.
Actions & Reactive Behavior
a2ui-shadcn provides two reactive flows: two-way data binding for inputs and event actions for buttons and links.
How a2ui-shadcn Handles Reactivity & Actions
Two reactive flows: instant local updates (inputs) and agent-bound actions (buttons)
Two-Way Binding (Inputs)
User Actions (Buttons, Links)
- Path bindings:
{ path: "/key" }- resolved to current data model value - FunctionCall:
{ call: "formatDate", args: {...} }- executed and result included in context - sendDataModel: When enabled in createSurface, full data model sent with every action
These are live, interactive examples. Type in the inputs and click buttons to see how a2ui-shadcn handles reactivity and actions.
Two-Way Data Binding
As you type, the data model updates immediately and the Text component below re-renders with the new value (no server round-trip).
Action with Context Resolution
Fill the form and click Submit. The button's context (with path bindings) is resolved to current values and sent via onAction.
Two-Way Binding: Input components (TextField, CheckBox, Switch, Slider, ChoicePicker) use value or checked with { "path": "/key" }. When the user types or toggles, dataModel.set(path, value) runs immediately. The store notifies subscribers, and any component bound to that path (e.g. Text with text: { "path": "/key" }) re-renders with the new value. No server round-trip is needed for live updates.
User Actions: Buttons and links with action: { event: { name, context } } resolve context path bindings to current values at click time, then call onAction with the resolved data. When using transports (WebSocket, SSE), actions are sent to the agent. The agent can respond with updateDataModel or updateComponents to update the UI.
Action Structure
Basic Handler
Form Actions
Handler:
Context Resolution
When a button is clicked, all context values are resolved before calling onAction. Resolution happens recursively:
Path Bindings: { "path": "/user/email" } - current value from data model
Nested Objects: Entire object structure is resolved recursively
FunctionCall: { "call": "formatDate", "args": {...} } - function executed, return value used
Resolved context sent to onAction:
sendDataModel
Enable sendDataModel: true in createSurface to automatically include the full data model with every action:
Action payload will include dataModel:
This is useful when the agent needs the full UI state alongside the user's action.
Context Functions
Register functions that return values for use in action context:
Agent uses in button context:
Client-Side Action Functions
For local actions (no server round-trip), use action.functionCall:
Agent triggers:
Note: Use "call" not "name" for functionCall (A2UI v0.9 spec).
Live Examples
Try these in the Playground:
- Two-Way Binding: See
TextFieldupdateTextin real-time - Reactive Flow Demo: Type and click "Submit" to see context resolution
- sendDataModel: Enable in
createSurface, check action log's "dataModel" field - Context Functions: See
formatDateresolve timestamp when button clicked - Nested Context: Complex nested objects with path bindings