Input Group

Groups an input with leading or trailing addons. Install Input Group from the VLLNT UI registry with the shadcn CLI.

Report a bug

Groups an input with leading or trailing addons. Part of the form family in VLLNT UI, it ships as a machine-readable registry entry — copy the source directly into your app with the shadcn CLI and own it, no runtime dependency on a component library.

Preview

Switch between light and dark to inspect the embedded Storybook preview.

Installation

Add Input Group to your project with the shadcn CLI. The source lands in your codebase, ready to adapt:

pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/input-group.json

Source

import * as React from "react"; import { cva, type VariantProps } from "class-variance-authority"; import { cn } from "../../lib/utils"; const inputGroupVariants = cva( "flex w-full items-center overflow-hidden rounded-md border border-input bg-background text-sm ring-offset-background focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 has-[input:disabled]:cursor-not-allowed has-[input:disabled]:opacity-50", ); const inputGroupAddonVariants = cva( "flex shrink-0 items-center text-muted-foreground [&_svg]:size-4 [&_svg]:shrink-0", { defaultVariants: { align: "leading", }, variants: { align: { leading: "pl-3", trailing: "pr-3", }, }, }, ); /** Container that groups an input with leading or trailing addons. */ export type InputGroupProps = React.ComponentPropsWithoutRef<"div">; const InputGroup = ({ className, ref, ...props }: InputGroupProps & { ref?: React.Ref<HTMLDivElement> }) => ( <div className={cn(inputGroupVariants(), className)} data-slot="input-group" ref={ref} role="group" {...props} /> ); InputGroup.displayName = "InputGroup"; /** Leading or trailing addon (icon, text, or action) inside an InputGroup. */ export type InputGroupAddonProps = React.ComponentPropsWithoutRef<"div"> & VariantProps<typeof inputGroupAddonVariants>; const InputGroupAddon = ({ align, className, ref, ...props }: InputGroupAddonProps & { ref?: React.Ref<HTMLDivElement> }) => ( <div className={cn(inputGroupAddonVariants({ align }), className)} data-slot="input-group-addon" ref={ref} {...props} /> ); InputGroupAddon.displayName = "InputGroupAddon"; /** Borderless input that fills the remaining space inside an InputGroup. */ export type InputGroupInputProps = React.ComponentPropsWithoutRef<"input">; const InputGroupInput = ({ className, ref, ...props }: InputGroupInputProps & { ref?: React.Ref<HTMLInputElement> }) => ( <input className={cn( "h-10 w-full flex-1 bg-transparent px-3 py-2 placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed", className, )} ref={ref} {...props} /> ); InputGroupInput.displayName = "InputGroupInput"; export { InputGroup, InputGroupAddon, inputGroupAddonVariants, InputGroupInput, inputGroupVariants, };

Stories

Explore every variant and state in the interactive Storybook:

Preview

Switch between light and dark to inspect the embedded Storybook preview.

Dependencies

  • @vllnt/ui@^0.3.0