GooseUI

Components

Input Group

New

One border and one focus ring around an input and its addons. The group draws the ring through :focus-within and turns red through :has(:user-invalid), the inner input has no border of its own. Order in the DOM is the order on screen. Server component, no JavaScript.

Browser Support

Baseline Widely available
2 features
Details
:focus-within

Draws the focus ring around the whole group

Your browser:
:has()

Turns the group border red when the inner input is invalid. Without it the border stays neutral

Your browser:

Preview

Installation

npx shadcn@latest add @gooseui/input-group
pnpm dlx shadcn@latest add @gooseui/input-group
yarn dlx shadcn@latest add @gooseui/input-group
bunx --bun shadcn@latest add @gooseui/input-group

Usage

import { Search } from "lucide-react"
import {
  InputGroup,
  InputGroupAddon,
  InputGroupInput,
} from "@/components/ui/input-group"

export default function Example() {
  return (
    <InputGroup>
      <InputGroupAddon>
        <Search />
      </InputGroupAddon>
      <InputGroupInput type="search" aria-label="Search" placeholder="Search…" />
    </InputGroup>
  )
}

Examples

Clear animation

Type something and press the X, or select the text and press Delete. The X pops in and the placeholder slides back. Pure CSS, no JavaScript.

<InputGroup>
  <InputGroupAddon>
    <Search />
  </InputGroupAddon>
  <InputGroupInput
    type="search"
    aria-label="Search"
    placeholder="Search…"
  />
</InputGroup>

Text prefix and suffix

InputGroupText holds a short label before or after the value.

https://
.com
<InputGroup>
  <InputGroupAddon>
    <InputGroupText>https://</InputGroupText>
  </InputGroupAddon>
  <InputGroupInput aria-label="Domain" placeholder="example" />
  <InputGroupAddon>
    <InputGroupText>.com</InputGroupText>
  </InputGroupAddon>
</InputGroup>

Button

InputGroupButton is a small Button for an action next to the input.

<InputGroup>
  <InputGroupAddon>
    <AtSign />
  </InputGroupAddon>
  <InputGroupInput type="email" aria-label="Email" placeholder="name@example.com" />
  <InputGroupAddon>
    <InputGroupButton variant="secondary">Subscribe</InputGroupButton>
  </InputGroupAddon>
</InputGroup>

Validation

The group reacts to the input: :user-invalid and aria-invalid turn the border red.

<InputGroup>
  <InputGroupAddon>
    <AtSign />
  </InputGroupAddon>
  <InputGroupInput type="email" aria-label="Email" aria-invalid="true" />
</InputGroup>

Props

PropTypeDefaultDescription
classNamestring-Additional CSS classes

Parts

PartElementDescription
InputGroupdivBorder, focus ring and invalid state; role="group"
InputGroupAddondivSlot before or after the input for an icon, text or button
InputGroupTextspanText inside an addon
InputGroupInputinputBorderless input; takes all the remaining width
InputGroupButtonbuttonButton for an addon; ghost and small by default