iced-cube

Forms

Input

A single line of editable text, with an optional icon, password masking and an invalid state.

use iced_cube::{input, lucide};
use iced_cube::primitives::input::Size;
API reference
With icon: A leading Lucide icon, in small, medium and large sizes.With icon: A leading Lucide icon, in small, medium and large sizes.
Static preview
With icon. A leading Lucide icon, in small, medium and large sizes.

Usage

Inputs are controlled: the app stores the value, passes it to input and updates it from the on_input message. Leave out on_input to show a read-only value in the disabled style.

To name an input, wrap it in field, which adds a label, a description and an error message. Set .invalid(true) on the input when the field has an error so the border matches.

Clicking an input focuses it. iced does not move focus on Tab by itself: listen for Tab in a keyboard subscription and return iced::widget::operation::focus_next(), or give the input an .id(...) and return iced::widget::operation::focus(id) from update.

Examples

Default

A controlled input that submits on Enter.

Default: A controlled input that submits on Enter.Default: A controlled input that submits on Enter.
Static preview

Password

A secure input with a button that reveals the value.

Password: A secure input with a button that reveals the value.Password: A secure input with a button that reveals the value.
Static preview

Invalid and disabled

An invalid value draws a destructive border. An input without on_input is disabled.

Invalid and disabled: An invalid value draws a destructive border. An input without on_input is disabled.Invalid and disabled: An invalid value draws a destructive border. An input without on_input is disabled.
Static preview

API

ItemDescription
input(placeholder, value)Creates a text input showing value, with the placeholder while it is empty. It renders disabled until it has on_input.
.on_input(fn) / .on_input_maybe(option)Sets the message built from the new value on every edit. None disables the input.
.on_submit(message) / .on_submit_maybe(option)Sets the message emitted when Enter is pressed. A disabled input never submits.
.icon(glyph)Adds a Lucide icon at the start of the input.
.secure(bool)Masks the value, for passwords and other secrets.
.invalid(bool)Draws a destructive border. Pair it with an error message from field.
.size(Size)Sm, Md or Lg (32, 36 and 40 pixels tall). Defaults to Md.
.id(id) / .width(length)Sets the widget id, used to focus the input from a task or find it in tests, and overrides the width. Inputs fill the available width by default.

Keyboard

KeysBehaviour
EnterEmits the on_submit message.
EscapeRemoves focus from the input.
Home / EndMoves the cursor to the start or end of the value.
Shift + ArrowExtends the selection.
Esc