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: StringThe 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: ComponentSizeDesign-system size slot.
padding: Option<[f32; 4]>Custom content padding [left, right, top, bottom].
multiline: boolWhen true, the input accepts newlines and scrolls vertically.
autofocus: boolWhen true, the input requests focus automatically when mounted.
enabled: boolWhen false, the field is non-interactive and does not receive focus.
read_only: boolWhen 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: boolWhen true, display each grapheme as obscuring_character (password mode).
obscuring_character: charThe 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: boolWhen true, the background rect and border are omitted (for embedding
in editor chrome).
capture_tab: boolWhen true, the Tab key inserts whitespace instead of moving focus.
auto_indent: boolWhen 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: TextAlignHorizontal text alignment inside the editable region.
text_align_vertical: TextAlignVerticalVertical alignment for the editable region when the field is taller than its content.
expands: boolWhen 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: TextFontStyleOptional 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: TextDirectionParagraph text direction override for the editable content.
strut_line_height: Option<f32>Optional paragraph strut line height.
text_height_behavior: TextHeightBehaviorParagraph 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: TextInputTypePreferred software keyboard / input modality.
text_input_action: TextInputActionPreferred return/submit action.
text_capitalization: TextCapitalizationAutomatic capitalization strategy for inserted text.
max_length: Option<usize>Maximum number of Unicode scalar values allowed in the field.
max_length_enforcement: MaxLengthEnforcementWhether max_length is enforced during editing.
input_formatters: Vec<InputFormatter>Structured input formatters applied to inserted text.
autocorrect: boolHint whether platform autocorrect should be enabled.
enable_suggestions: boolHint whether platform suggestions should be enabled.
spell_check: boolHint whether platform spell checking should be enabled.
smart_dashes: boolHint whether smart dashes should be enabled.
smart_quotes: boolHint 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: DragStartBehaviorWhether selection drags become active on pointer-down or only after slop is crossed.
Built-in context menu configuration for pointer and touch editing affordances.
selection_controls: TextSelectionControlsSelection-handle visual configuration.
magnifier_configuration: TextMagnifierConfigurationMagnifier 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
impl TextInput
pub fn value(self, v: impl Into<String>) -> Self
pub fn label(self, label: impl Into<TextContent>) -> Self
pub fn padding(self, padding: [f32; 4]) -> Self
pub fn background_fill(self, fill: Fill) -> Self
pub fn text_color(self, color: IrColor) -> Self
pub fn placeholder_color(self, color: IrColor) -> Self
pub fn helper_text(self, helper_text: impl Into<TextContent>) -> Self
pub fn error_text(self, error_text: impl Into<TextContent>) -> Self
pub fn counter_text(self, counter_text: impl Into<TextContent>) -> Self
pub fn label_color(self, color: IrColor) -> Self
pub fn helper_color(self, color: IrColor) -> Self
pub fn error_color(self, color: IrColor) -> Self
pub fn counter_color(self, color: IrColor) -> Self
pub fn selection_color(self, color: IrColor) -> Self
pub fn selection_text_color(self, color: IrColor) -> Self
pub fn text_align(self, text_align: TextAlign) -> Self
pub fn text_align_vertical(self, text_align_vertical: TextAlignVertical) -> Self
pub fn expands(self, expands: bool) -> Self
pub fn cursor_color(self, color: IrColor) -> Self
pub fn cursor_width(self, width: f32) -> Self
pub fn cursor_height(self, height: f32) -> Self
pub fn cursor_radius(self, radius: f32) -> Self
pub fn enabled(self, enabled: bool) -> Self
pub fn autofocus(self, autofocus: bool) -> Self
pub fn read_only(self, read_only: bool) -> Self
pub fn keyboard_type(self, keyboard_type: TextInputType) -> Self
pub fn text_input_action(self, action: TextInputAction) -> Self
pub fn text_capitalization(self, capitalization: TextCapitalization) -> Self
pub fn max_length(self, max_length: usize) -> Self
pub fn max_length_enforcement(self, enforcement: MaxLengthEnforcement) -> Self
pub fn input_formatters(self, input_formatters: Vec<InputFormatter>) -> Self
pub fn autocorrect(self, autocorrect: bool) -> Self
pub fn enable_suggestions(self, enable_suggestions: bool) -> Self
pub fn spell_check(self, spell_check: bool) -> Self
pub fn smart_dashes(self, smart_dashes: bool) -> Self
pub fn smart_quotes(self, smart_quotes: bool) -> Self
pub fn autofill_hints(self, autofill_hints: Vec<String>) -> Self
pub fn drag_start_behavior(self, drag_start_behavior: DragStartBehavior) -> Self
pub fn selection_controls( self, selection_controls: TextSelectionControls, ) -> Self
pub fn magnifier_configuration( self, magnifier_configuration: TextMagnifierConfiguration, ) -> Self
pub fn on_tap_outside(self, action: ActionEnvelope) -> Self
pub fn undo_controller(self, undo_controller: TextUndoController) -> Self
pub fn spell_check_configuration( self, spell_check_configuration: SpellCheckConfiguration, ) -> Self
pub fn restoration_id(self, restoration_id: impl Into<String>) -> Self
pub fn family(self, family: impl Into<String>) -> Self
pub fn locale(self, locale: impl Into<String>) -> Self
pub fn weight(self, weight: u16) -> Self
pub fn italic(self, italic: bool) -> Self
pub fn font_size(self, size: f32) -> Self
pub fn text_scale(self, text_scale: f32) -> Self
pub fn line_height(self, line_height: f32) -> Self
pub fn letter_spacing(self, letter_spacing: f32) -> Self
pub fn text_direction(self, text_direction: TextDirection) -> Self
pub fn strut_line_height(self, strut_line_height: f32) -> Self
pub fn text_height_behavior( self, text_height_behavior: TextHeightBehavior, ) -> Self
pub fn prefix(self, node: Node) -> Self
pub fn suffix(self, node: Node) -> Self
pub fn mouse_cursor(self, mouse_cursor: SemanticsMouseCursor) -> Self
pub fn scroll_padding(self, scroll_padding: [f32; 4]) -> Self
pub fn into_node(self) -> Node
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TextInput
impl<'de> Deserialize<'de> for TextInput
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Lower for TextInput
impl Lower for TextInput
Source§fn lower(&self, cx: &mut LoweringContext<'_>) -> NodeId
fn lower(&self, cx: &mut LoweringContext<'_>) -> NodeId
Auto Trait Implementations§
impl Freeze for TextInput
impl !RefUnwindSafe for TextInput
impl Send for TextInput
impl Sync for TextInput
impl Unpin for TextInput
impl UnsafeUnpin for TextInput
impl !UnwindSafe for TextInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.