Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Input Group

FreeNew

An input with icons, units, prefixes or buttons at either end, sharing one border and one focus ring.

Installation

pnpm dlx shadcn@latest add @viewport/input-group

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

input-group-demo.tsx
import { AtSign, Search } from "lucide-react";
import { CopyButton } from "@/components/viewport/copy-button";
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/viewport/input-group";
import { Kbd } from "@/components/viewport/kbd";

export default function InputGroupDemo() {
  return (
    <div className="flex w-full max-w-sm flex-col gap-3">
      <InputGroup>
        <InputGroupAddon>
          <Search aria-hidden />
        </InputGroupAddon>
        <InputGroupInput aria-label="Search contacts" placeholder="Search contacts" />
        <InputGroupAddon>
          <Kbd>/</Kbd>
        </InputGroupAddon>
      </InputGroup>

      <InputGroup>
        <InputGroupAddon boxed>https://</InputGroupAddon>
        <InputGroupInput aria-label="Subdomain" defaultValue="northwind" spellCheck={false} />
        <InputGroupAddon boxed>.acme.app</InputGroupAddon>
      </InputGroup>

      <InputGroup>
        <InputGroupAddon>$</InputGroupAddon>
        <InputGroupInput aria-label="Deal value in US dollars" inputMode="decimal" defaultValue="48,000" className="tabular-nums" />
        <InputGroupAddon>USD</InputGroupAddon>
      </InputGroup>

      <InputGroup>
        <InputGroupAddon>
          <AtSign aria-hidden />
        </InputGroupAddon>
        <InputGroupInput aria-label="Invite link" readOnly defaultValue="acme.app/i/7Fq2Lm" className="font-mono text-xs sm:text-xs" />
        <InputGroupAddon className="pe-1">
          <CopyButton value="https://acme.app/i/7Fq2Lm" label="Copy invite link" />
        </InputGroupAddon>
      </InputGroup>
    </div>
  );
}

Props

PropTypeDefault
boxedboolean

Give the addon its own tinted cell with a divider, for prefixes such as "https://".

false

Accessibility

  • A group whose focus ring surrounds every part, so it reads as one control.
  • Pressing an icon or unit focuses the input.
  • Addon corners follow the writing direction.
  • Respects prefers-reduced-motion.