# Input

> A surface-first text input built on Base UI's Input primitive, with filled and outlined variants, shapes, sizes, leading addons, and inline button/badge support.

Canonical URL: https://taut-ui.com/docs/components/input

```tsx
import { Input } from "@/components/ui/input";

export default function Particle() {
  return <Input className="w-72" placeholder="Enter your email" type="email" />;
}
```

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/input.json
```

**Manual**

- Install the following dependencies:

```bash
npm install @base-ui/react class-variance-authority
```

- Copy and paste the following code into your project.

```tsx title="components/ui/input.tsx"
"use client";

import { Input as InputPrimitive } from "@base-ui/react/input";
import { cva, type VariantProps } from "class-variance-authority";
import type * as React from "react";
import { cn } from "@/lib/utils";

export const inputVariants = cva(
  [
    "group/input relative inline-flex w-full min-w-0 items-center text-foreground outline-none",
    "focus-within:shadow-[inset_0_0_0_0.125rem_var(--color-primary)]",
    "has-[[aria-invalid=true]]:shadow-[inset_0_0_0_0.125rem_var(--color-destructive)]! data-invalid:shadow-[inset_0_0_0_0.125rem_var(--color-destructive)]!",
    "has-autofill:bg-[color-mix(in_oklab,var(--color-background),var(--color-foreground)_8%)]",
    "has-disabled:pointer-events-none has-disabled:opacity-38 data-disabled:pointer-events-none data-disabled:opacity-38",
    "[&_svg]:shrink-0 [&_svg]:transition-none",
    "[&_button]:transition-none",
    "[&_[data-slot=ripple-hover]]:transition-none!",
    "[&_svg:not(button_*)]:text-muted-foreground focus-within:[&_svg:not(button_*)]:text-primary",
    "has-[[aria-invalid=true]]:[&_svg:not(button_*)]:text-destructive! data-invalid:[&_svg:not(button_*)]:text-destructive!",
    "[&_button[data-variant=ghost]:hover]:text-foreground [&_button[data-variant=ghost]:hover_svg]:text-foreground [&_button[data-variant=ghost]]:text-muted-foreground focus-within:[&_button[data-variant=ghost]]:text-primary",
    "[&:not(:has([data-align=block-start],[data-align=block-end]))_button]:h-[calc(100%-0.5rem)]",
    "[&:not(:has([data-align=block-start],[data-align=block-end]))_button[data-size^=icon]]:aspect-square [&:not(:has([data-align=block-start],[data-align=block-end]))_button[data-size^=icon]]:w-auto",
    "[&:not(:has([data-align=block-start],[data-align=block-end]))_[data-slot=badge]:not([data-size=dot])]:h-[calc(100%-0.5rem)] [&:not(:has([data-align=block-start],[data-align=block-end]))_[data-slot=badge]:not([data-size=dot])]:px-3",
    "data-[shape=rounded]:[&_button]:[--r-full:0.5rem] data-[shape=square]:[&_button]:[--r-full:0.375rem]",
    "data-[shape=rounded]:[&_[data-slot=badge]]:rounded-lg data-[shape=square]:[&_[data-slot=badge]]:rounded-md",
  ],
  {
    defaultVariants: {
      shape: "pill",
      size: "default",
      variant: "filled",
    },
    variants: {
      shape: {
        pill: "rounded-full",
        round: "rounded-full",
        rounded: "rounded-xl",
        square: "rounded-lg",
      },
      size: {
        default:
          "h-10 gap-2.5 px-4 text-sm has-[>[data-slot=badge]:first-child]:ps-1 has-[>button:first-child]:ps-1 has-[>[data-slot=badge]:last-child]:pe-1 has-[>button:last-child]:pe-1 [&_svg:not([class*='size-'])]:size-4.5",
        lg: "h-12 gap-3 px-5 text-base has-[>[data-slot=badge]:first-child]:ps-1 has-[>button:first-child]:ps-1 has-[>[data-slot=badge]:last-child]:pe-1 has-[>button:last-child]:pe-1 [&_svg:not([class*='size-'])]:size-5",
        md: "h-10 gap-2.5 px-4 text-sm has-[>[data-slot=badge]:first-child]:ps-1 has-[>button:first-child]:ps-1 has-[>[data-slot=badge]:last-child]:pe-1 has-[>button:last-child]:pe-1 [&_svg:not([class*='size-'])]:size-4.5",
        sm: "h-9 gap-2 px-3 text-sm has-[>[data-slot=badge]:first-child]:ps-1 has-[>button:first-child]:ps-1 has-[>[data-slot=badge]:last-child]:pe-1 has-[>button:last-child]:pe-1 [&_svg:not([class*='size-'])]:size-4",
      },
      variant: {
        filled:
          "bg-[color-mix(in_oklab,var(--color-background),var(--color-foreground)_6%)] shadow-[inset_0_0_0_0.0625rem_var(--color-border)]",
        outline:
          "bg-background shadow-[inset_0_0_0_0.0625rem_var(--color-input)]",
        outlined:
          "bg-background shadow-[inset_0_0_0_0.0625rem_var(--color-input)]",
      },
    },
  },
);

