React Input Group Component
A React input group that attaches text, icons or buttons to a field and shares one focus ring. Use InputGroup when one field needs things attached to it: an https:// prefix, a .com suffix, a currency or unit, or a button such as Apply inside the same edge.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/input-group.jsonShare your page
Type an address, then copy it.
InputGroupInputGroupTextInputGroupAddonInputGroupInput- +2 more
Using it in a form? See the react-hook-form and zod recipe.
Prefix, suffix, unit and button
Compose InputGroupAddon and InputGroupInput in reading order. Use Input's leading and trailing for a single icon.
import { Button } from "@/components/sheenui/button/button";
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from "@/components/sheenui/input-group/input-group";
// Package build (after the first npm release, or a packed tarball): import { Button, InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
export function Example() {
return (
<div className="flex w-full max-w-sm flex-col gap-4">
<InputGroup>
<InputGroupAddon>
<InputGroupText>https://</InputGroupText>
</InputGroupAddon>
<InputGroupInput aria-label="Domain" placeholder="example" />
<InputGroupAddon align="end">
<InputGroupText>.com</InputGroupText>
</InputGroupAddon>
</InputGroup>
<InputGroup size="lg">
<InputGroupInput aria-label="Amount" inputMode="decimal" placeholder="0.00" />
<InputGroupAddon align="end">USD</InputGroupAddon>
</InputGroup>
<InputGroup size="sm" invalid>
<InputGroupInput aria-label="Coupon" aria-invalid defaultValue="SPRING" />
<InputGroupAddon align="end">
<Button variant="ghost" size="sm">Apply</Button>
</InputGroupAddon>
</InputGroup>
</div>
);
}Files to copy
3 folders · 2 files · 4 packages
- From
theme/src/ components/input-group/lib/{cn.ts, field-size.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/input-group.jsonRegistry item: input-group. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/button/components/field/components/spinner/hooks/{use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}motion/{gate.ts, tokens.ts}lib/{form.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/field.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Inside a Field
Field wires the label, the description and the error to the input: wrap the InputGroupInput in FieldControl, and set invalid on both the Field and the group so the danger edge and the message agree.
import { useState } from "react";
import { Field, FieldControl, FieldError, FieldLabel } from "@/components/sheenui/field/field";
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from "@/components/sheenui/input-group/input-group";
// Package build (after the first npm release, or a packed tarball): import { Field, FieldControl, FieldError, FieldLabel, InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from "@sheenui/theme";
// This example also uses field: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/field.json
export function Example() {
const [slug, setSlug] = useState("");
const invalid = slug.length > 0 && !/^[a-z0-9-]+$/.test(slug);
return (
<Field invalid={invalid} className="max-w-sm">
<FieldLabel>Workspace address</FieldLabel>
<InputGroup invalid={invalid}>
<InputGroupAddon>
<InputGroupText>example.com/</InputGroupText>
</InputGroupAddon>
<FieldControl>
<InputGroupInput value={slug} onChange={(event) => setSlug(event.target.value)} />
</FieldControl>
</InputGroup>
<FieldError>Use lowercase letters, numbers and dashes.</FieldError>
</Field>
);
}InputGroup props
InputGroupAddon props
Other parts
Keyboard
Accessibility
- The group is role="group". Name the input with aria-label or a Field label: addon text is read as part of the page but is not the input's name unless you link it with aria-describedby.
- invalid shows the danger edge; set aria-invalid on the input too, so the state is not carried by colour alone.
- Icons in an addon should be aria-hidden; text such as https:// is read in order with the field.
- Height follows the shared control scale (sm 32px, md 40px, lg 48px; 44px for sm and md on touch screens).
When to use the input group
- Use InputGroup for a URL field with an https:// prefix, a price with a currency symbol and a unit, or a search box with an Apply button on its right edge, all sharing one focus ring.
- Compose InputGroupAddon and InputGroupInput in reading order. Use align end on an addon that follows the input, and put it after the input in the markup.
- Wrap the input in Field with FieldControl when it needs a label, a description or an error message, and set invalid on the Field and the group together.
- Skip it for a single icon inside a plain field. Input has leading and trailing slots for that.
- Pair it with Button for an inline action, Tooltip on an icon-only addon, and Select when the addon is a currency or unit picker.
Frequently asked questions
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .