Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Textbox

A text input control for editing string-backed values.

When To Use It

Use Textbox for short text, numeric entry, search fields, and form input. Use Textbox::new_multiline for paragraph-style editing.

Constructing a Textbox

Single-line textbox:

let name = Signal::new(String::from(""));

Textbox::new(cx, name)
	.placeholder("Display name")
	.on_edit(|cx, text| cx.emit(AppEvent::EditingName(text)))
	.on_submit(|cx, text, from_enter| cx.emit(AppEvent::SubmitName(text, from_enter)));

Multiline textbox with wrapping:

let notes = Signal::new(String::new());

Textbox::new_multiline(cx, notes, true)
	.placeholder("Notes")
	.on_submit(|cx, text, _| cx.emit(AppEvent::SubmitNotes(text)));

Validation example:

Textbox::new(cx, age_text)
	.validate(|age: &u32| *age <= 130)
	.on_submit(|cx, age, _| cx.emit(AppEvent::SetAge(age)));

Textbox Modifiers

ModifierTypeDescriptionDefault
on_editFn(&mut EventContext, String)Called whenever text content changes.-
on_submitFn(&mut EventContext, T, bool)Called on submit/blur with parsed value and source flag.-
on_blurFn(&mut EventContext)Called when textbox loses editing focus.-
on_cancelFn(&mut EventContext)Called when edit is cancelled (Escape).-
validateFn(&T) -> boolValidates parsed value; invalid values are not submitted.none
placeholderimpl Res<impl ToStringLocalized>Placeholder text when input is empty.empty

Components and Styling

SelectorDescription
textboxRoot textbox element.
textbox.multilineApplied for wrapped multiline textbox.
textbox.caretApplied while caret is visible/blinking.
textbox:placeholder-shownApplied when placeholder text is shown.

Accessibility

  • Single-line textbox uses role TextInput.
  • Multiline textbox uses role MultilineTextInput.
  • Use name(...) for accessible naming when no visible label is present.
  • Use id(...) and describing(...)/labeled_by(...) with a Label for explicit associations.

Keyboard Interaction

KeyAction
EnterSubmit in single-line mode; insert newline in multiline mode.
EscapeCancel editing (on_cancel) or end edit if no cancel handler is set.
ArrowLeft / ArrowRightMove caret left/right.
ArrowUp / ArrowDownMove caret by line in multiline mode.
Home / EndMove caret to line start/end.
PageUp / PageDownMove by page.
Ctrl+PageUp / Ctrl+PageDownMove to start/end of document body.
Backspace / DeleteDelete text backward/forward.
Ctrl/Cmd+ASelect all text.
Ctrl/Cmd+CCopy selection.
Ctrl/Cmd+VPaste from clipboard.
Ctrl/Cmd+XCut selection.

On macOS, word navigation/deletion uses Option, and line-boundary navigation uses Cmd, matching platform conventions.