Skip to main content

TextInput

Struct TextInput 

Source
pub struct TextInput {
Show 85 fields pub id: Option<NodeId>, pub value: String, pub label: Option<TextContent>, pub placeholder: Option<TextContent>, pub helper_text: Option<TextContent>, pub error_text: Option<TextContent>, pub counter_text: Option<TextContent>, pub on_change: Option<ActionEnvelope>, pub on_submit: Option<ActionEnvelope>, pub on_editing_complete: Option<ActionEnvelope>, pub on_tap_outside: Option<ActionEnvelope>, pub width: Option<f32>, pub height: Option<f32>, pub size: ComponentSize, pub padding: Option<[f32; 4]>, pub multiline: bool, pub autofocus: bool, pub enabled: bool, pub read_only: bool, pub min_lines: Option<usize>, pub max_lines: Option<usize>, pub obscure_text: bool, pub obscuring_character: char, pub mask: Option<InputMask>, pub styled_runs: Option<Vec<TextRun>>, pub borderless: bool, pub capture_tab: bool, pub auto_indent: bool, pub on_cursor_change: Option<ActionEnvelope>, pub highlight_ranges: Vec<(usize, usize, Color)>, pub background_fill: Option<Fill>, pub border_color: Option<Color>, pub focus_border_color: Option<Color>, pub border_width: Option<f32>, pub focus_border_width: Option<f32>, pub border_radius: Option<f32>, pub font_size: Option<f32>, pub text_color: Option<Color>, pub placeholder_color: Option<Color>, pub label_color: Option<Color>, pub helper_color: Option<Color>, pub error_color: Option<Color>, pub counter_color: Option<Color>, pub selection_color: Option<Color>, pub selection_text_color: Option<Color>, pub text_align: TextAlign, pub text_align_vertical: TextAlignVertical, pub expands: bool, pub cursor_color: Option<Color>, pub cursor_width: Option<f32>, pub cursor_height: Option<f32>, pub cursor_radius: Option<f32>, pub font_family: Option<String>, pub locale: Option<String>, pub font_weight: Option<u16>, pub font_style: TextFontStyle, pub text_scale: Option<f32>, pub line_height: Option<f32>, pub letter_spacing: Option<f32>, pub text_direction: TextDirection, pub strut_line_height: Option<f32>, pub text_height_behavior: TextHeightBehavior, pub prefix: Option<Box<Node>>, pub suffix: Option<Box<Node>>, pub mouse_cursor: Option<MouseCursor>, pub keyboard_type: TextInputType, pub text_input_action: TextInputAction, pub text_capitalization: TextCapitalization, pub max_length: Option<usize>, pub max_length_enforcement: MaxLengthEnforcement, pub input_formatters: Vec<InputFormatter>, pub autocorrect: bool, pub enable_suggestions: bool, pub spell_check: bool, pub smart_dashes: bool, pub smart_quotes: bool, pub autofill_hints: Vec<String>, pub scroll_padding: Option<[f32; 4]>, pub drag_start_behavior: DragStartBehavior, pub context_menu: TextContextMenuConfig, pub selection_controls: TextSelectionControls, pub magnifier_configuration: TextMagnifierConfiguration, pub undo_controller: Option<TextUndoController>, pub spell_check_configuration: Option<SpellCheckConfiguration>, pub restoration_id: Option<String>,
}
Expand description

An editable text field with support for single-line and multiline input, syntax highlighting, password masking, and IME composition.

TextInput is the primary text-editing widget. It manages its own scroll container, caret, selection, and (when styled_runs is provided) multi-colour syntax-highlighted rendering.

§Example

let on_change = ctx.bind(TextChanged { .. }, reduce_with!(handle_text));

TextInput {
    value: view.state.query.clone(),
    placeholder: Some("Search...".into()),
    on_change: Some(on_change),
    ..Default::default()
}

§Code editor mode

For embedding in a code editor, enable borderless, capture_tab, auto_indent, and provide styled_runs for syntax highlighting:

