Input Group

Puts icons, text and buttons inside a single input frame.

12 results
import { Input } from "@/components/ui/input"
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupText } from "@/components/ui/input-group"
import { ArrowUpIcon } from "@phosphor-icons/react/dist/csr/ArrowUp"
import { MagnifyingGlassIcon } from "@phosphor-icons/react/dist/csr/MagnifyingGlass"
import { VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

export default function InputGroupDemo() {
  return (
    <VStack gap={4} xstyle={widths.xs}>
      <InputGroup>
        <Input placeholder="Search projects" aria-label="Search projects" />
        <InputGroupAddon>
          <MagnifyingGlassIcon aria-hidden="true" />
        </InputGroupAddon>
        <InputGroupAddon align="inline-end">
          <InputGroupText>12 results</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
      <InputGroup>
        <Input placeholder="Ask a question" aria-label="Ask a question" />
        <InputGroupAddon align="inline-end">
          <InputGroupButton variant="default" size="icon-xs" aria-label="Send">
            <ArrowUpIcon aria-hidden="true" />
          </InputGroupButton>
        </InputGroupAddon>
      </InputGroup>
    </VStack>
  )
}

Installation

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

Needs the arene setup first. Also adds Button and Input.

Usage

import { Input } from "@/components/ui/input"
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupText } from "@/components/ui/input-group"
<InputGroup>
  <Input placeholder="Search" aria-label="Search" />
  <InputGroupAddon>
    <Search />
  </InputGroupAddon>
</InputGroup>

Composition

InputGroup
├── Input
└── InputGroupAddon
    ├── InputGroupButton
    └── InputGroupText

There is no InputGroupInput. Input finds the group through context and drops its own border, fill and ring, so only the group draws a frame. Any other control joins the frame when it has data-slot="input-group-control".

There is no InputGroupTextarea either. A Textarea joins the frame through the same data-slot, plus textareaStyles.inGroup, which removes the textarea's own frame.

Align

Use the align prop on InputGroupAddon to place the addon. The inline values put the addon beside the control. The block values put it on its own row and make the frame taller.

