Textarea
A multi-line text field: a fixed number of rows, or growing with its text between a minimum and a maximum, with a character counter and Enter to submit.
Textarea
ui.add(Textarea::new(&mut state.text).rows(6));
Auto grow
ui.add(
Textarea::new(&mut state.auto_grow)
.auto_grow(1, 5)
.placeholder("Grows from one row to five as you type"),
);
Character counter
ui.add(
Textarea::new(&mut state.bio)
.rows(3)
.char_limit(100)
.counter(true),
);
Disabled
ui.add(Textarea::new(&mut state.disabled).rows(2).disabled(true));
Submit on Enter (chat)
let composer = Textarea::new(&mut state.message)
.auto_grow(1, 5)
.submit_on_enter(true)
.placeholder("Message (Shift+Enter for a new line)")
.show(ui);
if composer.submitted && !state.message.trim().is_empty() {
state.messages.push(std::mem::take(&mut state.message));
}
The story above is gallery/src/stories/textarea.rs, running in your browser. Every snippet on this page is cut from it.