TextField
A labelled single-line text field with a hint or an error under it.
Stability: experimental
Props
| Prop | Type | Default | Means |
|---|---|---|---|
label | string | The label above the field, and its accessible name. | |
value | string | bindable("") | The text. Bind it with bind:value={name}. |
placeholder | string | Hint text while empty. | |
hint | string | Help under the field. | |
error | string | An error under the field; replaces the hint, turns the border red and marks the field invalid. | |
type | "text" | "email" | "password" | "number" | "phone" | "search" | text | The kind of text, which picks the keyboard. |
autocomplete | Autocomplete | What the field holds, so the browser, iOS and Android can offer saved values: email, username, current-password, new-password, one-time-code, name, tel, postal-code and the other words input's autocomplete takes (decision 0106). | |
icon | string | An icon inside the field, before the text. | |
disabled | boolean | false | Cannot be edited or focused. |
onChange | (value: string) => void | Runs when the user leaves the field after editing it. |
States
| State | Looks like |
|---|---|
focused | Primary border and a soft primary ring. |
error | Danger border and ring; the error text with an alert icon. |
disabled | Raised background, dimmed label. |
Accessibility
| role | textbox |
| name | The label prop. |
| focus | Tab reaches it; Shift+Tab leaves it. A disabled one is skipped. |
| notes | error sets aria-invalid and the message is a live alert. The field is described (aria-describedby) by the error when there is one, otherwise by the hint. |
Theme tokens
color.surface color.border color.primary color.danger color.raised color.ink color.muted space.3 radius.md text.label text.caption
Example
<TextField label="Email" type="email" bind:value={email} error={emailError} />