export type InputProps = Omit<
  InputPrimitive.Props & React.RefAttributes<HTMLInputElement>,
  "size"
> &
  VariantProps<typeof inputVariants> & {
    size?: VariantProps<typeof inputVariants>["size"] | number;
    startAddon?: React.ReactNode;
    unstyled?: boolean;
    nativeInput?: boolean;
    children?: React.ReactNode;
  };

export function Input({
  className,
  variant = "filled",
  shape = "pill",
  size = "default",
  startAddon,
  unstyled = false,
  nativeInput = false,
  style,
  children,
  ...props
}: InputProps): React.ReactElement {
  const variantSize = typeof size === "number" ? "default" : size;
  const htmlSize = typeof size === "number" ? size : undefined;
  const inputClassName = cn(
    "m-0 h-full w-full min-w-0 flex-1 border-0 bg-transparent p-0 text-foreground outline-none ring-0",
    "placeholder:text-muted-foreground/72 focus:outline-none focus:ring-0 disabled:cursor-not-allowed",
    "[transition:background-color_5000000s_ease-in-out_0s] autofill:[-webkit-text-fill-color:var(--foreground)]",
    props.type === "search" &&
      "[&::-webkit-search-cancel-button]:appearance-none [&::-webkit-search-decoration]:appearance-none [&::-webkit-search-results-button]:appearance-none [&::-webkit-search-results-decoration]:appearance-none",
    props.type === "file" &&
      "h-auto cursor-pointer text-muted-foreground file:me-3 file:cursor-pointer file:border-0 file:bg-transparent file:p-0 file:font-medium file:text-foreground file:text-sm",
  );

  return (
    <span
      className={
        cn(
          !unstyled && inputVariants({ shape, size: variantSize, variant }),
          className,
        ) || undefined
      }
      data-shape={shape}
      data-size={variantSize}
      data-slot="input-control"
      data-variant={variant}
    >
      {startAddon && (
        <span
          aria-hidden="true"
          className="pointer-events-none flex shrink-0 items-center justify-center"
          data-slot="input-start-addon"
        >
          {startAddon}
        </span>
      )}
      {nativeInput ? (
        <input
          className={inputClassName}
          data-slot="input"
          size={htmlSize}
          style={typeof style === "function" ? undefined : style}
          {...props}
        />
      ) : (
        <InputPrimitive
          className={inputClassName}
          data-slot="input"
          size={htmlSize}
          style={style}
          {...props}
        />
      )}
      {children}
    </span>
  );
}

export { InputPrimitive };
```

- Update the import paths to match your project setup.

## Usage [#usage]

```tsx
import { Input } from "@/components/ui/input"
```

```tsx
<Input placeholder="Enter your email" type="email" />
```

## Examples [#examples]

### Outline [#outline]

```tsx
import { Input } from "@/components/ui/input";

