Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Input Group for Vue

An input group for Vue on Ark UI: an icon, a prefix, a unit or a button inside the same border as an input or a textarea.

On this page9 sections
UI library: Ark UI

Input Group puts an icon, a fixed piece of text or a small button inside the same border as an input or a textarea: a search icon, a https:// prefix, a currency code, a copy button. The pieces read as one control, and clicking an icon or a prefix focuses the input.

To join full-size buttons to the side of a field, use a Button Group. For a field with nothing inside its border, a plain Input is enough.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Input Group anatomy: root, addon, input, text, button

Usage

<script setup lang="ts">
import { SearchIcon } from "lucide-vue-next";
import {
  InputGroup, InputGroupAddon, InputGroupInput,
} from "@/components/ui/input-group";
</script>

InputGroupInput is the input itself. Each InputGroupAddon shows where its align puts it, at the start of the row unless you say otherwise, whatever its place in the markup.

<template>
  <InputGroup class="max-w-xs">
    <InputGroupInput aria-label="Search" placeholder="Search..." />
    <InputGroupAddon>
      <SearchIcon aria-hidden="true" />
    </InputGroupAddon>
    <InputGroupAddon align="inline-end">12 results</InputGroupAddon>
  </InputGroup>
</template>

Accessibility

InputGroup is a div with role="group", and the input inside it is a native <input> or <textarea> that needs a name of its own: a FieldLabel pointed at it, or an aria-label. An addon's text is not part of that name. Give an icon that only decorates aria-hidden, and a button that holds only an icon an aria-label, as the Button demo does. Clicking an addon anywhere but on a button focuses the input, which helps the pointer only. Keyboard focus moves through the input and the addon buttons in markup order, which align doesn't change.

Tab
Moves focus to the next focusable part, the input or a button in an addon, in the order they appear in the markup.
Shift+Tab
Moves focus to the previous focusable part.
Enter
On an addon button, presses it. In the input, submits the form around it, as any text input does.
Space
On an addon button, presses it.

Demos

Inline start

A search field with a magnifier in front of the text. align set to inline-start puts the addon at the start of the row, which is also where it goes when you leave align out. Start is a logical side, so on a right-to-left page the icon moves to the right with no change to the code.

Preview width

Inline end

A password field with an eye-off icon at the end of the box, placed there by align set to inline-end. The end side follows the reading direction too. The icon here only decorates, so to show the password when it is pressed, make it an InputGroupButton, or use Password Input, which has the toggle built in.

Preview width

Block start

Two headers inside the border, set with align to block-start: a Full Name caption over a one-line input, and a script.js file bar with a copy button over a code textarea. A block addon spans the full width, and the group grows taller to hold it. Use the top edge when the addon names or acts on the whole control.

Preview width

Block end

Two footers, set with align to block-end: USD under an amount, and a 0/280 count with a Post button under a comment box. The count is fixed text in the demo, so update it from the textarea's length yourself. Use the bottom edge for a status about what was typed, or for the button that sends it.

Preview width

Icon

Four fields with lucide icons: a search, an email, a card number between a card icon and a check, and a card number with a star and an info icon at the end. Every icon is aria-hidden, so each input carries an aria-label that says in words what its icon shows, such as Search or Email. With a visible label, use a FieldLabel instead.

Preview width

Text

Fixed text that frames the value without being typed: $ and USD around an amount, https:// and .com around a domain, an @company.com suffix, and a characters-left note under a textarea. InputGroupText sets the string in the muted color. The value holds only what was typed, so add the prefix or suffix yourself when you save it.

Preview width

Button

Three fields with buttons in their addons. A read-only URL ends in a copy button that turns into a check for two seconds, a rounded field opens a popover from an info button and toggles a star, and a search field ends in a Search button. InputGroupButton defaults to type="button", so none of them submits a form by accident.

Preview width

Kbd

A search field with a magnifier at the start and a Kbd showing ⌘K at the end. The hint is plain text, so clicking it focuses the input like any other addon. The group doesn't listen for the shortcut, so bind ⌘K to focus the field yourself, and leave the hint out on touch screens.

Preview width

A file name field ends in a more-actions button that opens Settings, Copy path and Open location, and a search field ends in a Search In button that picks where to search. Each trigger is an InputGroupButton, so pressing it opens its menu without click-to-focus pulling focus into the input. Use it for a choice about the field, such as its scope.

Preview width

Spinner

Four fields in a busy state: a Spinner at the end, one at the start, one beside a Saving status, and a spinning loader icon with a Please wait note. Spinner has role="status" and the name Loading, while the plain loader icon is aria-hidden and says nothing to a screen reader. Show the spinner only while the request runs.

Preview width

Textarea

A small code editor: a script.js bar with refresh and copy buttons on top, the code in an InputGroupTextarea, and a cursor position with a Run button at the bottom. A border-b and a border-t on the addons set the bars apart from the code. Clicking a bar's text focuses the textarea, as it would an input.

Preview width

Custom

A plain <textarea> that grows with its content through the CSS field-sizing property, with a Submit button under it. It sets data-slot to input-group-control, the slot the group's focus ring looks for. InputGroupInput and InputGroupTextarea carry that slot already, so add it only to a control of your own.

