Inputs
TextField
Styled text input with label, helper text, error state and leading and trailing slots.
<script>
import { TextField } from "@codeatlasdev/ui";
let email = $state("");
</script>
<TextField label="Email" type="email" bind:value={email} />
An error replaces the description and is announced to assistive tech. On touch devices the input text stays at 16px or more so iOS Safari does not zoom on focus. Native input attributes (maxlength, inputmode, data-*, onkeydown, onfocus…) are spread on the <input>, and bind:ref gives you the element. For an inline field whose label is implied visually, set hideLabel (the label stays for screen readers) or pass aria-label without label. For a password, type="password" plus revealable adds the eye button inside the field: it toggles the input between password and text, has a localized name from the catalog (“Show password” / “Hide password”), aria-pressed, and a 44px hit area on touch without changing the field height. Do not rebuild it with trailing. below renders a snippet under the field, after the error or description: use it for a “Forgot password?” link or a strength meter. requiredIndicator={false} hides the asterisk of a required field when the form marks nothing as optional (the input stays required). Wrapper components such as MaskedField, MoneyInput and PhoneField forward these props to TextField.
Default
Basic text inputs with a label.
Reference #056 · Pick in the gallery
Code
With icons
leading and trailing snippets. Interactive trailing content must be a real button with its own label; for a password reveal use revealable.
Reference #057 · Pick in the gallery
Code
States
Helper text, error, required, read-only, disabled and the small size.
3–20 characters, letters and underscores only.
Please enter a valid email address.
Reference #058 · Pick in the gallery
Code
Text addons
`prefix` and `suffix` as strings: fixed context inside the border, read with the label.
Read with the label: https:// acme .com
Already taken
Reference #982 · Pick in the gallery
Code
Button addons
`prefix` and `suffix` as snippets: a Button or IconButton keeps its own name and Tab stop.
Reference #983 · Pick in the gallery
Code
Password
revealable adds the show/hide eye, below holds the Forgot password link, requiredIndicator={false} drops the asterisk.
Reference #500 · Pick in the gallery
Code
Hidden label
hideLabel keeps the label for assistive tech only; maxlength and ref reach the native input.
Reference #389 · Pick in the gallery
Code
Addons (input group)
prefix and suffix put an addon inside the field border, flush with it and set apart from the input by a divider (shadcn’s InputGroup). Differences from leading and trailing, which are bare icons inside the padding:
- A string is static text (
https://,$,.com,USD). It is part of the field’s accessible description (read after the label, before thedescriptionorerror) and a click on it focuses the input. It is not repeated as a label: name the field itself withlabel. - A snippet is interactive content: an
IconButton(variant="text" size="sm"), aButton(variant="ghost" size="sm") or a nativeselect. It is not hidden from assistive tech, keeps its own accessible name and Tab stop (input first, then a suffix button, in reading order), and a button must have a visible text or anaria-label. - The focus ring wraps the whole group while the input or an addon button has focus;
erroranddisabledreach the addons. --ca-tf-addon-bgsets the addon fill (default--ca-action-hover).
Tokens
--ca-field-gap (label to box to hint, default --ca-space-1) and --ca-field-label-leading (default --ca-line-height-snug) are shared with TextArea; --ca-tf-gap and --ca-tf-label-line-height set this component only and win.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | – | Label text. |
hideLabel | boolean | false | Renders the label with `.ca-sr-only`: read by screen readers, not shown. |
placeholder | string | '' | Input placeholder. |
value | string | '' | Bindable input value. |
type | string | 'text' | HTML input type. |
error | string | – | Validation error message. Puts the field in the error state. |
description | string | – | Non-error hint shown below the field. |
helperText | string | – | Deprecated alias of description. |
disabled | boolean | false | Disables the input. |
required | boolean | false | Marks the field as required. |
requiredIndicator | boolean | true | `false` hides the asterisk of a `required` field; the input stays `required`. |
readonly | boolean | false | Makes the input read-only. |
autocomplete | HTMLInputAttributes['autocomplete'] | – | Native autocomplete hint. |
name | string | – | Native name, for form submission. |
size | 'sm' | 'md' | 'md' | Field height. |
leading | Snippet | – | Icon or element before the input. |
trailing | Snippet | – | Icon or element after the input. |
prefix | string | Snippet | – | Addon before the input, inside the border. A string is text read as part of the description; a snippet is interactive content (Button, IconButton, select). |
suffix | string | Snippet | – | Addon after the input, same rules as `prefix`. |
revealable | boolean | false | With `type="password"`: adds a show/hide eye button inside the field (`aria-pressed`, localized name, 44px on touch). |
below | Snippet | – | Content under the field and its hint or error: a link such as Forgot password, or a strength meter. |
skeleton | boolean | false | Loading placeholder with the exact size of the loaded field (disabled, `aria-busy`). See Skeleton. |
class | string | – | Extra classes on the root. |
ref | HTMLInputElement | null | – | Bindable native input element. |
oninput | (value: string) => void | – | Called on every keystroke with the new value. |
onchange | (value: string) => void | – | Called when the value is committed (blur or Enter). |
onfocus | (e: FocusEvent) => void | – | Called when the input gains focus. |
onblur | (e: FocusEvent) => void | – | Called when the input loses focus. |