export default function Particle() {
  return (
    <Input
      className="w-72"
      placeholder="Enter your email"
      type="email"
      variant="outline"
    />
  );
}
```

### Rounded [#rounded]

```tsx
import { Input } from "@/components/ui/input";

export default function Particle() {
  return <Input className="w-72" placeholder="Rounded input" shape="rounded" />;
}
```

### Small [#small]

```tsx
import { Input } from "@/components/ui/input";

export default function Particle() {
  return <Input className="w-72" placeholder="Small input" size="sm" />;
}
```

### Large [#large]

```tsx
import { Input } from "@/components/ui/input";

export default function Particle() {
  return <Input className="w-72" placeholder="Large input" size="lg" />;
}
```

### With Leading Icon [#with-leading-icon]

```tsx
import { SearchIcon } from "lucide-react";
import { Input } from "@/components/ui/input";

export default function Particle() {
  return (
    <Input
      className="w-72"
      placeholder="Search components…"
      startAddon={<SearchIcon />}
      type="search"
    />
  );
}
```

### Password Toggle [#password-toggle]

```tsx
"use client";

import { EyeIcon, EyeOffIcon } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";

export default function Particle() {
  const [visible, setVisible] = useState(false);

  return (
    <Input
      className="w-72"
      defaultValue="s3cr3t-p@ss"
      placeholder="Password"
      type={visible ? "text" : "password"}
    >
      <Button
        aria-label={visible ? "Hide password" : "Show password"}
        onClick={() => setVisible((prev) => !prev)}
        size="icon"
        variant="ghost"
      >
        {visible ? <EyeOffIcon /> : <EyeIcon />}
      </Button>
    </Input>
  );
}
```

### Invalid [#invalid]

```tsx
import { Input } from "@/components/ui/input";

export default function Particle() {
  return (
    <Input
      aria-invalid="true"
      className="w-72"
      defaultValue="invalid-email"
      placeholder="Enter your email"
      type="email"
    />
  );
}
```

### Disabled [#disabled]

```tsx
import { Input } from "@/components/ui/input";

export default function Particle() {
  return <Input className="w-72" disabled placeholder="Disabled input" />;
}
```

### File [#file]

```tsx
import { Input } from "@/components/ui/input";

export default function Particle() {
  return <Input className="w-72" type="file" />;
}
```

## API Reference [#api-reference]

### Input [#input]

Wraps Base UI `Input` inside a styled container that automatically sizes trailing buttons, badges, and leading addons.

| Prop          | Type                                          | Default     | Description                                                                   |
| ------------- | --------------------------------------------- | ----------- | ----------------------------------------------------------------------------- |
| `variant`     | `"filled" \| "outline" \| "outlined"`         | `"filled"`  | `"filled"` uses a solid tonal surface; `"outline"` adds an inset border       |
| `shape`       | `"pill" \| "round" \| "rounded" \| "square"`  | `"pill"`    | Border-radius shape of the container and nested buttons/badges                |
| `size`        | `"sm" \| "default" \| "md" \| "lg" \| number` | `"default"` | Height and padding preset; pass a number to forward the HTML `size` attribute |
| `startAddon`  | `React.ReactNode`                             | -           | Leading element (such as an icon) rendered before the input                   |
| `children`    | `React.ReactNode`                             | -           | Trailing elements (buttons, badges, icons) rendered inside the container      |
| `unstyled`    | `boolean`                                     | `false`     | Suppresses default variant styling on the outer wrapper                       |
| `nativeInput` | `boolean`                                     | `false`     | Renders a plain `<input>` instead of Base UI's `Input` primitive              |
| `className`   | `string`                                      | -           | Additional CSS classes applied to the outer container                         |
| `...props`    | Base UI Input props                           | -           | All standard input attributes (`type`, `disabled`, `aria-invalid`, etc.)      |

### inputVariants [#inputvariants]

A `cva` helper exported for composing consistent input surfaces in other components (such as `AutocompleteInput`).