TextInput {
    value: source_code.clone(),
    multiline: true,
    borderless: true,
    capture_tab: true,
    auto_indent: true,
    styled_runs: Some(highlighted_runs),
    ..Default::default()
}

Fields§

§id: Option<NodeId>

Explicit node identity (used for focus tracking and scroll state).

§value: String

The current text value (controlled by the application).

§label: Option<TextContent>

Optional label shown above the field.

§placeholder: Option<TextContent>

Placeholder text shown when value is empty.

§helper_text: Option<TextContent>

Optional supporting text shown below the field when there is no error.

§error_text: Option<TextContent>

Optional validation error shown below the field.

§counter_text: Option<TextContent>

Optional explicit counter text shown below the field.

§on_change: Option<ActionEnvelope>

Action dispatched when the text changes.

§on_submit: Option<ActionEnvelope>

Action dispatched when the user submits the field (for example by pressing Enter on a single-line input).

§on_editing_complete: Option<ActionEnvelope>

Action dispatched when editing is explicitly completed.

§on_tap_outside: Option<ActionEnvelope>

Action dispatched when the user taps/clicks outside the active field.

§width: Option<f32>

Fixed width in layout points.

§height: Option<f32>

Fixed height in layout points.

§size: ComponentSize

Design-system size slot.

§padding: Option<[f32; 4]>

Custom content padding [left, right, top, bottom].

§multiline: bool

When true, the input accepts newlines and scrolls vertically.

§autofocus: bool

When true, the input requests focus automatically when mounted.

§enabled: bool

When false, the field is non-interactive and does not receive focus.

§read_only: bool

When true, the field can be focused and selected but not edited.

§min_lines: Option<usize>

Minimum number of visible lines (multiline only).

§max_lines: Option<usize>

Maximum number of visible lines (multiline only).

§obscure_text: bool

When true, display each grapheme as obscuring_character (password mode).

§obscuring_character: char

The character used when obscure_text is true (default: '•').

§mask: Option<InputMask>

Structural input mask (e.g. phone number, date).

§styled_runs: Option<Vec<TextRun>>

Pre-styled text runs for syntax highlighting.

When provided and no selection is active, these runs are rendered instead of the default single-colour text. The concatenated text of all runs must match value exactly.

§borderless: bool

When true, the background rect and border are omitted (for embedding in editor chrome).

§capture_tab: bool

When true, the Tab key inserts whitespace instead of moving focus.

§auto_indent: bool

When true, pressing Enter copies the leading whitespace of the current line (auto-indentation).

§on_cursor_change: Option<ActionEnvelope>

Action dispatched when the caret or selection anchor changes.

§highlight_ranges: Vec<(usize, usize, Color)>

Ranges to highlight in the text (e.g. find-match results).

Each entry is (start_byte, end_byte, background_color).

§background_fill: Option<Fill>

Optional fill override for the field background.

§border_color: Option<Color>

Optional border color override when not focused.

§focus_border_color: Option<Color>

Optional border color override when focused.

§border_width: Option<f32>

Optional border width override when not focused.

§focus_border_width: Option<f32>

Optional border width override when focused.

§border_radius: Option<f32>

Optional corner radius override.

§font_size: Option<f32>

Optional font size override.

§text_color: Option<Color>

Optional text color override.

§placeholder_color: Option<Color>

Optional placeholder color override.

§label_color: Option<Color>

Optional label color override.

§helper_color: Option<Color>

Optional helper/supporting text color override.

§error_color: Option<Color>

Optional error text color override.

§counter_color: Option<Color>

Optional counter text color override.

§selection_color: Option<Color>

Optional selection highlight color override.

§selection_text_color: Option<Color>

Optional selected text color override.

§text_align: TextAlign

Horizontal text alignment inside the editable region.

§text_align_vertical: TextAlignVertical

Vertical alignment for the editable region when the field is taller than its content.

§expands: bool

When true, expand to fill the available height from the parent.

§cursor_color: Option<Color>

Optional caret color override.

§cursor_width: Option<f32>

Optional caret width override.

§cursor_height: Option<f32>

