-
Notifications
You must be signed in to change notification settings - Fork 9
Component TextInput
MeowLynxSea edited this page Jun 13, 2026
·
10 revisions
A single-line text input. Owns the caret / selection / IME state internally (the renderer mints a TextInputState keyed by id). Use password_input for masked input, search_input for the search variant, text_area for multi-line.
use yororen_ui::headless::text_input::text_input;use yororen_ui::headless::text_input::text_input;
text_input("name-input")
.placeholder("Your name")
.max_length(64)
.on_change({
let entity = cx.entity();
move |new: &str, _window, cx| {
entity.update(cx, |s, _cx| s.name = new.to_string());
}
})
.on_submit({
let entity = cx.entity();
move |value: &str, _window, cx| {
entity.update(cx, |s, _cx| s.last_submitted = value.to_string());
}
})
.render(cx, window)| Method | Purpose |
|---|---|
placeholder(text) |
Hint shown when empty. |
disabled(v) |
Disable interaction. |
max_length(n) |
Hard cap on the value's UTF-8 byte length. |
on_change(closure) |
Fn(&str, &mut Window, &mut App) + 'static + Send + Sync. Fires on every accepted change. |
on_submit(closure) |
Fn(&str, &mut Window, &mut App) + 'static + Send + Sync. Fires on Enter. |
has_custom_bg(v) / custom_bg(hsla)
|
Override the rendered background. |
has_custom_border(v) / custom_border(hsla)
|
Override the border. |
has_custom_focus_border(v) / custom_focus_border(hsla)
|
Override the focus border. |
custom_text_color(hsla) |
Override the text color. |
-
Factory takes
(id)only — nocxargument. The id must be stable across re-renders. -
.render(cx, window)is two-arg and returnsAnyElement. Thewindowis required because the renderer registers theEntityInputHandlerfor IME / paste. -
on_changeandon_submitreceive&str(the new UTF-8 text), notSharedString. Convert with.to_string()before storing. - The state is minted internally by the renderer via
window.use_keyed_state(...)— there is noEntity<TextInputState>for the caller to manage. -
Boot step (required): call
yororen_ui::headless::text_input::init(cx)once at app startup. The function is idempotent (guarded by aOnceLock); without it the 14 keyboard actions bound to theUITextInputcontext will not fire and keystrokes (backspace, arrow keys, enter, etc.) will not work.
PasswordInput, SearchInput, NumberInput, TextArea, Form
Yororen UI v0.3.0 · repository · Apache-2.0 · This wiki documents Yororen UI v0.3.0.
This wiki documents Yororen UI v0.3.0 — the headless-core, swappable-renderer build.