Skip to Content
Zuri
Components

Input group

Wraps an input with an icon, prefix, suffix or button on either side, so they read as one control.

Live preview
Theme
Preview width
@
TZS

Use InputGroup when a field needs something beside it: a search icon, an @ for a username, a unit like TZS, or a button to show a password or clear the text. For phone numbers use Phone input, which adds a country dropdown. The group draws the border and the focus ring, and the input inside is made borderless, so the pieces look like one control.

Installation

pnpm dlx shadcn@latest add https://components.abdulqadirmsingi.com/r/input-group.json

This also installs Input, which it is built on.

Usage

import { Input } from "@/components/ui/input";
import { InputGroup } from "@/components/ui/input-group";
import { Label } from "@/components/ui/label";

<Label htmlFor="amount">Amount</Label>
<InputGroup end={<span>TZS</span>}>
  <Input id="amount" inputMode="numeric" />
</InputGroup>

Give the input its label, as usual. The group has no name of its own.

Buttons at either end

A button in start or end needs its own accessible name, and a toggle needs aria-pressed.

Live preview
Theme
Preview width
<InputGroup
  end={
    <Button variant="ghost" size="icon-sm" aria-label="Show password" aria-pressed={shown} onClick={toggle}>
      <EyeIcon />
    </Button>
  }
>
  <Input id="pass" type={shown ? "text" : "password"} autoComplete="new-password" />
</InputGroup>

Looks and sizes

It takes the same variant and size as Input. An invalid input inside turns the group's border red by itself.

Live preview
Theme
Preview width
TZS
TZS

Props

InputGroup extends native <div> props (except children) and spreads them onto the wrapper, including ref (React 19).

Props
PropTypeDefaultDescription
childrenReactNode–The field: an `Input`, or any native `<input>`. Required.
startReactNode–Content before the field: an icon or a short prefix.
endReactNode–Content after the field: a unit or a button.
variant"default" | "soft" | "underline" | "glass""default"The surface, as on Input.
size"sm" | "md" | "lg""md"The height, as on Input.
halobooleantrueThe soft grey glow around the group while its input has focus. Set false to keep only the border change.
classNamestring–Merged with the built-in classes; yours win on conflicts.

Accessibility

  • The input inside keeps its own label and is the only focusable field. The group is a plain div with no role.
  • The focus ring appears around the whole group when the input has focus.
  • Icons are decorative: give them aria-hidden="true". A text prefix or suffix such as "TZS" is visible but is not part of the input's name, so say the unit in the label too (for example "Amount in TZS") when it matters.
  • Buttons inside need an aria-label when they show only an icon, and a toggle needs aria-pressed. They are 32 pixels at the smallest size, above the 24-pixel WCAG minimum.
  • Invalid state comes from the input's own aria-invalid; the red border is not the only signal when you also show an error message (see Field).

Tokens used

The same as Input, plus --muted-foreground for the ends.

Known limitations

  • It makes the first <input> inside borderless with a descendant selector, so put one field in the group.
  • It does not connect a label to the input for you. Use htmlFor and id, or build the field with Field.
  • Not for a <textarea> or <select>.

Source

import type { VariantProps } from "class-variance-authority";import type { ComponentProps, ReactNode } from "react";import { inputVariants } from "@/components/ui/input";import { cn } from "@/lib/utils";export interface InputGroupProps  extends Omit<ComponentProps<"div">, "children">,    Omit<VariantProps<typeof inputVariants>, "halo"> {  /** The soft grey glow around the group while its input has focus. Defaults to true. */  halo?: boolean;  start?: ReactNode;  end?: ReactNode;  children: ReactNode;}export function InputGroup({  start,  end,  variant,  size,  halo = true,  className,  children,  ...props}: InputGroupProps) {  return (    <div      className={cn(        inputVariants({ variant, size, halo: false }),        "flex items-center gap-2 has-[input:disabled]:cursor-not-allowed has-[input:disabled]:opacity-50 has-[input:focus-visible:not([aria-invalid=true])]:border-ring has-[[aria-invalid=true]]:border-danger has-[[aria-invalid=true]]:animate-[zuri-shake_var(--duration-slow)_var(--ease-out)] motion-reduce:animate-none [&_input]:aria-[invalid=true]:animate-none",        "[&_input]:h-full [&_input]:min-h-0 [&_input]:flex-1 [&_input]:border-0 [&_input]:bg-transparent [&_input]:p-0 [&_input]:outline-none [&_input]:focus-visible:border-transparent [&_input]:focus-visible:ring-0 [&_input]:placeholder:text-muted-foreground",        halo &&          variant !== "underline" &&          "has-[input:focus-visible]:ring-4 has-[input:focus-visible]:ring-foreground/10",        className,      )}      {...props}    >      {start ? (        <span className="flex shrink-0 items-center self-stretch text-muted-foreground [&_svg]:size-4">          {start}        </span>      ) : null}      {children}      {end ? (        <span className="flex shrink-0 items-center text-muted-foreground [&_svg]:size-4">          {end}        </span>      ) : null}    </div>  );}

On this page