Native editing#

The native provider connects an Editor for text, selection and IME.

Enable JavaScript to run the preview. Go source and install commands remain available.

Usage
name := tree.ID(page, "name")
f.Input(components.InputSnapshot{
    ID: name, Label: "Name", Value: value,
    Placeholder: "Type in Chinese or English…",
})

Empty field#

Empty values show a placeholder; native focus provides the caret.

Enable JavaScript to run the preview. Go source and install commands remain available.

Usage
f.Input(components.InputSnapshot{
    ID: tree.ID(page, "name"), Label: "Name", Value: "",
    Placeholder: "Type in Chinese or English…",
})

Validation state#

Demo rule: any nonempty value containing @ clears the error.

Enable JavaScript to run the preview. Go source and install commands remain available.

Usage
invalid := value == "" || !strings.Contains(value, "@")
f.Input(components.InputSnapshot{
    ID: tree.ID(page, "email"), Label: "Email", Value: value,
    Placeholder: "name@example.com", Invalid: invalid,
})

Disabled and read-only#

Fixed examples never expose an editor to the native provider.

Enable JavaScript to run the preview. Go source and install commands remain available.

Usage
f.Input(components.InputSnapshot{
    ID: tree.ID(page, "disabled"), Label: "Disabled",
    Value: "Not editable", Disabled: true,
})
f.Input(components.InputSnapshot{
    ID: tree.ID(page, "read-only"), Label: "Read-only",
    Value: "Viva · read-only text", ReadOnly: true,
})

Installation

Copy the recipe into your own project.

Repository command
go run ./cmd/viva add --out ./components/local input

Text stays with the application#

PaintInput paints a field snapshot and its hit region. Web and native text bridges connect to the same caller-owned Go editor, which retains text, selection and composition while each platform supplies text-system events.

  • Only hide the static label while the field actually owns platform editing focus.
  • On blur, publish the current editor value as a label in the same frame that disables the platform editor.
  • InputSnapshot selection offsets are UTF-8 byte offsets for painting; platform text-event ranges are rune indices. Do not interchange them.

Editing & limitations#

The Web and native examples handle insertion, Backspace/Delete, Left/Right, Shift+Left/Right and composition through the same Go editor. macOS also delivers click placement, drag selection and Command-A.

  • Single-line Tab changes focus; it does not insert a tab character.
  • Read-only and disabled examples do not enable a platform editor.
  • Browser and desktop bridges differ only in event transport; application text state remains shared Go state.
  • Platform-specific clipboard shortcuts, undo/redo and multiline editing require separate backend verification.

Keyboard

Use Tab to move between controls and Ctrl/⌘ K to search the catalog. Inside a preview, the Go runtime handles keyboard input.