# Input

> Text input for React and shadcn on Base UI, with leading and trailing addons and an error state that shakes once.

A Base UI text input whose focus firms the border and grows a soft glow. An error shakes it once, 6px, then the field's message opens with a height spring. Leading and trailing addons.

- Tier: Free (MIT)
- Interaction: Type
- Page: https://eased.dev/components/input
- Installs: @base-ui/react
- Registry: https://eased.dev/r/input.json

## Install

```bash
npx shadcn add https://eased.dev/r/input.json
```

A single-line text input on Base UI's Input, in a bordered shell that holds leading and trailing addons and shows the field's invalid state.

## When to use

- Short free text: a name, an email address, a workspace URL.
- A value with a fixed prefix or unit beside it: `eased.dev/` before a slug, `EUR` after an amount.
- Any text control inside a [Field](/components/field), which gives it a label, help text and errors.

## When not to use

- Text that runs to several lines: use a [Textarea](/components/textarea).
- Numbers people step up and down: use a [Number Field](/components/number-field).
- A fixed-length code from an SMS or an authenticator app: use an [OTP Field](/components/otp-field).
- Picking from a known list: use a [Select](/components/select), or a [Combobox](/components/combobox) when the list is long.

## Usage

```tsx workspace-url.tsx
import { useState } from "react";
import { Field } from "@/components/eased/field/field";
import { Input } from "@/components/eased/input/input";

export function WorkspaceUrl() {
  const [slug, setSlug] = useState("northwind");
  return (
    <Field label="URL" description="Changing it breaks links people have saved.">
      <Input value={slug} onValueChange={setSlug} start="eased.dev/" spellCheck={false} />
    </Field>
  );
}
```

## Examples

### Standalone, with a unit

Outside a Field, name it with `aria-label` and drive the error state with `invalid`.

```tsx
<Input aria-label="Amount" inputMode="decimal" end="EUR" invalid={amount > balance} />
```

### Validated as you type

Inside a Field, the field's validity drives the border and the shake; `invalid` is not needed.

```tsx
<Field label="URL" validate={validateSlug} validationMode="onChange">
  <Input value={slug} onValueChange={setSlug} start="eased.dev/" />
</Field>
```

## API reference

### Input

| Prop | Type | Default | Description |
|---|---|---|---|
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | 32, 36 or 40px tall. |
| `start` | `ReactNode` | | Leading content: an icon, or a prefix such as `https://`. |
| `end` | `ReactNode` | | Trailing content: a unit, a kbd hint, a button. |
| `invalid` | `boolean` | | Marks the input invalid outside a Field: danger border, `aria-invalid`, and one shake when it turns on. Inside a Field, the field's validity drives it. |
| `className` | `string` | `""` | Classes for the bordered shell. |
| `controlClassName` | `string` | `""` | Classes for the `<input>` itself. |

Every other Base UI Input prop passes through to the `<input>`: `value`, `defaultValue`, `onValueChange`, `type`, `placeholder`, `disabled`, `name`, `autoComplete` and the rest.

## Accessibility

- Inside a Field, Base UI ties the label to the input and points `aria-describedby` at the description and error. Outside one, pass `aria-label`.
- `invalid` sets `aria-invalid`, and the danger border stays while the input is focused, so the shake is never the only signal.
- Pressing a non-interactive part of the shell, such as a prefix or an icon, focuses the input; buttons in an addon keep their own clicks.
- Text is 16px on touch screens so iOS does not zoom in on focus.

## Motion

Hover steps the border up once; focus steps it up and grows a soft 3px glow, both over 200ms. An invalid input keeps its danger border and glows in danger while focused. When the input turns invalid the shell shakes once, 6px, over 360ms, and inside a Field the message line springs open under it. Reduced motion drops the shake and the colour transitions, so the border changes at once.

## Notes for AI

Use Input for single-line text and wrap it in a Field for its label and messages. Put prefixes, units and icons in `start` and `end` rather than positioning them yourself, and use `onValueChange` for the string value.

Do not add your own focus ring, error border or shake: the shell draws them. Do not pass `invalid` inside a Field unless you mean to override the field's validity.

## Related

- [Field](/components/field): the label and message line around it.
- [Textarea](/components/textarea): for text that runs to several lines.
- [Number Field](/components/number-field): for numbers with steppers.

## Example

`components/eased/input/input-demo.tsx`

```tsx
"use client";

import { useState } from "react";
import { Field } from "../field/field";
import { DemoFrame } from "../lib/demo-frame";
import { Input } from "./input";

const RESERVED = ["admin", "api", "app", "eased", "www"];

const validateSlug = (value: unknown) => {
  const v = String(value ?? "");
  if (!v) return "Pick a URL for your workspace.";
  if (/[^a-z0-9-]/.test(v)) return "Use lowercase letters, numbers and hyphens.";
  if (v.length < 3) return "Use at least 3 characters.";
  if (RESERVED.includes(v)) return `“${v}” is reserved. Try another.`;
  return null;
};

export function InputDemo() {
  const [name, setName] = useState("Northwind Traders");
  const [slug, setSlug] = useState("northwind");

  return (
    <DemoFrame title="Workspace" meta="Settings">
      <div className="flex min-h-0 flex-1 flex-col gap-4 p-4">
        <Field label="Name">
          <Input value={name} onValueChange={setName} placeholder="Acme Inc." />
        </Field>

        <Field
          label="URL"
          description="Changing it breaks links people have saved."
          validate={validateSlug}
          validationMode="onChange"
        >
          <Input
            value={slug}
            onValueChange={setSlug}
            start={<span className="-mr-2 text-ui text-text-muted">eased.dev/</span>}
            spellCheck={false}
            autoCapitalize="off"
          />
        </Field>

        <Field label="Region" description="Data residency is set when the workspace is created." disabled>
          <Input
            defaultValue="Frankfurt (eu-central-1)"
            start={
              <svg viewBox="0 0 16 16" fill="none" aria-hidden>
                <path
                  d="M4.5 7V5.5a3.5 3.5 0 0 1 7 0V7m-7.75 0h8.5c.41 0 .75.34.75.75v5c0 .41-.34.75-.75.75h-8.5a.75.75 0 0 1-.75-.75v-5c0-.41.34-.75.75-.75Z"
                  stroke="currentColor"
                  strokeWidth="1.5"
                  strokeLinecap="round"
                />
              </svg>
            }
          />
        </Field>
      </div>
    </DemoFrame>
  );
}
```
