Text Field

Loading...

Installation

Add the component with the CLI.

npx shadcn@latest add @intentui/text-field

Composed components

When you install this component via the CLI, it automatically loads all composed components, so you don’t need to add them individually.

Manual installation

Install the dependencies, then copy the component source into your project.

npm install react-aria-components @heroicons/react

Anatomy

import { TextField } from "@/components/ui/text-field"

<TextField
  name="name"
  type="text"
  label="Name"
  description="Enter your name"
  placeholder="John Doe"
  errorMessage="This field is required"
  prefix="..."
  suffix="..."
/>

Examples

Prefix and suffix

Wrap Input with InputGroup to add prefix and suffix content.

Loading...

Suffix button

Wrap Input with InputGroup to add a button as the suffix.

Loading...

Revealable

When using a text field as a password input, you may want the option to reveal the password.

Loading...

Validation

Set isRequired to require a value when the form is submitted.

Loading...

Controlled

Pass value and update it with onChange to control the text field.

Loading...

Uncontrolled

Use defaultValue to set the initial text of an uncontrolled text field.

Loading...

Description

Add Description inside TextField to provide supporting text.

Loading...

Readonly

Set the TextField to readonly, preventing any edits.

Loading...

Disabled

When the TextField is disabled, it becomes non-editable and appears inactive.

Loading...

Component API

TextField

TextField extends the React Aria Components <TextField> component.

classNamestring

See the React Aria for the full API reference.

Design