Skip to main content

Module text_input

Module text_input 

Source
Expand description

TextInput — styled single-line text field composite.

Wraps the TextInputField editing primitive in a bordered, padded frame with placeholder overlay, validation, optional clear button, and leading/trailing slots. All actual text editing is delegated to the field: every configuration method here has a direct counterpart on the primitive.

Most applications want TextInput. Choose TextInputField directly when you’re building a composite of your own that already supplies its frame — SpinBox is the canonical in-tree example.

§Example

ⓘ
let search = ctx.signal(String::new());
TextInput::new(search.clone())
    .placeholder("Search...")
    .show_clear_button(true)
    .leading_slot(IconWidget::from_svg(SEARCH_ICON))
    .on_submit_fn(|ctx| ctx.send_intent(AppIntent::Search))

§Appearance

  • text_style — the size, family and weight of the typed text and of the placeholder, from a TextStyleRole (follows the theme) or a fixed TextStyle. The field’s height follows the style’s line, so a small style gives a short field and a large one a tall field.
  • text_alignment — where a text narrower than the field sits: start, centre or end, mirrored in a right-to-left layout. A longer text scrolls as usual.
  • text_color — the colour of the text and the caret. A disabled field still greys out. For one colour at rest and another while editing, map the field’s focus: input.handle().focused_signal().map(|f| if *f { TextRole::Primary } else { TextRole::Secondary }).
  • min_height — replaces the minimum height the style and the density would give the field. Below 24 dp the field fails WCAG 2.5.8 unless the app offers a larger target for it.

None of them is set by default, and the field then looks as it always has.

§Touch and pen

The trailing clear affordance is 16 dp of paint and a 24 dp target: raising its box would widen every field in the workspace at Compact, so the shortfall is made up between the pointer and the arena through Widget::hit_outset — declared by the slot that takes the tap, because the ring around an outset resolves to the declaring node rather than to a descendant, and by a direct child of the row, because an outset never escapes its parent. The slot keeps its 16 dp while the affordance is hidden so the row does not jump, and withdraws its outset while there is nothing to clear. The caret and selection behaviour of the field itself belongs to the touch-text package.

Structs§

TextInput
Styled single-line text input composite.

Enums§

TextInputVariant
ValidationState
Validation state for the text input field.