Fields
Text Field
A shared field brain that connects a label, one text input, help, and errors.
When to use it: Use it for a one-line text value such as an email or name.
Example
import { Description, Input, Label, TextField } from "@comp0/react";
export function Example() {
return (
<TextField as="div" className="flex max-w-xs flex-col gap-1.5">
<Label className="text-base font-medium text-zinc-900 sm:text-sm dark:text-zinc-100">
Email
</Label>
<Input
className="w-full rounded border border-zinc-950/10 bg-white px-3 py-2.5 text-base text-zinc-950 outline-teal-600 focus-visible:outline-2 sm:py-2 sm:text-sm dark:border-white/10 dark:bg-zinc-900 dark:text-zinc-50 dark:outline-teal-400"
name="email"
type="email"
placeholder="you@example.com"
/>
<Description className="text-base text-zinc-600 sm:text-sm dark:text-zinc-400">
We only use this for receipts.
</Description>
</TextField>
);
}Anatomy
Dashed frames are invisible state providers; shaded shapes own real DOM. Numbered pins match the list below.
A wireframe sketch of the assembled component. Each numbered marker matches a part in the list that follows.
TextField
Field provider; it owns no DOM unless as is supplied. Does not add a DOM element.
Label
Native label linked to the control. Owns a DOM element.
Input
Native single-line control that owns typing and submission. Owns a DOM element.
Description / FieldErrorOptional
Linked help or error text. Owns a DOM element.
Step by step
- 1
Add the main part
Start TextField with Label and Input.
- 2
Add the supporting parts
Add Description for a useful hint and FieldError for validation feedback.
- 3
Make the behavior clear
Give Input a native name so a form can send its value.
Exampletsx <TextField><Label>Email</Label><Input name="email" /></TextField>
Keyboard
- ⇥
- Moves to and from the native control.
Forms and accessibility
Input submits its native name and value.
Accessibility checklist
- Use Label so the input has a clear name.
- Put Description and FieldError near their field.
- Do not rely on placeholder text as the only label.
API reference
import { Description, FieldError, Input, Label, TextField } from "@comp0/react";TextField
Context onlyField provider; it owns no DOM unless as is supplied.
| Prop | Type | Description |
|---|---|---|
value | string | Controlled field value. |
defaultValue | string | Initial field value. |
onChange | (value: string) => void | Receives the next value. |
disabled / invalid / required | boolean | Field-wide states shared with every part. |
Label
DOM elementNative label linked to the control.
| Prop | Type | Description |
|---|---|---|
htmlFor | string | Auto-wired to the field control; set it only to override. |
Input
DOM elementNative single-line control that owns typing and submission.
| Prop | Type | Description |
|---|---|---|
name | string | Submission name for the value. |
type | string | Native input type such as "email" or "password". |
placeholder | string | Hint text; never a replacement for Label. |
disabled / required | boolean | Override the field-wide state for this control. |
Description / FieldError
OptionalDOM elementLinked help or error text.
| Prop | Type | Description |
|---|---|---|
forceMount | boolean | FieldError only: keep it rendered while the field is valid. |
Style hooks
Attributes that appear while a state is true. Target them with Tailwind data variants such as data-open:bg-zinc-100, or with any CSS selector.
[data-invalid]on Input
- The field is invalid.
[data-required]on Input
- The field is required.
[data-disabled]on Input
- The field is disabled.