Text Field
One input for every form: label, hint and error in place, prefix and suffix, clear, copy and show-password buttons, and a character count with a soft limit.
oxyn add text-fieldrsx! {
TextField {
label: "Commit message",
value: draft(),
counter: true,
max: Some(50),
soft: Some(40),
on_input: move |s: String| draft.set(s),
}
}Rendered from Rust at build time · goes live when visible
When to use
- One input for every form: repository, email, budget, API key, search, commit message.
When not to use
Installation
Text Field is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add text-fielduse crate::oxyn::{TextField, PRIMITIVES_CSS};Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{TextField, PRIMITIVES_CSS};
Usage
rsx! {
TextField {
label: "Commit message",
value: draft(),
counter: true,
max: Some(50),
soft: Some(40),
on_input: move |s: String| draft.set(s),
}
}Examples
Counter
Commit message near its limit.
Code
rsx! {
TextField {
label: "Commit message",
value: draft(),
counter: true,
max: Some(50),
soft: Some(40),
on_input: move |s: String| draft.set(s),
}
}Search
Search with an icon and clear.
Code
rsx! {
TextField {
label: "Search runs",
value: draft(),
kind: "search",
prefix: "icon:search",
clearable: true,
on_input: move |s: String| draft.set(s),
}
}Prefix suffix
Number with a prefix and suffix.
Code
rsx! {
TextField {
label: "Budget",
value: draft(),
kind: "number",
prefix: "$",
suffix: "/ month",
optional: true,
on_input: move |s: String| draft.set(s),
}
}Password
Show, then hide again after 10 s.
Code
rsx! {
TextField {
label: "Password",
value: draft(),
kind: "password",
hint: "Hides again after 10 s",
auto_hide_s: Some(10),
on_input: move |s: String| draft.set(s),
}
}Error
Email with an error in place.
Code
rsx! {
TextField {
label: "Email",
value: draft(),
kind: "email",
on_input: move |s: String| draft.set(s),
}
}API reference
TextField
| Prop | Type | Default | Description |
|---|---|---|---|
labelrequired | String | — | Label. |
value | String | Default::default() | Initial value. |
kind | String | "text" | `text` · `password` · `email` · `search` · `number` · `url`. |
placeholder | Option<String> | Default::default() | Placeholder. |
hint | Option<String> | Default::default() | Hint. |
error | Option<String> | Default::default() | Error from the app. |
prefix | Option<String> | Default::default() | Prefix text or icon name (`icon:search`). |
suffix | Option<String> | Default::default() | Suffix text. |
size | String | "md" | `sm` · `md` · `lg`. |
optional | bool | Default::default() | "Optional" next to the label. |
required | bool | Default::default() | Required. |
clearable | bool | Default::default() | Clear button. |
copyable | bool | Default::default() | Copy button. |
counter | bool | Default::default() | Character counter (needs `max`). |
max | Option<usize> | Default::default() | Hard limit. |
soft | Option<usize> | Default::default() | Soft limit (warning). |
validate | String | "blur" | `blur` · `type` · `submit`. |
auto_hide_s | Option<u64> | Default::default() | Hide a revealed password after this many seconds. |
disabled | bool | Default::default() | Disabled. |
state | Option<String> | Default::default() | Review sheets: force `hover` or `focus`. |
now | ClockMs | Default::default() | Clock. |
on_input | EventHandler<String> | — | Value changed. |
on_clear | EventHandler<()> | — | Cleared. |
on_copy | EventHandler<String> | — | Copied. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| Esc | Clear (search and clearable fields) |
| Tab | Into the clear, copy or reveal buttons |
Accessibility
- Native input with a label; aria-describedby points at the message slot, which is aria-live=polite.
- aria-invalid and aria-required reflect the model.
- Clear, copy and reveal are named buttons, reachable after the input in tab order.
From the spec
Native <input> with a <label for>; aria-describedby always points at the message slot, which is aria-live=polite; aria-invalid and aria-required reflect the model. Icon buttons inside the field are named and reachable after the input in tab order.
Motion & interaction
No focus ring: the grey edge darkens on hover and a little more on focus. An error nudges the field once (4 → 1 px over 300 ms) and its message slides in out of a short blur in place of the hint — nothing below moves. Showing a password brings the characters out of a short blur. Arc: the helper / error row opens its height on a smooth spring; changed words rise in; numbers roll.
Timing
| Transition | Duration | Easing | Reduced motion |
|---|---|---|---|
| Edge colour | 120 ms | ease.out | 80 ms |
| Error nudge | 300 ms (dur.error.nudge) | damped sine | none |
| Message in | 180 ms, 5 px rise, blur 3 → 0 | ease.out | 80 ms fade |
| Reveal | 180 ms blur → sharp | ease.out | instant |
| Copy confirm | 1500 ms (dur.copy.confirm) | — | same |
| Check draw | 240 ms | ease.out | drawn |
| Auto-hide (Oxyn plus) | 10 s default | linear ring | ring hidden, timer kept |
Responsive behaviour
- Fills its container; long prefixes shrink the input, never overflow.
- Pasting over the hard limit keeps the value and turns the counter red.
Edge cases (spec)
Pasting over the hard limit: the counter goes red and the error explains; the value is kept (no silent truncation) unless maxlength is set without a soft limit. Clearing a field that showed an error re-validates. Long prefixes shrink the input, never overflow. Disabled fields ignore input in the model as well as the DOM.
Notes for AI
- Import
TextFieldfromoxyn_dioxusand includePRIMITIVES_CSSplus the token stylesheet once. - A GPUI version exists:
TextFieldElinoxyn_gpui. - Props to set first:
label. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.