@cf/ui

@cf/input-group

Input Group

A bordered shell that joins an input or textarea with addons, buttons and text, sharing one focus ring.

Stock shadcn base-nova. Clicking an addon focuses the control, unless the click lands on a button. The chat composer is the one real use: a quote strip in a block-start addon, the InputGroupTextarea, and send and stop buttons in a block-end addon.

The group is h-8, which doesn't agree with InputGroupInput: it inherits Input's h-11 below md, so a single-line group will overflow on touch screens until one of them gives. I've only used it with a textarea so far, where the group goes h-auto. Icons also follow a different convention here: InputGroupButton sizes bare svg children rather than data-icon ones.

import {
  InputGroup,
  InputGroupAddon,
  InputGroupButton,
  InputGroupTextarea,
} from "@/components/ui/input-group";
 
<InputGroup>
  <InputGroupTextarea aria-label="Message" rows={1} />
  <InputGroupAddon align="block-end">
    <InputGroupButton aria-label="Send" className="ml-auto" size="icon-xs" type="submit">
      <ArrowUpIcon />
    </InputGroupButton>
  </InputGroupAddon>
</InputGroup>

Props

PropTypeDefault
InputGroupAddon aligninline-start | inline-end | block-start | block-endinline-start
InputGroupButton sizexs | sm | icon-xs | icon-smxs
InputGroupButton variantButton variantghost
InputGroupButton typebutton | submit | resetbutton

Rules

The same rules ship in DESIGN.md and the MCP server, for the agents building with this.

  • must

    Put InputGroupInput or InputGroupTextarea inside the group, never a bare Input or Textarea.

    The shared focus and invalid rings watch for data-slot="input-group-control", which only the group's own controls set.

    use-group-controls

  • must

    Use InputGroupButton for buttons inside an InputGroupAddon, and pass type="submit" explicitly for a send button, since it defaults to type="button".

    buttons-in-addons

  • must

    Give every icon-only InputGroupButton (size="icon-xs" or size="icon-sm") an aria-label.

    icon-buttons-named

  • should

    Use align="block-start" or align="block-end" on InputGroupAddon for rows above or below a textarea, and the inline-* values for prefixes and suffixes on a single-line input.

    block-align-for-toolbars

Install

bunx shadcn@latest add @cf/input-group

Needs the @cf registry in your components.json once. The theme and any sibling components come along automatically.

Source

input-group.tsxShow
"use client";
 
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "cn";
import type * as React from "react";
 
import { Button } from "./button";
import { Input } from "./input";
import { Textarea } from "./textarea";
 
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      className={cn(
        "group/input-group relative flex h-8 w-full min-w-0 items-center rounded-lg border border-input outline-none transition-colors in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-start]]:h-auto has-[>textarea]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:flex-col has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot][aria-invalid=true]]:border-destructive has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:bg-input/30 dark:has-disabled:bg-input/80 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
        className
      )}
      data-slot="input-group"
      role="group"
      {...props}
    />
  );
}
 
const inputGroupAddonVariants = cva(
  "flex h-auto cursor-text select-none items-center justify-center gap-2 py-1.5 font-medium text-muted-foreground text-sm group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",
  {
    defaultVariants: {
      align: "inline-start",
    },
    variants: {
      align: {
        "block-end":
          "order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2",
        "block-start":
          "order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2",
        "inline-end":
          "order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]",
        "inline-start":
          "order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]",
      },
    },
  }
);
 
function InputGroupAddon({
  className,
  align = "inline-start",
  ...props
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
  return (
    // biome-ignore lint/a11y/noNoninteractiveElementInteractions: Upstream shadcn behaviour; the click only forwards pointer focus to the control, which is already keyboard reachable.
    // biome-ignore lint/a11y/useKeyWithClickEvents: See above; there is no keyboard equivalent to add.
    <div
      className={cn(inputGroupAddonVariants({ align }), className)}
      data-align={align}
      data-slot="input-group-addon"
      onClick={(e) => {
        if ((e.target as HTMLElement).closest("button")) {
          return;
        }
        e.currentTarget.parentElement
          ?.querySelector<HTMLElement>("input, textarea")
          ?.focus();
      }}
      role="group"
      {...props}
    />
  );
}
 
const inputGroupButtonVariants = cva(
  "flex items-center gap-2 text-sm shadow-none",
  {
    defaultVariants: {
      size: "xs",
    },
    variants: {
      size: {
        "icon-sm": "size-8 p-0 has-[>svg]:p-0",
        "icon-xs":
          "size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0",
        sm: "",
        xs: "h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
      },
    },
  }
);
 
function InputGroupButton({
  className,
  type = "button",
  variant = "ghost",
  size = "xs",
  ...props
}: Omit<React.ComponentProps<typeof Button>, "size" | "type"> &
  VariantProps<typeof inputGroupButtonVariants> & {
    type?: "button" | "submit" | "reset";
  }) {
  return (
    <Button
      className={cn(inputGroupButtonVariants({ size }), className)}
      data-size={size}
      type={type}
      variant={variant}
      {...props}
    />
  );
}
 
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
  return (
    <span
      className={cn(
        "flex items-center gap-2 text-muted-foreground text-sm [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none",
        className
      )}
      {...props}
    />
  );
}
 
function InputGroupInput({
  className,
  ...props
}: React.ComponentProps<"input">) {
  return (
    <Input
      className={cn(
        "flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
        className
      )}
      data-slot="input-group-control"
      {...props}
    />
  );
}
 
function InputGroupTextarea({
  className,
  ...props
}: React.ComponentProps<"textarea">) {
  return (
    <Textarea
      className={cn(
        "flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
        className
      )}
      data-slot="input-group-control"
      {...props}
    />
  );
}
 
export {
  InputGroup,
  InputGroupAddon,
  InputGroupButton,
  InputGroupInput,
  InputGroupText,
  InputGroupTextarea,
};