---
title: "Input"
description: "Text input with label, left/right icons, optional stable error row, error shake and success check draw."
category: "Components"
publishedAt: "2026-06-29"
updatedAt: "2026-11-24"
documentation: "https://beui.dev/components/motion/input"
markdown: "https://beui.dev/components/motion/input.md"
license: "MIT"
---

# Input

> Text input with label, left/right icons, optional stable error row, error shake and success check draw.

## Install

```bash
npx shadcn@latest add @beui/input
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `tailwind-merge`

## Usage

```tsx
"use client";

import { Eye, EyeOff, Mail, Search } from "lucide-react";
import { useState } from "react";
import { Input } from "@/components/motion/input";

export function InputPreview() {
  const [email, setEmail] = useState("");
  const [pass, setPass] = useState("hunter2");
  const [query, setQuery] = useState("Ada");
  const [show, setShow] = useState(false);

  const emailError =
    email.length > 0 && !email.includes("@") ? "Enter a valid email address." : undefined;

  return (
    <div className="flex w-full max-w-xs flex-col gap-1">
      <Input
        label="Email"
        type="email"
        placeholder="you@example.com"
        leftIcon={<Mail />}
        value={email}
        onChange={setEmail}
        error={emailError}
        reserveErrorLine
      />
      <Input
        label="Password"
        type={show ? "text" : "password"}
        value={pass}
        onChange={setPass}
        rightIcon={
          <button
            type="button"
            onClick={() => setShow((s) => !s)}
            aria-label={show ? "Hide password" : "Show password"}
            className="pointer-events-auto"
          >
            {show ? <EyeOff /> : <Eye />}
          </button>
        }
        reserveErrorLine
      />
      <Input
        label="Search"
        leftIcon={<Search />}
        value={query}
        onChange={setQuery}
        success={query.length > 1}
        reserveErrorLine
      />
    </div>
  );
}
```

## API Reference

### Input

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `label` | `string` |  | No | Text shown above the field and tied to it as its label. |
| `value` | `string` |  | No | The field text, for controlled use. |
| `defaultValue` | `string` |  | No | The initial field text when uncontrolled. |
| `onChange` | `((value: string) => void)` |  | No | Called with the new text on every edit. |
| `error` | `string \| boolean` |  | No | Truthy error triggers a shake, red border and (if a string) a message. |
| `reserveErrorLine` | `boolean` | `false` | No | Reserve one message line so validation does not shift nearby content. |
| `success` | `boolean` |  | No | Shows a green check in place of `rightIcon`. |
| `leftIcon` | `ReactNode` |  | No | Icon inside the field, before the text. |
| `rightIcon` | `ReactNode` |  | No | Icon inside the field, after the text. Hidden while `success` is set. |
| `className` | `string` |  | No | Classes merged onto the root element. |
| `classNames` | `InputClassNames` |  | No | Classes for the root, label, field, input, icons and error message. |

## Types

### InputClassNames

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `root` | `string` | No | Classes for the outer wrapper. |
| `label` | `string` | No | Classes for the label above the field. |
| `field` | `string` | No | Classes for the bordered box around the input and icons. |
| `input` | `string` | No | Classes for the input element. |
| `leftIcon` | `string` | No | Classes for the wrapper of the icon before the text. |
| `rightIcon` | `string` | No | Classes for the wrapper of the icon after the text. |
| `successIcon` | `string` | No | Classes for the check mark shown while `success` is set. |
| `errorMessage` | `string` | No | Classes for the error message under the field. |

## About Input

Input is an animated text field for React built with Framer Motion and Tailwind CSS. It takes an optional label, left and right icons, and shows validation through motion: an error shakes the field and slides in a message, and a success state draws a check mark at the right edge. It works controlled or uncontrolled and forwards its ref to the native input element.

### When to use it

- A sign-up or login form needs fields that clearly react to validation errors without a separate error component.
- A search, email or URL field needs a leading icon or a trailing action button such as a clear or reveal control.
- A form that validates on blur needs a reserved message line so errors appearing do not push the layout down.

### Accessibility

The label is a real label element tied to the input, and an error sets aria-invalid on the field. A string error renders a message with the alert role that the input references through aria-describedby, so screen readers announce it and read it again on focus. With reduced motion enabled, the shake is skipped, the error message fades without sliding or blurring, and the success check appears already drawn.

### FAQ

**How do I show an error message on an input in React?**

Pass a string to the error prop. The field shakes, turns red and shows the message below it. Passing true shows the error styling and shake without a message.

**How do I stop validation errors from shifting the layout?**

Set reserveErrorLine. The input keeps one message line of space below the field, so an error appearing or clearing does not move nearby content.

**Can I use this input with a form library?**

Yes. Input forwards its ref to the native input and passes through standard input props such as name, type and onBlur. Note that onChange receives the string value rather than the change event.

## React Native

A React Native version ships in beUI Native. The detail JSON has every file to copy.

```bash
npx expo install react-native-reanimated react-native-worklets
npm install uniwind tailwindcss
```

- Native detail: https://beui.dev/native/r/input
- GitHub: https://github.com/starc007/beui-native/tree/main/src/components/input

## Source

- Registry detail: https://beui.dev/r/input
- Raw source: https://beui.dev/r/input/raw
- GitHub: https://github.com/starc007/ui-components
