TextField
A labeled, described and validated single-line text field.
View code
<form
method="post"
action="/examples/workspaces"
mix={[on<HTMLFormElement, "submit">("submit", (event) => event.preventDefault())]}
>
<Card>
<Card.Header>
<Card.Title>Create a workspace</Card.Title>
<Card.Description>You can rename it later; the address stays.</Card.Description>
</Card.Header>
<Card.Content mix={[vstack({ gap: 4, align: "stretch" })]}>
<TextField name="name" required autoComplete="organization" defaultValue="Acme Design">
<TextField.Label>Workspace name</TextField.Label>
<TextField.Description>Shown to everyone you invite.</TextField.Description>
</TextField>
<TextField type="email" name="billingEmail" required defaultValue="billing@acme">
<TextField.Label>Billing email</TextField.Label>
<TextField.Error>Enter an address we can invoice.</TextField.Error>
</TextField>
</Card.Content>
<Card.Footer mix={[hstack({ gap: 2, align: "center", justify: "end" })]}>
<Button type="submit">Create workspace</Button>
</Card.Footer>
</Card>
</form>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Or copy it into your project to edit it:
sdxc ui add text-fieldUsage
import { TextField } from "@sdxc/ui";Renders a text field: the control from the native attributes, laid out with the parts
the caller writes. A .Prefix or .Suffix joins the control as one bordered field; an
enclosing Form's issue for name shows as the error when no .Error is written.
Examples
Invalid value
View code
<TextField name="username" defaultValue="ab">
<TextField.Label>Username</TextField.Label>
<TextField.Error>Usernames need at least 3 characters.</TextField.Error>
</TextField>With a prefix or suffix
Teammates open the workspace at this address.
View code
<TextField name="slug" defaultValue="northwind">
<TextField.Label>Workspace URL</TextField.Label>
<TextField.Prefix>pulse.dev/</TextField.Prefix>
<TextField.Description>Teammates open the workspace at this address.</TextField.Description>
</TextField>
<TextField name="budget" type="number" defaultValue="250">
<TextField.Label>Monthly budget</TextField.Label>
<TextField.Prefix>$</TextField.Prefix>
</TextField>
<TextField name="threshold" type="number" defaultValue="800">
<TextField.Label>Alert after</TextField.Label>
<TextField.Suffix>ms</TextField.Suffix>
</TextField>With a hint
Use at least 12 characters, mixing letters and numbers.
View code
<TextField type="password" name="password" autoComplete="new-password">
<TextField.Label>Password</TextField.Label>
<TextField.Description>Use at least 12 characters, mixing letters and numbers.</TextField.Description>
</TextField>Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
color | "brand" | "neutral" | "success" | "warning" | "danger" | — | No | Semantic color role for the control's focus ring. Defaults to "neutral" when omitted. |
autoFocus | boolean | — | No | Native autofocus. Defaults to true for the first invalid field of an enclosing Form's issues, landing keyboard focus on the problem with no client JavaScript; pass explicitly to override. |
type | "text" | "email" | "password" | "tel" | "url" | "search" | "number" | — | No | Native <input> type. Defaults to DEFAULT_TYPE. |
name | string | — | No | Native name; it also finds the enclosing Form's issue for this field. |
value | string | — | No | |
defaultValue | string | — | No | |
placeholder | string | — | No | |
required | boolean | — | No | |
disabled | boolean | — | No | |
readOnly | boolean | — | No | |
autoComplete | string | — | No | |
pattern | string | — | No | |
minLength | number | — | No | |
maxLength | number | — | No | |
children | RemixNode | — | No | The field's parts: .Label, .Description, .Error, .Prefix and .Suffix. The control follows the caption, the addons join it, and the rest keep their order. |
Also accepts everything in Omit<TagProps<"div">, "prefix">.
Types
| Name | Values | What it decides |
|---|---|---|
Color | "brand" | "neutral" | "success" | "warning" | "danger" | Semantic color role for the control's keyboard focus ring, each mapped to its matching --ui-* variables. |
Type | "text" | "email" | "password" | "tel" | "url" | "search" | "number" | Native <input> type this field renders a single-line, text-like control for. |