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
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.
<TextField variant="outline" label="Payee" placeholder="City Water" />
<TextField variant="soft" label="Payee" placeholder="City Water" />Sizes
sm, md (the default) and lg.
<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.
<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.
<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.
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.
<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
| Prop | Type | Default | Description |
|---|---|---|---|
| leadingIcon | ReactNode | — | Icon rendered inside the field, pinned to the left edge. |
| trailingIcon | ReactNode | — | Icon rendered inside the field, pinned to the right edge. |
| label | string | — | Optional label text rendered above the field. |
| hint | string | — | Optional hint/helper text rendered below the field. |
| length | number | string | 6 | Number of digits/slots when type="otp". Default 6. |
| mask | boolean | false | Whether to mask digits with bullet dots (for PIN / password OTP codes) or mask password text. Default false. |
| separator | ReactNode | — | OTP only: separator element or character rendered midway (e.g. '-' or index=3 for 3-3 split). |
| separatorIndex | number | — | 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. |
| slotClassName | string | — | Optional custom CSS class name applied directly to individual OTP slot boxes. |
| showHidePassword | boolean | — | Password-only: render the built-in show/hide (Eye/EyeOff) trailing button. Ignored for other types. |
| errorMessage | string | — | Error message text — when set, the field renders in invalid/error state and shows this message below the input. |
| announceError | boolean | true | Announce `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" | — |