Input
A single-line text input with caret, selection, and editing.
This demo runs the real GPUI component on WebGPU, which this browser does not expose.
Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.
You can also run it natively: cargo run -p showcase input
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase input
Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.
Recent phones with WebGPU may manage it (downloads ~18 MB):
#Anatomy
Import the component's parts and compose them under its root:
use base_gpui::input::{
Input,
};
Input::new();
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#Input
Text input integrated with the component's state and behavior.
use base_gpui::input::Input;
Input::new()
.with_field_context(/* context: FieldContext */)
.id("example-id")
.name("name")
.value(/* value: impl Into<SharedString> */)
.default_value(/* default_value: impl Into<SharedString> */)
.aria_label("aria label")
.placeholder("placeholder")
.disabled(true)
.read_only(true)
.required(true)
.auto_focus(true)
.tab_index(/* tab_index: isize */)
.tab_stop(true)
.focus_handle(/* focus_handle: FocusHandle */)
.on_edge_left(|/* callback arguments */| { /* handle change */ })
.on_edge_right(|/* callback arguments */| { /* handle change */ })
.select_all_on_focus(true)
.on_value_change(|/* callback arguments */| { /* handle change */ })
.on_enter(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a Input with its default configuration. |
.with_field_context | pub fn with_field_context(mut self, context: FieldContext) -> Self
Sets the with field context configuration for this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.name | pub fn name(mut self, name: impl Into<SharedString>) -> Self
Sets the form field name used when serializing or submitting the value. |
.value | pub fn value(mut self, value: impl Into<SharedString>) -> Self
Sets the current controlled value or the value represented by this part, depending on the part's role. |
.default_value | pub fn default_value(mut self, default_value: impl Into<SharedString>) -> Self
Sets the initial value for uncontrolled state. Later user changes are retained by the component. |
.aria_label | pub fn aria_label(self, aria_label: impl Into<SharedString>) -> Self
Sets the accessible name announced by assistive technology. There is no |
.placeholder | pub fn placeholder(mut self, placeholder: impl Into<SharedString>) -> Self
Sets the content shown when the component has no current value. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.read_only | pub fn read_only(mut self, read_only: bool) -> Self
When true, allows presentation and focus behavior without permitting value changes. |
.required | pub fn required(mut self, required: bool) -> Self
Marks the control as required for validation and accessibility state. |
.auto_focus | pub fn auto_focus(mut self, auto_focus: bool) -> Self
Controls whether auto focus behavior is enabled. |
.tab_index | pub fn tab_index(mut self, tab_index: isize) -> Self
Sets the tab index configuration for this part. |
.tab_stop | pub fn tab_stop(mut self, tab_stop: bool) -> Self
Overrides window Tab-order participation; composite containers such as the Toolbar use this to keep a single roving tab stop. |
.focus_handle | pub fn focus_handle(mut self, focus_handle: FocusHandle) -> Self
Overrides the input's focus handle so composite containers can own the control's roving focus handle. |
.on_edge_left | pub fn on_edge_left(mut self, on_edge_left: impl Fn(SharedString, &mut Window, &mut gpui::Context<InputRuntime>) -> bool + 'static,) -> Self
Consulted when a plain Left arrow is pressed with the caret at position 0 and no selection; returning |
.on_edge_right | pub fn on_edge_right(mut self, on_edge_right: impl Fn(SharedString, &mut Window, &mut gpui::Context<InputRuntime>) -> bool + 'static,) -> Self
Consulted when a plain Right arrow is pressed with the caret at the end of the text and no selection; returning |
.select_all_on_focus | pub fn select_all_on_focus(mut self, select_all_on_focus: bool) -> Self
Selects the whole text whenever the input gains focus. |
.on_value_change | pub fn on_value_change(mut self, on_value_change: impl Fn(SharedString) + 'static) -> Self
Registers a callback invoked when value change occurs. |
.on_enter | pub fn on_enter(mut self, on_enter: impl Fn(SharedString) + 'static) -> Self
Registers a callback invoked when enter occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(InputStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. Input also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#Accessibility
Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.
#Stability
Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.