TextInput
Text field on a filled container surface in S/M/L sizes, with focus, hover, disabled, error and password states. All colors come from tokens in @npolyhunter/ds/theme.css.
Playground
Live preview
Examples
Trailing action · amount maximum
<TextInput size="large" value={amount} onChange={...} trailingAction={{ label: "Max", onClick: () => setAmount(balance) }} />Applied filter input · success border
<TextInput appearance="openValueActive" value={query} onChange={handleChange} />Sizes
<TextInput size="small" placeholder="Small" />
<TextInput size="medium" placeholder="Medium" />
<TextInput size="large" placeholder="Large" />With labels
Pair with the Label atom via htmlFor.
import { Label, TextInput } from "@npolyhunter/ui";
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<TextInput id="email" type="email" placeholder="you@example.com" />
</div>States
Focus switches to a 2px focus-neutral border. Invalid uses status-danger-border for the border and ring. Disabled keeps the container surface with a subtle border and disabled text.
<TextInput placeholder="Default" />
<TextInput placeholder="Focus me" autoFocus />
<TextInput placeholder="With value" defaultValue="Polyhunter" />
<TextInput placeholder="Disabled" disabled />
// Readonly — filled text stays foreground-default, empty shows the placeholder token,
// and the focus border treatment is suppressed (native focus still lands on the field)
<TextInput readOnly defaultValue="Readonly value" />
<TextInput readOnly placeholder="Readonly placeholder" />
// Error — border uses status-danger-border; on focus it becomes 2px status-danger-foreground
// plus a danger-tinted ring
<TextInput invalid placeholder="Error" />
<TextInput invalid defaultValue="bad value" aria-describedby="error-id" />With icons & password toggle
type="search" renders the shared SearchIcon on the left out of the box, leadingIcon adds any left adornment, and type="password" renders a show/hide toggle on the right — no manual positioning.
"use client";
import { Lock, Mail } from "lucide-react";
import { TextInput } from "@npolyhunter/ui";
// Search — type="search" renders the shared SearchIcon on the left out of
// the box; clearable adds the shared CloseIcon to empty the field.
<TextInput type="search" placeholder="Search" clearable />
// Leading icon — left adornment with automatic padding.
<TextInput leadingIcon={<Mail />} type="email" placeholder="Email" clearable />
// Password — type="password" renders a show/hide toggle on the right.
<TextInput leadingIcon={<Lock />} type="password" placeholder="Password" />Clearable
clearable renders the shared CloseIcon (same as Tag) on the right once the field has text. Clicking it empties the field — onChange fires with "", then onClear. Works controlled and uncontrolled; hidden when disabled or readonly, and the native webkit clear button is suppressed. With clearable the component wraps the input in a full-width root, so constrain width with a wrapper div (e.g. max-w-xs) rather than a width class on className. When composing a leading icon alongside clearable, give it z-10 — the component's root is a positioned wrapper that would otherwise paint over it.
import { TextInput } from "@npolyhunter/ui";
// Clear button appears once the field has text; clicking it empties
// the field (onChange fires with "", then onClear).
// Constrain width on a wrapper — the clear button anchors to the
// component's root, which wraps the input when clearable.
<div className="max-w-xs">
<TextInput clearable placeholder="Search missions..." type="search" />
</div>
// Controlled
const [value, setValue] = useState("");
<TextInput
clearable
value={value}
onChange={(e) => setValue(e.target.value)}
onClear={() => console.log("cleared")}
/>Disabled
<TextInput disabled placeholder="Disabled" />
<TextInput disabled defaultValue="Disabled with value" />Code
import { TextInput } from "@npolyhunter/ui";
// Default (filled container surface)
<TextInput placeholder="Type here..." />
// Clearable — shared CloseIcon appears once there's text
<TextInput clearable placeholder="Search..." type="search" />
// Sizes S / M / L
<TextInput size="small" placeholder="Small" />
<TextInput size="medium" placeholder="Medium" />
<TextInput size="large" placeholder="Large" />
// Error state
<TextInput invalid placeholder="Invalid input" />
// Applied filter input
<TextInput appearance="openValueActive" value={query} onChange={handleChange} />
// Disabled
<TextInput disabled placeholder="Disabled input" />Code
const [value, setValue] = useState("");
<TextInput
size="${size}" // "small" | "medium" | "large"
appearance="${variant}" // "default" | "openValueActive"
type="${type}" // "text" | "password" | "email" | "number" | "search"
placeholder="${placeholder}"
value={value}
onChange={(e) => setValue(e.target.value)}
clearable // shows the shared CloseIcon to clear once there's text
invalid={invalid}
disabled={disabled}
/>Used in
Includes use through shared UI components.
