Agent-readable docs index: /effect-swiftui/llms.txt. Full docs in one file: /effect-swiftui/llms-full.txt. Download /effect-swiftui/docs.zip to grep all markdown files locally.

AppKit 0.2.x: Built-in controls

AppKit 0.2.x archive. This table describes the deprecated AppKit renderer. For the current controls, see the SwiftUI overview.
Inside a component’s 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.
ElementAppKit viewPropertiesEvents
h.stackVertical NSStackView, aligned to the leading edgeWorkspace layout propertiesNone
h.rowHorizontal NSStackView, aligned on the vertical centerWorkspace layout propertiesNone
h.labelRead-only NSTextFieldvalue: stringNone
h.buttonNSButtontitle: string; keyboard propertiespress — no payload
h.checkboxCheckbox-style NSButtontitle: string, checked: boolean; keyboard propertieschange — the new boolean state
h.sliderContinuous NSSlidervalue: number in [0, 1], accessibilityLabel: string; focusedchange — the new position in [0, 1]
h.pickerSingle-selection NSPopUpButtonoptions: readonly { value: string; title: string }[], value: string; focus propertieschange — the selected option’s value
h.textFieldNSTextFieldText propertiesedit, selectionChange, submit, focusChange
h.searchFieldNSSearchFieldSameSame
h.secureFieldNSSecureTextFieldSameSame
h.textAreaScrolling, plain NSTextViewSameSame

Place views and text

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.
view: (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 })) ) )
This 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.

Map a slider to a model value

The native slider has no 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:
h.slider .prop("accessibilityLabel", "Step size") .prop("value", (model.step - 1) / 9) .on("change", position => Message.ChangeStep({ position }))
In the 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.
Supplying 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.

Choose one option

h.picker.prop("accessibilityLabel", "Priority") .prop("options", [{ value: "low", title: "Low" }, { value: "high", title: "High" }]) .prop("value", model.priority) .on("change", value => Message.Priority({ value }))
Each option needs a unique 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.
There is no HTML 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.

Keyboard shortcuts and focus

Keyboard shortcuts and focus require version 0.2.0 or later of both the TypeScript adapter and the Swift host.
h.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.
All interactive built-ins accept 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.

Editable forms

Run 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.
h.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.
If 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.
Starting with 0.2.1, when the model normalizes the edited string, the host maps both UTF-16 selection endpoints using the unchanged prefix and suffix. A rejected edit restores its original selection; if the model later accepts that same edit, the host restores the edit’s selection.
A secure field masks the display, not your application's messages or model. Its handler receives the actual string. The example wraps it in 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.
Controls, labels and stacks accept 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.

What isn’t a control

There is no generic HTML tag, attribute, CSS, or browser event layer. Unsupported elements, properties, and event names are errors. For menus, navigation and desktop layouts, see native workspace views. For an app-owned AppKit or SwiftUI control, register a native leaf.

Native attributes and ref Commands

.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.
Declare 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.