Binders & events¶
A component template may use this complete shorthand vocabulary. Every token is compiled. None is interpreted at runtime.
Events¶
| Event | Fires on | Notes |
|---|---|---|
@click |
click | allowed everywhere (incl. :each rows) |
@dblclick |
double click | allowed everywhere |
@submit |
form submit | preventDefault() applied; sends the form's fields with a command: the idiomatic submit (never @click on a button whose default type=submit would reload) |
@reset |
form reset | allowed everywhere (incl. :each rows). Fires on a type="reset" button, and on data-reset after a successful command, so @reset="open = False" closes a form on both |
@input |
input | allowed everywhere; pairs with :bind for validate-as-you-type. On an element holding no field, a CompileError |
@escape |
Esc keydown | allowed everywhere |
@pointerdown |
pointer pressed | allowed everywhere |
@clickout |
click outside the element | top-level only |
@commit |
a :combobox commits an option |
top-level only |
@change, @keydown, @keyup, @focus, @blur, @scroll, @mouseenter and others |
that DOM event | allowed everywhere. The list is closed, as a misspelt event would never fire: @paste, @wheel, @drop, @contextmenu and the rest are in DOM_EVENTS |
Any event but @escape, @clickout and @commit takes the modifiers .stop and .prevent, with or without an action: @click.stop on a row's controls keeps their clicks from the row's own @click, and @pointerdown.prevent on a button keeps the focus or text selection where it was. On another event, or a component's, they are a CompileError.
@keydown and @keyup also take a key, and what they hold with it: @keydown.enter, @keydown.arrowup, @keydown.ctrl.enter. .enter, .escape, .tab, .space, .backspace, .delete, .home, .end, .pageup, .pagedown, the four arrows, .ctrl, .shift, .alt and .meta are the ones it knows. One element can have several, one per key, and .stop and .prevent only apply to the key they are written with. A key held does not exclude others: @keydown.enter fires on Ctrl+Enter too.
An action can read the DOM event as event: @change="pick(event.target.value)", @keydown="last = event.key". A signal or a local named event comes first. It is not available in binders, or in a handler's body, which takes what it needs as parameters. event.target.value and event.key are text, and event.target.checked is a bool, so a number signal takes int(event.target.value) or float(...): storing the text in a Local[int] is a CompileError, as is storing a field of the event situ gives no type.
A click bubbles through nested rows, so on a :tree a row's @click also fires on each of its ancestors, outermost last. Use @click.stop for the deepest row alone to answer.
The value is an action program: ;-separated signal = expr assignments and handler calls. See Handlers & commands.
Core binders¶
| Binder | Meaning | Constraint |
|---|---|---|
:text="expr" |
textContent tracks the expression |
|
:show="expr" |
element hidden unless truthy; focuses a child [autofocus] on reveal; add data-transition to cross-fade on show/hide (View Transitions API, progressive) |
|
:class="name: expr" |
toggle one class on a condition | repeat it for several classes on one element |
:attr="name: expr" |
set/remove an attribute (False/None removes; True → empty attr) |
repeat it for several attributes on one element |
:bind="signal" |
two-way input binding; type=number inputs coerce to JS numbers; the focused field is never repainted mid-keystroke |
the signal must be Local |
:each="row in coll" |
the keyed client list reconciler | coll is a Local[list] (or an enclosing row's field); binders and events on the same element compile against its row |
:tree="row.children" |
self-recursive row template (recursive lists, comment threads) | inside a :each |
:autohide="signal" |
clear a status signal back to its default after ~4 s |
Inside a :each row¶
Row-scoped binders compile against the row object: :text/:show/:class/:attr/:bind all work with t.field reads; @clickout and @commit are the events they cannot have. A row's identity is its id field (reconciliation is keyed on it). Server-rendered rows expose fields to the client through data-* attributes. t.field in a binder on a data-id row reads the row's dataset. Such a row must declare its type: data-row="<Record>" on the row element plus a matching TypedDict in the .py, so each DOM string is decoded to its real type (an integer id, a boolean flag). Every field a binder reads must be in the record and shipped as data-<field>; an undeclared client-read row is a CompileError. (declui derives the record from your model; the unified idiom's named projection ~ Record[…] is the same declaration.)
An element in a row authored hidden with a :show keeps its content out of the row until it is first shown, so a long list with an edit form in each row stays light. Once shown, the content stays, with what is typed in it. This does not apply inside a form, whose submit sends all its fields, or to an element that also has :tree, :text or :bind.
Transport binders¶
| Binder | Meaning | Requires |
|---|---|---|
:virtual="handler(scroll)" |
a windowed viewport: only the visible rows in the DOM, fetched from the mount's /window route |
a server handler + a Local scroll signal; mount_component(window_template=...) |
Widget binders (kit-internal wiring)¶
Policy: an interactive kit widget is a component; the binder below is its internal wiring. Each self-contained widget ships as a situ_ui component (<Tabs>, <DataTable>, <DataGrid>, <Combobox> / <ComboboxMulti>, <Menu>, <CommandPalette>). The component is how you use it; the kit catalog is the canonical reference. The raw binder is the escape hatch for a bespoke host that can't splice a component (declui's codegen emits one directly, for instance). Either way the runtime holds only presentation state, leaving your data and selection in Locals.
| Binder | Component (use this) | App-owned state |
|---|---|---|
:tabs |
<Tabs> |
none (bar generated from data-tab panels) |
:table="rows" |
<DataTable> |
Local[list]; header-click sort |
:datagrid="rows" + :datagridsel="sel" |
<DataGrid> |
Local[list] + Local[set]: sort + filter + pagination + selection |
:combobox="value" |
<Combobox> / <ComboboxMulti> (multi via data-multi) |
Local[str] / Local[set] |
:menu |
<Menu> |
none (items keep their compiled @click) |
:palette |
<CommandPalette> |
none (⌘K overlay) |
The other two runtime binders have no self-contained component. You compose them onto your own markup (like :each), so they stay first-class author binders:
| Binder | Meaning | App-owned state |
|---|---|---|
:sortable="list" |
pointer drag-reorder over a :each list (<Sortable> is a thin convenience wrapper) |
Local[list] |
:cells="grid" |
the spreadsheet formula engine: the one sanctioned runtime interpreter for user-typed formulas | Local[dict] |
The island feature-detects each runtime (S.tabs && S.tabs(el)), so pages that don't load widgets.js are unaffected.
The unified idiom (opt-in)¶
With mount_component(..., unified=True):
| Construct | Meaning |
|---|---|
{ expr } |
one interpolation: server-rendered or live, derived from the expression's sites |
:each="t in coll ~ [f1, f2]" |
the loop with its wire projection: the complete per-row field list allowed to cross to the browser; anything else is a CompileError |
See The unified idiom.