https://
.com
Domain
Lowercase letters and dashes only.
import { Input } from "@/components/ui/input"
import { InputGroup, InputGroupAddon, InputGroupText } from "@/components/ui/input-group"
import { VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

export default function InputGroupAlign() {
  return (
    <VStack gap={4} xstyle={widths.xs}>
      <InputGroup>
        <Input placeholder="inline-start" aria-label="inline-start" />
        <InputGroupAddon align="inline-start">
          <InputGroupText>https://</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
      <InputGroup>
        <Input placeholder="inline-end" aria-label="inline-end" />
        <InputGroupAddon align="inline-end">
          <InputGroupText>.com</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
      <InputGroup>
        <Input placeholder="block-start" aria-label="block-start" />
        <InputGroupAddon align="block-start">
          <InputGroupText>Domain</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
      <InputGroup>
        <Input placeholder="block-end" aria-label="block-end" />
        <InputGroupAddon align="block-end">
          <InputGroupText>Lowercase letters and dashes only.</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
    </VStack>
  )
}

Render every addon after the control. align positions it with order, so the control stays first in the DOM and therefore first in the tab order. An addon written before the control appears in the same place but comes before the control in the tab order.

Icon

import { Input } from "@/components/ui/input"
import { InputGroup, InputGroupAddon } from "@/components/ui/input-group"
import { VStack } from "@/components/ui/stack"
import { CheckIcon } from "@phosphor-icons/react/dist/csr/Check"
import { CreditCardIcon } from "@phosphor-icons/react/dist/csr/CreditCard"
import { MagnifyingGlassIcon } from "@phosphor-icons/react/dist/csr/MagnifyingGlass"
import { widths } from "@/theme/widths"

export default function InputGroupIcon() {
  return (
    <VStack gap={4} xstyle={widths.xs}>
      <InputGroup>
        <Input placeholder="Search" aria-label="Search" />
        <InputGroupAddon>
          <MagnifyingGlassIcon aria-hidden="true" />
        </InputGroupAddon>
      </InputGroup>
      <InputGroup>
        <Input placeholder="Card number" aria-label="Card number" />
        <InputGroupAddon>
          <CreditCardIcon aria-hidden="true" />
        </InputGroupAddon>
        <InputGroupAddon align="inline-end">
          <CheckIcon aria-hidden="true" />
        </InputGroupAddon>
      </InputGroup>
    </VStack>
  )
}

Text

Use InputGroupText for a prefix, a unit or a counter.

$
USD
@arene.style
import { Input } from "@/components/ui/input"
import { InputGroup, InputGroupAddon, InputGroupText } from "@/components/ui/input-group"
import { VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

export default function InputGroupTextDemo() {
  return (
    <VStack gap={4} xstyle={widths.xs}>
      <InputGroup>
        <Input placeholder="0.00" inputMode="decimal" aria-label="Amount" />
        <InputGroupAddon>
          <InputGroupText>$</InputGroupText>
        </InputGroupAddon>
        <InputGroupAddon align="inline-end">
          <InputGroupText>USD</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
      <InputGroup>
        <Input placeholder="ada" aria-label="Username" />
        <InputGroupAddon align="inline-end">
          <InputGroupText>@arene.style</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
    </VStack>
  )
}

Button

Use InputGroupButton for an action inside the frame. It defaults to the ghost variant at size xs and shifts toward its addon's edge so its padding does not stack with the addon's.

"use client"

import { useState } from "react"
import { Input } from "@/components/ui/input"
import { InputGroup, InputGroupAddon, InputGroupButton } from "@/components/ui/input-group"
import { VStack } from "@/components/ui/stack"
import { EyeIcon } from "@phosphor-icons/react/dist/csr/Eye"
import { EyeSlashIcon } from "@phosphor-icons/react/dist/csr/EyeSlash"
import { widths } from "@/theme/widths"

export default function InputGroupButtonDemo() {
  const [visible, setVisible] = useState(false)

  return (
    <VStack gap={4} xstyle={widths.xs}>
      <InputGroup>
        <Input
          type={visible ? "text" : "password"}
          defaultValue="correcthorsebatterystaple"
          aria-label="Password"
        />
        <InputGroupAddon align="inline-end">
          <InputGroupButton
            size="icon-xs"
            aria-label={visible ? "Hide password" : "Show password"}
            onClick={() => setVisible(!visible)}
          >
            {visible ? <EyeSlashIcon aria-hidden="true" /> : <EyeIcon aria-hidden="true" />}
          </InputGroupButton>
        </InputGroupAddon>
      </InputGroup>
      <InputGroup>
        <Input placeholder="Type to search" aria-label="Search" />
        <InputGroupAddon align="inline-end">
          <InputGroupButton variant="secondary">Search</InputGroupButton>
        </InputGroupAddon>
      </InputGroup>
    </VStack>
  )
}

Pass InputGroupButton to a menu trigger through render.

import * as stylex from "@stylexjs/stylex"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Input } from "@/components/ui/input"
import { InputGroup, InputGroupAddon, InputGroupButton } from "@/components/ui/input-group"
import { CaretDownIcon } from "@phosphor-icons/react/dist/csr/CaretDown"
import { width } from "@/theme/tokens.stylex"

const styles = stylex.create({
  group: { maxWidth: width.xs },
})

export default function InputGroupDropdown() {
  return (
    <InputGroup xstyle={styles.group}>
      <Input placeholder="Search" aria-label="Search" />
      <InputGroupAddon align="inline-end">
        <DropdownMenu>
          <DropdownMenuTrigger render={<InputGroupButton />}>
            Everywhere
            <CaretDownIcon aria-hidden="true" />
          </DropdownMenuTrigger>
          <DropdownMenuContent align="end" sideOffset={8}>
            <DropdownMenuItem>Everywhere</DropdownMenuItem>
            <DropdownMenuItem>Documentation</DropdownMenuItem>
            <DropdownMenuItem>Changelog</DropdownMenuItem>
          </DropdownMenuContent>
        </DropdownMenu>
      </InputGroupAddon>
    </InputGroup>
  )
}

Disabled and invalid

Set disabled or invalid on the enclosing Field or directly on the group. The group passes both to the control through context, so one prop styles the frame and marks the input.

import { Field, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import { InputGroup, InputGroupAddon } from "@/components/ui/input-group"
import { VStack } from "@/components/ui/stack"
import { EnvelopeIcon } from "@phosphor-icons/react/dist/csr/Envelope"
import { widths } from "@/theme/widths"

export default function InputGroupStates() {
  return (
    <VStack gap={4} xstyle={widths.xs}>
      <InputGroup disabled>
        <Input defaultValue="me@example.com" aria-label="Email" />
        <InputGroupAddon>
          <EnvelopeIcon aria-hidden="true" />
        </InputGroupAddon>
      </InputGroup>
      <InputGroup invalid>
        <Input defaultValue="not-an-email" aria-label="Email" />
        <InputGroupAddon>
          <EnvelopeIcon aria-hidden="true" />
        </InputGroupAddon>
      </InputGroup>
      <Field invalid disabled>
        <FieldLabel>Email</FieldLabel>
        <InputGroup>
          <Input defaultValue="not-an-email" />
          <InputGroupAddon>
            <EnvelopeIcon aria-hidden="true" />
          </InputGroupAddon>
        </InputGroup>
      </Field>
    </VStack>
  )
}

Setting disabled on the control alone greys the text but leaves the frame undimmed. The frame cannot read its children's state, because :has() is below this project's browser baseline. Set the state on the group instead.

API reference

Pass render to replace a part's element or compose it with another component.

Every part renders a div (or a span, for InputGroupText) and takes xstyle and className.

InputGroup

PropTypeDefault
disabledbooleanfalse
invalidbooleanfalse
xstyleStyleXStyles—
classNamestring—

The group draws its focus ring from React state. It sets that state from a focus event that bubbles up from an element with data-slot="input-group-control". A button inside an addon keeps its own ring and does not light the frame's ring.

InputGroupAddon

PropTypeDefault
align"inline-start" | "inline-end" | "block-start" | "block-end""inline-start"

Clicking an addon focuses the group's control, unless the click landed on a button.

InputGroupButton

PropTypeDefault
variantevery Button variant"ghost"
size"xs" | "sm" | "icon-xs" | "icon-sm""xs"

Takes every other Button prop. The larger Button sizes are left out because they are taller than the frame.

InputGroupText

A muted run of text at the control's size, with a 0.5rem gap for an icon.

inputGroupStyles

The style maps behind the component. Spread them onto any element.

KeyWhat it is
baseThe frame: field surface, wrap layout, min height
focusedThe ring, with no pseudo-class on it, over the drop
invalidThe destructive border and ring
disabledThe disabled fill, dimmed and inert
addonAn addon's row, type and cursor
alignsOne key per align value, each an order and inset
textInputGroupText
buttonsAn in-frame button, flat and concentric, xs/sm

base is the frame's own box plus states.fieldSurface. focused is ring with the field's shadow kept under it. invalid is invalidRing. All three come from states in theme/states.ts. disabled is two styles, the group's own fill and the shared disabled. buttons.xs and buttons.sm set --arene-button-radius to the frame's radius less the button's inset, for a 24px and a 28px button. The frame tracks focus itself, from a focus event the control raises, so its ring has no pseudo-class.

Data attributes

AttributeOnEffect
data-slot="input-group"the frameTargets the frame from a parent
data-disabledthe framePresent when disabled is set
data-slot="input-group-addon"an addonTargets an addon from a parent
data-alignan addonReflects the align prop
data-slot="input-group-button"a buttonTargets a button from a parent
data-slot="input-group-text"a text runTargets a text run from a parent
data-slot="input-group-control"the controlWhat the frame watches to draw its focus ring