TextField
A text input with label and validation built on Base UI
Installation
pnpm dlx shadcn@latest add https://prototyper-ui.com/r/textfield.jsonnpx shadcn@latest add https://prototyper-ui.com/r/textfield.jsonyarn dlx shadcn@latest add https://prototyper-ui.com/r/textfield.jsonbunx --bun shadcn@latest add https://prototyper-ui.com/r/textfield.jsonThis will add the following files to your project:
components/ui/textfield.tsx
Note: This component depends on Field. It will be installed automatically.
Usage
import { TextField, Input } from "@/components/ui/textfield"
import { FieldLabel } from "@/components/ui/field"
<TextField>
<FieldLabel>Name</FieldLabel>
<Input placeholder="Enter your name" />
</TextField>Anatomy
<TextField>
<FieldLabel />
<Input />
<FieldDescription />
<FieldError />
</TextField>Or with TextArea:
<TextField>
<FieldLabel />
<TextArea />
<FieldDescription />
<FieldError />
</TextField>| Sub-component | data-slot | Purpose | Required |
|---|---|---|---|
TextField | text-field | Root field wrapper, provides form context | Yes |
Input | input | Single-line text input | Yes* |
TextArea | textarea | Multi-line text input | Yes* |
FieldLabel | field-label | Label for the text field | No |
FieldDescription | field-description | Descriptive helper text | No |
FieldError | field-error | Validation error message | No |
* Use either Input or TextArea, not both.
Examples
Description
Disabled
Multiline
Read Only
Reusable
Validation
Styling
Data Slots
Use data-slot attributes to target specific parts of the text field:
| Slot name | Element |
|---|---|
text-field | Root wrapper (Field.Root) |
input | The <input> element |
textarea | The <textarea> element |
Customization Examples
/* Remove border and shadow from all inputs */
[data-slot="input"] {
@apply border-0 shadow-none;
}
/* Custom focus ring color */
[data-slot="input"]:focus {
@apply ring-2 ring-blue-500;
}{/* Override size via className */}
<Input className="h-12 text-lg" placeholder="Large input" />API Reference
TextField
Root wrapper that provides form field context. Built on Base UI Field.Root.
Prop
Type
All Base UI Field props are forwarded via ...props.
Input
A styled single-line text input built on Base UI Input.
Prop
Type
All Base UI Input props are forwarded via ...props.
TextArea
A styled multi-line text area using a native <textarea> element.
Prop
Type
All native textarea props are forwarded via ...props.
ProtoTextField
A convenience wrapper that composes TextField, Input/TextArea, FieldLabel, FieldDescription, and FieldError into a single component.
Prop
Type
All Base UI Field props are forwarded via ...props.
inputVariants
A cva helper exported for applying input styles outside of the <Input> component.
import { inputVariants } from "@/components/ui/textfield"
<input className={inputVariants({ size: "sm" })} />Accessibility
Keyboard Interactions
| Key | Action |
|---|---|
Tab | Moves focus into or out of the input |
ARIA Attributes
TextFieldrenders as a Base UIField.Root, automatically associating the label, description, and error message with the input viaaria-labelledby,aria-describedby, andaria-errormessage.- When validation fails,
data-invalidis set on the input and the field root. data-disabledis set when the field is disabled.- Screen readers announce the label, description, and any error messages associated with the input.