Optional caret height override.

§cursor_radius: Option<f32>

Optional caret corner radius override.

§font_family: Option<String>

Optional font family override.

§locale: Option<String>

Optional locale override used for shaping and accessibility.

§font_weight: Option<u16>

Optional font weight override.

§font_style: TextFontStyle

Optional font style override.

§text_scale: Option<f32>

Optional text scale multiplier.

§line_height: Option<f32>

Optional absolute line-height override in layout points.

§letter_spacing: Option<f32>

Optional letter-spacing override in layout points.

§text_direction: TextDirection

Paragraph text direction override for the editable content.

§strut_line_height: Option<f32>

Optional paragraph strut line height.

§text_height_behavior: TextHeightBehavior

Paragraph height trimming behavior.

§prefix: Option<Box<Node>>

Optional leading decoration node.

§suffix: Option<Box<Node>>

Optional trailing decoration node.

§mouse_cursor: Option<MouseCursor>

Optional hover cursor override while pointing at the field.

§keyboard_type: TextInputType

Preferred software keyboard / input modality.

§text_input_action: TextInputAction

Preferred return/submit action.

§text_capitalization: TextCapitalization

Automatic capitalization strategy for inserted text.

§max_length: Option<usize>

Maximum number of Unicode scalar values allowed in the field.

§max_length_enforcement: MaxLengthEnforcement

Whether max_length is enforced during editing.

§input_formatters: Vec<InputFormatter>

Structured input formatters applied to inserted text.

§autocorrect: bool

Hint whether platform autocorrect should be enabled.

§enable_suggestions: bool

Hint whether platform suggestions should be enabled.

§spell_check: bool

Hint whether platform spell checking should be enabled.

§smart_dashes: bool

Hint whether smart dashes should be enabled.

§smart_quotes: bool

Hint whether smart quotes should be enabled.

§autofill_hints: Vec<String>

Platform autofill categories associated with this field.

§scroll_padding: Option<[f32; 4]>

Extra padding to keep around the caret when auto-scrolling [left, right, top, bottom].

§drag_start_behavior: DragStartBehavior

Whether selection drags become active on pointer-down or only after slop is crossed.

§context_menu: TextContextMenuConfig

Built-in context menu configuration for pointer and touch editing affordances.

§selection_controls: TextSelectionControls

Selection-handle visual configuration.

§magnifier_configuration: TextMagnifierConfiguration

Magnifier visual configuration shown while dragging selection handles.

§undo_controller: Option<TextUndoController>

Optional undo-controller configuration for edit history.

§spell_check_configuration: Option<SpellCheckConfiguration>

Structured spell-check preferences.

§restoration_id: Option<String>

Stable restoration identifier for rehydrating local edit state.

Implementations§

Source§

impl TextInput

Source

pub fn value(self, v: impl Into<String>) -> Self

Source

pub fn label(self, label: impl Into<TextContent>) -> Self

Source

pub fn padding(self, padding: [f32; 4]) -> Self

Source

pub fn background_fill(self, fill: Fill) -> Self

Source

pub fn text_color(self, color: IrColor) -> Self

Source

pub fn placeholder_color(self, color: IrColor) -> Self

Source

pub fn helper_text(self, helper_text: impl Into<TextContent>) -> Self

Source

pub fn error_text(self, error_text: impl Into<TextContent>) -> Self

Source

pub fn counter_text(self, counter_text: impl Into<TextContent>) -> Self

Source

pub fn label_color(self, color: IrColor) -> Self

Source

pub fn helper_color(self, color: IrColor) -> Self

Source

pub fn error_color(self, color: IrColor) -> Self

Source

pub fn counter_color(self, color: IrColor) -> Self

Source

pub fn selection_color(self, color: IrColor) -> Self

Source

pub fn selection_text_color(self, color: IrColor) -> Self

Source

pub fn text_align(self, text_align: TextAlign) -> Self

Source

pub fn text_align_vertical(self, text_align_vertical: TextAlignVertical) -> Self

Source

pub fn expands(self, expands: bool) -> Self

