Components / Selection & input

Textarea

Markdown crates/ui/src/input.rs docs.rs

Textarea

Ask your agent

Install the bezel skill once

npx skills add crabtalk/bezel --skill bezel

Then ask

Add a message composer that grows from 3 to 12 lines, where enter sends and shift-enter breaks the line.
use ui::input::{self, Shape, TextField};

const COMPOSER: &str = "Composer";

cx.bind_keys([
    KeyBinding::new("enter", Send, Some(COMPOSER)),
    KeyBinding::new("shift-enter", input::InsertNewline, Some(COMPOSER)),
]);
let composer = cx.new(|cx| {
    TextField::new(cx)
        .with_shape(Shape::Grow { min: 3, max: 12 })
        .with_key_context(COMPOSER)
});
  • Shape::Fill is as tall as its parent, which must give it a definite height.
  • Rebind enter on a context of the field's own (with_key_context). Rebinding input::MULTILINE_KEY_CONTEXT takes the newline from every textarea in the app.