Preview width

RTL

The search field with a results count, two busy fields and the comment box, in Arabic, inside a wrapper with dir set to rtl. Inline addons follow the reading direction, so the search icon sits on the right and the count on the left, and ms-auto keeps Post at the end. Use logical classes like that in your own addons so they flip with the page.

Preview width

FAQ

How do I put an Input Group addon before, after, above or below the input?

Set align on InputGroupAddon. inline-start, the default, puts it before the input and inline-end after it, on the same row. block-start and block-end put it above or below at full width, and the group grows taller to hold it, as the Block start and Block end demos show.

The sides are logical, so they swap on a right-to-left page. Where the addon sits in the markup doesn't change where it shows, but it does set the Tab order of any button inside it.

Why does clicking an Input Group addon focus the input?

Each InputGroupAddon has a click handler that focuses the group's control, unless the click landed on a button. That makes an icon or a prefix feel like part of the box. It looks for the element whose data-slot is input-group-control, which InputGroupInput and InputGroupTextarea both carry, and falls back to the first <input> in the group.

Click-to-focus is a convenience for the pointer. Keyboard users Tab straight to the input and to each addon button, so a click on the addon is never the only way in.

How do I add a label to an Input Group?

Label the input, not the group. Put a FieldLabel above the InputGroup inside a Field, and Field points it at the InputGroupInput for you. Without a visible label, set aria-label on the InputGroupInput.

An addon such as https:// or USD isn't part of the input's name. When the unit matters, put it in the label, such as Price in USD.

How do I show an Input Group as disabled or invalid?

Set disabled on the InputGroupInput, and it stops taking focus while the group's styles fade the whole box, addons and all. A button in an addon stays live, though, so disable each InputGroupButton as well, or a copy or clear button keeps working beside a field nobody can edit. The fade follows any disabled element inside the group, so a disabled button alone, such as a Send button waiting for text, fades the whole field too.

For an error, mark the input invalid with aria-invalid, or set invalid on the Field around the group, which passes aria-invalid to it. The group's styles look for an invalid control inside and turn the border around the whole group, addons and all, to the destructive color.

How do I change the height of an Input Group?

Set size on InputGroup to sm or lg for a group 28 or 36 pixels tall, and the InputGroupInput inside takes the same size unless you give it one of its own. The default, md, takes the height from the group's styles.

A group with a block addon or a textarea drops the fixed height and grows to fit. The width is the container's, because the group is w-full.

How do I put my own control, such as an autoresizing textarea, in an Input Group?

Give it data-slot set to input-group-control, as the Custom demo does with a self-sizing <textarea>. The group draws its focus ring by looking for a focused element with that slot, so without it the control sits inside the border but the ring never shows.

InputGroupInput and InputGroupTextarea set the slot already, and they are the better choice whenever they can do the job. The slot also tells the addons' click-to-focus which element to focus.

How do I add a show password button to an Input Group?

Put an InputGroupButton in an addon with align set to inline-end, keep a boolean in state, and switch the input's type between password and text when the button is pressed. Give the button an aria-label that says what it will do, such as Show password, and swap its icon with the state.

The button is type="button" by default, so pressing it never submits the form. Password Input has this toggle built in, if you'd rather not wire it yourself.

Should I use an Input Group or a Button Group?

Use an Input Group when the input is the control and the extras live inside its border: an icon, a unit, a prefix, or a small button that acts on the value. Use a Button Group to join full-size buttons to one another or to the side of a field, each with its own border.

A Search button fits either one. Make it an InputGroupButton inside the border, as the last field of the Button demo does, when it should read as part of the box, and put it beside the field in a Button Group when it should look like a full-size button.

API Reference

InputGroup

<div>

PropType
size?"sm" | "md" | "lg"

The size.

Type
"sm" | "md" | "lg"
Default
"md"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

InputGroupAddon

<div> data-slot="input-group-addon"

PropType
align?"block-end" | "block-start" | "inline-end" | "inline-start"

Where it sits in the group: inline-start or inline-end beside the input, block-start or block-end above or below it.

Type
"block-end" | "block-start" | "inline-end" | "inline-start"
Default
"inline-start"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-align?string

Mirrors align.

InputGroupButton

data-slot="input-group-button"

PropType
clickEffect?boolean

Apply a click effect to the button.

Default
true
isLoading?boolean

Show a loading indicator.

Default
false
pill?boolean

Fully rounded corners.

Default
false
size?"icon-sm" | "icon-xs" | "sm" | "xs"

The size.

Type
"icon-sm" | "icon-xs" | "sm" | "xs"
Default
"xs"
variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"

Ark default: default.

Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Default
"ghost"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-size?string

Mirrors size.

InputGroupText

<span> data-slot="input-group-text"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

InputGroupInput

data-slot="input-group-control"

PropType
size?"lg" | "md" | "sm"

The size.

Type
"lg" | "md" | "sm"
Default
"md"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

InputGroupTextarea

data-slot="input-group-control"

PropType
autoresize?boolean

Whether the textarea should autoresize.

Default
false
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.