Source

pub fn cursor_color(self, color: IrColor) -> Self

Source

pub fn cursor_width(self, width: f32) -> Self

Source

pub fn cursor_height(self, height: f32) -> Self

Source

pub fn cursor_radius(self, radius: f32) -> Self

Source

pub fn enabled(self, enabled: bool) -> Self

Source

pub fn autofocus(self, autofocus: bool) -> Self

Source

pub fn read_only(self, read_only: bool) -> Self

Source

pub fn keyboard_type(self, keyboard_type: TextInputType) -> Self

Source

pub fn text_input_action(self, action: TextInputAction) -> Self

Source

pub fn text_capitalization(self, capitalization: TextCapitalization) -> Self

Source

pub fn max_length(self, max_length: usize) -> Self

Source

pub fn max_length_enforcement(self, enforcement: MaxLengthEnforcement) -> Self

Source

pub fn input_formatters(self, input_formatters: Vec<InputFormatter>) -> Self

Source

pub fn autocorrect(self, autocorrect: bool) -> Self

Source

pub fn enable_suggestions(self, enable_suggestions: bool) -> Self

Source

pub fn spell_check(self, spell_check: bool) -> Self

Source

pub fn smart_dashes(self, smart_dashes: bool) -> Self

Source

pub fn smart_quotes(self, smart_quotes: bool) -> Self

Source

pub fn autofill_hints(self, autofill_hints: Vec<String>) -> Self

Source

pub fn context_menu(self, context_menu: TextContextMenuConfig) -> Self

Source

pub fn drag_start_behavior(self, drag_start_behavior: DragStartBehavior) -> Self

Source

pub fn selection_controls( self, selection_controls: TextSelectionControls, ) -> Self

Source

pub fn magnifier_configuration( self, magnifier_configuration: TextMagnifierConfiguration, ) -> Self

Source

pub fn on_tap_outside(self, action: ActionEnvelope) -> Self

Source

pub fn undo_controller(self, undo_controller: TextUndoController) -> Self

Source

pub fn spell_check_configuration( self, spell_check_configuration: SpellCheckConfiguration, ) -> Self

Source

pub fn restoration_id(self, restoration_id: impl Into<String>) -> Self

Source

pub fn family(self, family: impl Into<String>) -> Self

Source

pub fn locale(self, locale: impl Into<String>) -> Self

Source

pub fn weight(self, weight: u16) -> Self

Source

pub fn italic(self, italic: bool) -> Self

Source

pub fn font_size(self, size: f32) -> Self

Source

pub fn text_scale(self, text_scale: f32) -> Self

Source

pub fn line_height(self, line_height: f32) -> Self

Source

pub fn letter_spacing(self, letter_spacing: f32) -> Self

Source

pub fn text_direction(self, text_direction: TextDirection) -> Self

Source

pub fn strut_line_height(self, strut_line_height: f32) -> Self

Source

pub fn text_height_behavior( self, text_height_behavior: TextHeightBehavior, ) -> Self

Source

pub fn prefix(self, node: Node) -> Self

Source

pub fn suffix(self, node: Node) -> Self

Source

pub fn mouse_cursor(self, mouse_cursor: SemanticsMouseCursor) -> Self

Source

pub fn scroll_padding(self, scroll_padding: [f32; 4]) -> Self

Source

pub fn into_node(self) -> Node

Trait Implementations§

Source§

impl Clone for TextInput

Source§

fn clone(&self) -> TextInput

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextInput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextInput

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TextInput

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<TextInput> for Node

Source§

fn from(w: TextInput) -> Self

Converts to this type from the input type.
Source§

impl Lower for TextInput

Source§

fn lower(&self, cx: &mut LoweringContext<'_>) -> NodeId

Lower this widget into the IR, returning the root node id.
Source§

impl Serialize for TextInput

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<S: AppState> Widget<S> for TextInput

Source§

fn build(&self, _ctx: &mut BuildCtx<S>, _view: &View<'_, S>) -> Node

Build the widget’s node tree. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,