Input
A single-line text input for entering and editing short text. The first stateful component in Synth UI — GPUI 0.2.2 has no built-in text-input element, so Input manages its own focus, selection, and key bindings.
When to use
- Collecting a single line of text (names, emails, search queries).
- As the building block for forms and filters.
API
Input::new(cx)
Creates an input and binds its editing key bindings (backspace, delete, arrow keys, shift-arrow selection, cmd-a/v/c/x, home/end).
| Method | Type | Description |
|---|---|---|
.placeholder(text) | impl Into<SharedString> | Placeholder shown while empty |
.value() | SharedString | The current value |
.error(bool) | bool | Show a red border for validation errors (kept while focused) |
Usage
Input is stateful, so it is created as an Entity and dropped into your view tree:
rust
use gpui::{div, prelude::*};
use components::Input;
let input = cx.new(|cx| Input::new(cx).placeholder("Type here..."));
// in render:
div().child(input.clone())To show the live value, observe the input and re-render:
rust
cx.observe(&input, |_, _, cx| cx.notify()).detach();Copy the source
crates/components/src/input.rs — self-contained and free to modify.