Atoms

Input Group

Grouped input with addons, buttons, and text.

Formance
Docs

Installation#

npx shadcn@latest add @formance/input-group

Install the following dependencies:

npm install class-variance-authority

Copy and paste the following code into your project.

Update the import paths to match your project setup.

Usage#

import {  InputGroup,  InputGroupAddon,  InputGroupInput,  InputGroupButton,  InputGroupText,  InputGroupTextarea,} from '@/components/ui/input-group'
<InputGroup>  <InputGroupAddon align="inline-start">    <SearchIcon />  </InputGroupAddon>  <InputGroupInput placeholder="Search transactions..." /></InputGroup>

Examples#

Drop Target#

Use an input group as a drop zone for files. Set data-drag-over to true while a file is over the group. The group then shows the focus border and an accent background. Set it to false when the file leaves or drops.

<InputGroup  data-drag-over={dragOver}  onDragEnter={(event) => {    event.preventDefault()    setDragOver(true)  }}  onDragOver={(event) => event.preventDefault()}  onDragLeave={(event) => {    if (      event.relatedTarget instanceof Node &&      event.currentTarget.contains(event.relatedTarget)    )      return    setDragOver(false)  }}  onDrop={(event) => {    event.preventDefault()    setDragOver(false)    addFiles(event.dataTransfer.files)  }}>  <InputGroupTextarea placeholder="Drop files here." /></InputGroup>

The dragleave event also fires when the pointer moves onto a child of the group. Ignore that event when relatedTarget is inside the group. If you do not, the drop state flickers.

API reference#

InputGroup#

PropTypeDefaultDescription
maxWidth"xs" | "sm" | "md" | "lg" | "xl"-The responsive maximum width of the group.
data-drag-overboolean-Set to true to show the drop state of the group.
classNamestring-More classes for the group.

Compound Components

Compose the pieces you need:

<InputGroup />Root container that groups an input with addons.
<InputGroupInput />The text input control (borderless, inherits group focus).
<InputGroupTextarea />A textarea control variant.
<InputGroupAddon />Slot for icons, badges, or buttons (inline-start, inline-end, block-start, block-end).
<InputGroupButton />A small button inside the addon area.
<InputGroupText />Static text or icon label inside an addon.