Skip to content
Back

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-field
MCP
49 / 50
Dioxus
rsx! {
    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

  • Pick one option in the text field's look: use Select instead.
  • On or off for things that apply right away: use Switch instead.
  • A real checkbox with a label and second line, an indeterminate state for Select all, an error, a card row and a check that draws itself: use Checkbox instead.

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.

Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add text-field
Rust
use 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

Dioxus · rust
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.

49 / 50
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.

$/ month
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.

Hides 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.

Enter an email like name@example.com
Code
rsx! {
    TextField {
        label: "Email",
        value: draft(),
        kind: "email",
        on_input: move |s: String| draft.set(s),
    }
}

API reference

TextField

PropTypeDefaultDescription
labelrequiredString—Label.
valueStringDefault::default()Initial value.
kindString"text"`text` · `password` · `email` · `search` · `number` · `url`.
placeholderOption<String>Default::default()Placeholder.
hintOption<String>Default::default()Hint.
errorOption<String>Default::default()Error from the app.
prefixOption<String>Default::default()Prefix text or icon name (`icon:search`).
suffixOption<String>Default::default()Suffix text.
sizeString"md"`sm` · `md` · `lg`.
optionalboolDefault::default()"Optional" next to the label.
requiredboolDefault::default()Required.
clearableboolDefault::default()Clear button.
copyableboolDefault::default()Copy button.
counterboolDefault::default()Character counter (needs `max`).
maxOption<usize>Default::default()Hard limit.
softOption<usize>Default::default()Soft limit (warning).
validateString"blur"`blur` · `type` · `submit`.
auto_hide_sOption<u64>Default::default()Hide a revealed password after this many seconds.
disabledboolDefault::default()Disabled.
stateOption<String>Default::default()Review sheets: force `hover` or `focus`.
nowClockMsDefault::default()Clock.
on_inputEventHandler<String>—Value changed.
on_clearEventHandler<()>—Cleared.
on_copyEventHandler<String>—Copied.

Read from the Rust signature and doc comments.

Keyboard interactions

KeyAction
EscClear (search and clearable fields)
TabInto 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
TransitionDurationEasingReduced motion
Edge colour120 msease.out80 ms
Error nudge300 ms (dur.error.nudge)damped sinenone
Message in180 ms, 5 px rise, blur 3 → 0ease.out80 ms fade
Reveal180 ms blur → sharpease.outinstant
Copy confirm1500 ms (dur.copy.confirm)—same
Check draw240 msease.outdrawn
Auto-hide (Oxyn plus)10 s defaultlinear ringring 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 TextField from oxyn_dioxus and include PRIMITIVES_CSS plus the token stylesheet once.
  • A GPUI version exists: TextFieldEl in oxyn_gpui.
  • Props to set first: label.
  • Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.

Guides

Oxyn · 74 free components · 264 Pro components · 96 screens · 20 blocks · Dioxus and GPUI