Skip to content

Text field

Single-line text input control with control radius (--radius-lg), leading/trailing icon slots, and optional label/hint wrapper.

// Plain markup
import { TextField } from "@shavin/ui";

Default

Component Source
const [value, setValue] = useState("");

<TextField
  className="w-64"
  label="Budget name"
  placeholder="Groceries"
  value={value}
  onChange={(e) => setValue(e.target.value)}
/>

Variants

outline (the default) has a border on the surface colour. soft drops the border and fills the field.

Component Source
<TextField variant="outline" label="Payee" placeholder="City Water" />
<TextField variant="soft" label="Payee" placeholder="City Water" />

Sizes

sm, md (the default) and lg.

Component Source
<TextField size="sm" placeholder="Small" />
<TextField size="md" placeholder="Medium" />
<TextField size="lg" placeholder="Large" />

With icons

leadingIcon and trailingIcon take any node. Use Icon.

Component Source
<TextField placeholder="Search transactions" leadingIcon={<Icon name="search" size="sm" />} />
<TextField placeholder="you@wiseowl.app" trailingIcon={<Icon name="mail" size="sm" />} />

States

errorMessage shows below the field, sets aria-invalid and links the message through aria-describedby. invalid alone sets the red border with no message.

Enter an amount above zero.
Component Source
<TextField
  label="Monthly limit"
  defaultValue="-50"
  errorMessage="Enter an amount above zero."
/>
<TextField label="Account number" placeholder="Linked by your bank" disabled />

One-time code

type="otp" renders one slot per digit over a single real input. It sets autoComplete="one-time-code", so phones can fill the code from a text message, and it accepts paste. onComplete fires when every slot is filled.

Enter the 6-digit code we sent to your phone.
Component Source
const [code, setCode] = useState("");

<TextField
  type="otp"
  length={6}
  label="Verification code"
  hint="Enter the 6-digit code we sent to your phone."
  value={code}
  onChange={(e) => setCode(e.target.value)}
  onComplete={(c) => console.log("Code entered", c)}
/>

Split and masked codes

separator and separatorIndex split the slots. mask hides each digit, for a PIN.

-
The 4-digit PIN you use to unlock WiseOwl.
Component Source
<TextField type="otp" length={6} separator="-" separatorIndex={3} label="Two-factor code" />
<TextField type="otp" length={4} mask label="App PIN" hint="The 4-digit PIN you use to unlock WiseOwl." />

Props

PropTypeDefaultDescription
leadingIconReactNode—Icon rendered inside the field, pinned to the left edge.
trailingIconReactNode—Icon rendered inside the field, pinned to the right edge.
labelstring—Optional label text rendered above the field.
hintstring—Optional hint/helper text rendered below the field.
lengthnumber | string6Number of digits/slots when type="otp". Default 6.
maskbooleanfalseWhether to mask digits with bullet dots (for PIN / password OTP codes) or mask password text. Default false.
separatorReactNode—OTP only: separator element or character rendered midway (e.g. '-' or index=3 for 3-3 split).
separatorIndexnumber—OTP only: index position to render the separator (defaults to Math.floor(length / 2)).
onComplete(code: string) => void—Callback fired when all OTP digits have been entered.
slotClassNamestring—Optional custom CSS class name applied directly to individual OTP slot boxes.
showHidePasswordboolean—Password-only: render the built-in show/hide (Eye/EyeOff) trailing button. Ignored for other types.
errorMessagestring—Error message text — when set, the field renders in invalid/error state and shows this message below the input.
announceErrorbooleantrueAnnounce `errorMessage` (polite) once when it first appears, for blur and change validation. Default true. Set false while a form moves focus to its FormErrorSummary after a failed submit (FormErrorSummary also silences it automatically for that render).
variant"outline" | "soft""outline"—
size"sm" | "md" | "lg""md"—
invalid"true" | "false""false"—
Configure Theme
Theme
Brand Color
Custom
Gray Family
Appearance
Radius
Scaling
Panel Style
Heading Font
Body Font