Skip to Content
WidgetsInput

Input

Input is the standard editable text field.

Input
Input terminal preview
Terminal preview of Input

Smallest example

let field = Input::new() .value(self.draft.clone()) .placeholder("Type a command") .on_change(Message::DraftChanged) .on_submit(|value| Some(Message::Submit(value))) .layout(Layout { width: Length::Fill, height: Length::Fixed(3) }) .build();

Use Input when

  • the user types text directly into the app
  • you need on_change and on_submit
  • cursor continuity matters across rerenders

Key builder methods

  • Input::new()
  • .value(...)
  • .placeholder(...)
  • .on_change(...)
  • .on_submit(...)
  • .style(...)

How it looks in view!

view! { <Input value={self.draft.clone()} placeholder={"Type a command".to_string()} on_change={Message::DraftChanged} on_submit={|value| Some(Message::Submit(value))} /> }

State boundary

Input usually works best when:

  • the in-progress draft lives in local or app state
  • submit turns that draft into a message
  • the runtime preserves cursor continuity across rerenders

Where to see it in examples

Last updated on