Forms

Text Field

A composition-friendly field with label and validation.

Rust
1use herogpui::components::input::TextField;

Usage

Rust
1use herogpui::prelude::TextField;
2
3TextField::new(self.text_field_state.clone())
4    .label("Full name")
5    .placeholder("Ada Lovelace")
6    .description("As it appears on your ID.")

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

TextFieldInput

Text Field is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Text Field uses.

Styling

Text Field styling
StyleDescription
Input wrapper flex_col + gap(4px)Root field stack uses the four-pixel gap.
validity-first description branchThe validation message replaces helper text instead of stacking with it.
12px helper text without px-1Helper and error text use pinned typography and colour; does not add horizontal inset.

API reference

Builders

Text Field builders
BuilderTypeDefaultDescription
content(render)AnyElement | Fn(values: TextFieldRenderProps) -> AnyElementReplacement content receives disabled, invalid, read-only, required and complete focus state.
full_width()boolfalseStretches the root and inner control to the available width.
new(state)stateThe caller-owned InputState entity supplies stable GPUI identity instead of a element id.
is_required(bool)boolfalseMarks the field required for native form validation.
is_invalid(bool)boolForces invalid field chrome and error state.
validate(callback)Fn(value: string) -> ValidationError | true | nullA callback returns one optional validation message.
validation_behavior(ValidationBehavior)ValidationBehaviorValidationBehavior::NativeSelects blocking native validation or non-blocking ARIA-style validation.
validation_errors(errors)errorsServer messages take precedence over custom validation.
default_value(text)textSeeds the uncontrolled InputState once.
on_change(callback)Fn(value: string) -> ()Reports each accepted edit without duplicate reports for rejected edits.
is_disabled(bool)boolfalseRemoves focus and editing and applies disabled opacity.
is_read_only(bool)boolfalseKeeps focus and selection while suppressing edits.
name(text)textSubmission name stored with the current field value.
auto_focus(bool)boolfalseFocuses the inner input on its first render.

Parts

Text Field parts
PartDescription
TextFieldRoot field state and vertical composition.
TextFieldOptional label rendered before the editable control.
InputSingle-line InputState-backed editable control.
TextFieldMulti-line field composition is supplied by the sibling TextArea component.
TextFieldHelper message shown while the field is valid.
TextFieldValidation or server message replacing the description while invalid.

States

Text Field states
BuilderStateDescription
resolved Input validityInvalidHides the description and shows the field error.
is_disabled(bool)DisabledApplies disabled opacity and removes focus and editing.
TextFieldRenderState::is_focus_withinFocus withinReplacement content receives focus-within while the inner input owns focus.
TextFieldRenderState::is_focus_visibleFocus visibleReplacement content receives keyboard-visible focus state.