Language
Behavior
Handlers react to abstract inputs, update local state and emit typed events. Controlled values stay with the host.
Handlers
on "<input>" reacts to an abstract input. when guards it; emit sends an event.
on "activation" {
when = !prop.disabled
emit = event.activate
}
Inputs are intents, not device gestures: activation covers a pointer click, the keyboard
and an assistive-technology press. So a component that handles it must be operable without a
pointer: it has an interactive role (button, link, checkbox, …), or it is a
focus stop with a role, which Space and Enter activate on the targets (DSF-A008, D-058).
An option, tree item, menu item or tab that is no stop is operated by its owner: it must sit
in a listbox, tree, menu or tablist that takes focus or names it as its active descendant
(DSF-A008, D-064). Keys reach the focused stop only, and go from it outward to the first
component with a handler of that key and those modifiers; a handler of Shift+ArrowLeft lets
a plain ArrowLeft through (D-064). Tab and Shift+Tab are distinct keys: a component that
takes both, or takes one around an instance that takes the other, traps keyboard focus
(DSF-A009). The 0.1 inputs are activation, focus, blur, dismiss,
increment, decrement, key (with key = "Escape"…), text_change and submit; a
pointer drag delivers drag_start, drag_change and drag_end (handlers read
input.position and input.translation), and a named accessibility action delivers
action (D-052).
A handler may be scoped to one node of the view with target = "<node>": it then matches
only an input delivered at that node, such as a press on it or a key while it holds focus, and
it runs before the untargeted handlers. A split view scopes its keys and drags to its
separator, so arrow keys pressed in a pane stay with the pane’s content.
A handler moves focus with focus = "<node>". A stack or overlay can delegate its focus
to a node it holds with focus_target = "<node>": focus directed at it lands there, and a
press on it outside its own controls (a label, the padding of a field’s chrome) moves focus
there, as a label does for its field. On the view root, focusing the component focuses that
node (D-056).
stack "chrome" {
padding = insets(dp(6), dp(10))
focus_target = "input"
text_input "input" {
value = prop.value
}
}
Key names are the web’s KeyboardEvent.key values ("Enter", "ArrowUp", "Home", " ",
"a"). A handler may name "ArrowInlineStart" or "ArrowInlineEnd", the arrow at the start
or the end of the line in the component’s direction: ArrowInlineEnd is the right arrow left to
right and the left arrow right to left, so one handler serves both directions. Examples press
physical keys (D-052).
Events with payloads
event "change" {
payload = {
value = enum(["unchecked", "checked"])
}
}
on "activation" {
when = !prop.disabled
emit "change" {
value = prop.checked == "checked" ? "unchecked" : "checked"
}
}
The payload is type-checked against its declaration (DSF-B002).
Controlled properties
property "checked" {
type = enum(["unchecked", "checked", "mixed"])
binding = "controlled"
description = "Host-owned value. The component reads it and never assigns it."
}
A controlled property belongs to the host. The component never writes it: it emits a
request (change) and the host decides. Generators may offer a two-way convenience
(a SwiftUI Binding, an Angular model()), always initiated by the host.
Local state
A handler may update local state with set { name = value }. Assigning a property or an
interaction-derived state is DSF-B005.
Checks
| ID | Caught at compile time |
|---|---|
DSF-B001 |
Unknown input. |
DSF-B002 |
Undeclared event, or payload of the wrong type. |
DSF-B003 |
Activation handler reachable while the component is disabled. |
DSF-B004 |
Two equal-priority handlers for one input that can both match. |
DSF-B005 |
Assignment to a property or a read-only state. |
When several handlers match, the one with the highest priority runs. Example tests assert
the emitted events: see Examples and rules.