view(h, model), use h to describe native elements. .children(...) sets layout order, .prop(key, value) writes a native property, and .on(name, handler) turns a native action into a component message.| Element | AppKit view | Properties | Events |
h.stack | Vertical NSStackView, aligned to the leading edge | Workspace layout properties | None |
h.row | Horizontal NSStackView, aligned on the vertical center | Workspace layout properties | None |
h.label | Read-only NSTextField | value: string | None |
h.button | NSButton | title: string; keyboard properties | press — no payload |
h.checkbox | Checkbox-style NSButton | title: string, checked: boolean; keyboard properties | change — the new boolean state |
h.slider | Continuous NSSlider | value: number in [0, 1], accessibilityLabel: string; focused | change — the new position in [0, 1] |
h.picker | Single-selection NSPopUpButton | options: readonly { value: string; title: string }[], value: string; focus properties | change — the selected option’s value |
h.textField | NSTextField | Text properties | edit, selectionChange, submit, focusChange |
h.searchField | NSSearchField | Same | Same |
h.secureField | NSSecureTextField | Same | Same |
h.textArea | Scrolling, plain NSTextView | Same | Same |
stack and row accept a string child directly, or use h.label.prop("value", text) explicitly. Both place children in the order you supply them, with 8 points between neighbors by default. Other native containers and layout knobs are in the workspace reference.12345678view: (h, model) => h.stack.children( "Native Effect counter", h.row.children( h.button.prop("title", `Count: ${model.count}`).on("press", Message.Count()), h.checkbox.prop("title", "Count down").prop("checked", model.down) .on("change", down => Message.ChangeDirection({ down })) ) )
view can replace the one in src/counter.ts. A press sends the same Count message every time; a checkbox change builds a message using the value AppKit reports. Neither event is a DOM event or supports preventDefault.min, max, or step property in this vocabulary. In the AppKit counter, the model uses whole-number steps from 1 to 10. Convert in both directions:1234h.slider .prop("accessibilityLabel", "Step size") .prop("value", (model.step - 1) / 9) .on("change", position => Message.ChangeStep({ position }))
ChangeStep update, 1 + Math.round(position * 9) turns the incoming position back into a step. For example, 0 means step 1, and 1 means step 10. AppKit sends changes while the user drags, not just when they let go. Use a descriptive accessibility label even when a nearby text field displays the numeric value.checked on a checkbox or value on a slider makes that input controlled: the model determines the displayed state. If update ignores a change, the renderer restores the model’s value; keep the new input by returning the corresponding model change. A slider value outside [0, 1] is an error, not a request to clamp it.1234h.picker.prop("accessibilityLabel", "Priority") .prop("options", [{ value: "low", title: "Low" }, { value: "high", title: "High" }]) .prop("value", model.priority) .on("change", value => Message.Priority({ value }))
value; its title is the text AppKit displays. A model value with no matching option clears the selection. Omit value to let AppKit own the selection. For a controlled picker, checkbox, or text input, ignoring the event (including returning undefined) or omitting the handler restores the model value after the event, even when there is no render.form.reset() equivalent here: AppKit has no form element, default-value attributes, or reset event. Implement a Reset button or shortcut that sends a message setting your model’s values; the renderer updates the native controls from that model.1234h.button.prop("title", "Save") .prop("keyboardShortcut", { key: "return" }) .prop("focused", model.editing) .on("press", Message.Save())
keyboardShortcut on h.button and h.checkbox sets a native key equivalent for the window. It sends the same press or change message as a click. Use a lowercase letter, digit, "return", "escape", or "space"; optional modifiers are "command", "option", "control", and "shift". Omitted modifiers mean none. For example, { key: "i", modifiers: ["command"] } is ⌘I. Omit the property to remove the shortcut. Avoid conflicts with the app’s menus and other controls; this is not a global hotkey.focused on a button, checkbox or slider requests first responder when it becomes true, including on initial mount. A user can then move focus without an unrelated render taking it back. Changing it to false or removing the property cancels the request and releases focus only if that control owns it. To request focus again, transition from false to true. It is a request, not a report of which control is currently focused.focused, report .on("focusChange", focused => ...) when first-responder ownership changes, and accept disabled. A field's window-owned editor counts as focus on that field. Unranked controls follow native Tab and Shift-Tab navigation and macOS Keyboard Navigation preferences. To change the order of particular controls within a surface, give each a distinct integer tabOrder: AppKit visits their existing key-view slots in ascending rank. Other controls keep their slots.bun run demo:form for the complete TS-only example. Tab from Name to Access code, Shift-Tab back; enter a name, press Return to save, and Escape to reset. Locking the form leaves the name and notes selectable but read-only and disables search.1234h.textField.prop("value", model.name).prop("placeholder", "Contact name") .prop("accessibilityIdentifier", "name").prop("accessibilityLabel", "Contact name") .on("edit", ({ value, selection, composing }) => Message.Name({ value, composing })) .on("submit", Message.Save())
edit carries { value: string, selection: { start, end }, composing: boolean }. Offsets are UTF-16, the units of String.slice, with an exclusive end. .on("selectionChange", ...) reports the same range when the user moves the caret or selects text. Set selection to request a range; it is clamped to the text length and waits for an editor if necessary. Do not bind a new selection on each redraw unless you intend to move it.value is present, accept an edit by returning the new string in your model. Leaving the model unchanged restores the previous value and selection. Avoid final validation while composing is true: marked text belongs to the system input method. The host leaves it alone and reconciles after the final unmarked edit. readOnly prevents typing but allows selection and copy where the native control permits it; disabled removes interaction. placeholder is a hint, not a replacement for a label. submit carries the current string on Return in single-line fields; Return inserts a newline in textArea, and ⌘Return submits it.Redacted.make(value) before creating the edit message, uses Schema.RedactedFromValue(Schema.String) in both the message and model schemas, and calls Redacted.value only to set the native field's value. The MessageLog wire encoder then replaces both occurrences with redaction markers. Never log the raw edit payload; redaction is not encryption or memory erasure.accessibilityLabel, accessibilityHelp, and accessibilityIdentifier. An identifier is for automation, not spoken guidance. accessibilityGroup: true on stack or row exposes an AX group containing its native children. Give it a descriptive label; don't replace the native role on an input. For a VoiceOver check, start VoiceOver, navigate to the Contact details group, interact with it, and verify the named text field, search field, secure text field and notes are reachable and announce their native roles. Automated tests inspect AppKit accessibility values, not synthesized speech..attr("data-testid", id) sets the AppKit view’s identifier, .attr("accessibilityIdentifier", id) sets its accessibility identifier, and .attr("toolTip", text) sets its native tooltip. This includes attributes forwarded by a part and attributes on registered views. Omit the attribute (or pass undefined) to clear it. These are three independent fields. Other attributes, including style, class, arbitrary aria-* and data-*, are renderer errors. Unrecognized events and preventDefault: true or "always" on target/action events also fail at bind time and can reach the component’s fallback. Omitting preventDefault or passing false is supported. Native actions do not bubble or expose a cancellable DOM event.const editor = ref("editor") once and attach .ref(editor) to an element. Command.map(Measure.make({ ref: editor }), rect => Message.Measured({ rect })) delivers its attached view’s bounding box in surface-local AppKit points, with the origin at the lower left. null means the ref was absent or detached. Focus, Blur and ScrollIntoView use the same { ref } argument; they report a boolean, not a synthetic event. Focus/blur require the view to take/own first responder, and reveal requires an enclosing NSScrollView. Lookup is instance-local and waits for the issuing update’s commit. A custom Command.make can also require the installed AppKit Effect service directly.