Skip to content
All components
Forms

Input group

Attach units, prefixes, icons or a small action to an input so the group shares one border and one focus ring.

An input with affixes, where the focus ring wraps the whole group.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add input-group

Then import it from @/components/ui/input-group. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Search

Compose search input content and its supporting icon. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { SearchIcon } from "lucide-react"

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

export function InputGroupSearch() {
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <InputGroup>
        <InputGroupAddon>
          <SearchIcon className="size-4" />
        </InputGroupAddon>
        <InputGroupInput aria-label="Search components" placeholder="Search components" />
      </InputGroup>
    </div>
  )
}

Prefix and suffix

Add supporting prefix and suffix content around the input. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

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

export function InputGroupPrefixAndSuffix() {
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <InputGroup>
        <InputGroupAddon>https://</InputGroupAddon>
        <InputGroupInput aria-label="Website domain" placeholder="example.com" />
        <InputGroupAddon>/r</InputGroupAddon>
      </InputGroup>
    </div>
  )
}

With label and hint

Label a grouped input and describe it with both its unit and a hint. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import {
  InputGroup,
  InputGroupAddon,
  InputGroupInput,
} from "@/components/ui/input-group"

export function InputGroupWithLabelAndHint() {
  const id = React.useId()
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-price`}>Price</FieldLabel>
        <InputGroup>
          <InputGroupInput
            id={`${id}-price`}
            inputMode="decimal"
            autoComplete="off"
            aria-describedby={`${id}-price-unit ${id}-price-hint`}
          />
          <InputGroupAddon id={`${id}-price-unit`}>USD</InputGroupAddon>
        </InputGroup>
        <FieldDescription id={`${id}-price-hint`}>
          Before taxes. Customers see the price in their local currency.
        </FieldDescription>
      </Field>
    </div>
  )
}

Password toggle

Reveal a password with a named toggle button placed inside the group. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { EyeIcon, EyeOffIcon } from "lucide-react"
import * as React from "react"

import { Button } from "@/components/ui/button"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import {
  InputGroup,
  InputGroupAddon,
  InputGroupInput,
} from "@/components/ui/input-group"

export function InputGroupPasswordToggle() {
  const id = React.useId()
  const [showPassword, setShowPassword] = React.useState(false)

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-password`}>Password</FieldLabel>
        <InputGroup className="pe-1">
          <InputGroupInput
            id={`${id}-password`}
            type={showPassword ? "text" : "password"}
            autoComplete="current-password"
            aria-describedby={`${id}-password-hint`}
          />
          <InputGroupAddon>
            <Button
              type="button"
              size="sm"
              intent="neutral"
              emphasis="ghost"
              iconOnly
              aria-label="Show password"
              aria-pressed={showPassword}
              aria-controls={`${id}-password`}
              onClick={() => setShowPassword((current) => !current)}
            >
              {showPassword ? <EyeOffIcon /> : <EyeIcon />}
            </Button>
          </InputGroupAddon>
        </InputGroup>
        <FieldDescription id={`${id}-password-hint`}>
          At least 12 characters.
        </FieldDescription>
      </Field>
    </div>
  )
}

Invalid

Associate the grouped input with its error text. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldError, FieldLabel } from "@/components/ui/field"
import {
  InputGroup,
  InputGroupAddon,
  InputGroupInput,
} from "@/components/ui/input-group"

export function InputGroupInvalid() {
  const id = React.useId()
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-handle`}>Profile address</FieldLabel>
        <InputGroup>
          <InputGroupAddon aria-hidden="true">@</InputGroupAddon>
          <InputGroupInput
            id={`${id}-handle`}
            defaultValue="ana torres"
            autoCapitalize="none"
            spellCheck={false}
            aria-invalid
            aria-describedby={`${id}-handle-error`}
          />
        </InputGroup>
        <FieldError id={`${id}-handle-error`}>
          Use letters, numbers and hyphens only, without spaces.
        </FieldError>
      </Field>
    </div>
  )
}

Disabled

Inspect the unavailable control using its real disabled semantics. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import {
  InputGroup,
  InputGroupAddon,
  InputGroupInput,
} from "@/components/ui/input-group"

export function InputGroupDisabled() {
  const id = React.useId()
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-domain`}>Custom domain</FieldLabel>
        <InputGroup>
          <InputGroupAddon>https://</InputGroupAddon>
          <InputGroupInput id={`${id}-domain`} disabled aria-describedby={`${id}-domain-hint`} />
        </InputGroup>
        <FieldDescription id={`${id}-domain-hint`}>
          Custom domains are available on paid plans.
        </FieldDescription>
      </Field>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

InputGroup

Wraps an input together with leading or trailing affixes (an icon, a unit, a button) so the focus ring belongs to the group rather than to the input alone. Without this the ring draws inside the affixes and looks broken.

InputGroup props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
InputGroup inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

InputGroupAddon

The InputGroupAddon part of input-group. Use it with the complete source composition and preserve its required parent context.

InputGroupAddon props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
InputGroupAddon inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

InputGroupInput

The InputGroupInput part of input-group. Use it with the complete source composition and preserve its required parent context.

InputGroupInput props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (32)
InputGroupInput inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLInputElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
altstring | undefined—Text alternative for the image. Identify informative images; use an empty alternative only when the image is genuinely decorative.
autoCompleteReact.HTMLInputAutoCompleteAttribute | undefined—Native autocomplete hint appropriate to the field's actual purpose.
checkedboolean | undefined—Current checked state. Apply the requested value from onCheckedChange when the parent owns this state.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
maxstring | number | undefined—Maximum supported numeric value.
maxLengthnumber | undefined—Maximum allowed text length for native input or code entry.
minstring | number | undefined—Minimum supported numeric value.
minLengthnumber | undefined—Minimum allowed text length for native validation.
multipleboolean | undefined—Allow multiple values where the native element or primitive supports them, using its source-defined value shape.
namestring | undefined—Name used by the control's form submission or primitive form integration.
patternstring | undefined—Native input validation pattern. Provide readable format guidance and associated validation feedback.
placeholderstring | undefined—Prompt shown before a value is selected or entered. Supply an accessible label separately.
readOnlyboolean | undefined—Prevent value editing while preserving readable content. Read-only behavior differs from disabled behavior.
requiredboolean | undefined—Mark this control as required using its native or primitive semantics. Consumers own contextual validation feedback.
srcstring | undefined—Image source URL. Supply alternative text appropriate to whether the image conveys identity or is decorative.
stepstring | number | undefined—Numeric increment used for slider or native input changes.
typeReact.HTMLInputTypeAttribute | undefined—Native element or primitive mode defined by the source union. Choose a supported value; its meaning depends on the component.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
onChangeReact.ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLInputElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLInputElement> | undefined—Receive the native blur event when focus leaves this control.
onKeyDownReact.KeyboardEventHandler<HTMLInputElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLInputElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLInputElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/input-group.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • A value with a fixed unit or prefix such as a currency code, a percentage or a URL scheme.
  • A search field with a leading icon.
  • A small inline action that only affects this input, such as showing a password or clearing the value.

When not to use

  • Text or icons that are not part of the value's meaning; put them in the label or hint.
  • Several actions or a primary form action inside the field; place buttons next to the field instead.
  • Wrapping a textarea or select; the group styles a single input.

Anatomy

InputGroup
The bordered container. It draws the focus ring with focus-within, shows the disabled look when its input is disabled and the error border when its input has aria-invalid="true".
InputGroupAddon
A leading or trailing slot for text, an icon or a small button. It is not labelled or focusable by itself.
InputGroupInput
The native input inside the group. It takes the id, label association, aria-describedby and aria-invalid.

Keyboard & interaction

  • Tab reaches the input and then any button in an addon, in source order.
  • The whole group shows the focus ring while the input or an addon button has focus.
  • A toggle button in an addon reports its state with aria-pressed and keeps a stable label.
  • Disabling the input also gives the group its disabled look and stops pointer input on the whole group.

Responsive behavior

  • Full width; the input shrinks with min-w-0 so long addons do not push the group past the viewport.
  • Keep addons short (a unit, a scheme, one icon); long prefixes leave no room for the value at 320 CSS px.
  • Height is 40 CSS px; an icon-only button inside should keep at least a 24x24 CSS px target.
  • Use inputMode and autoComplete on InputGroupInput exactly as on Input.

Content guidelines

  • Label the input with a visible FieldLabel; addons supplement it ('Price' with a 'USD' addon).
  • Reference a meaningful unit addon from aria-describedby (give it an id) so it is announced with the input.
  • Hide purely decorative addons and icons from assistive technology.
  • Errors follow the same rules as Input: what is wrong and how to fix it.

Alternatives

  • Input — A plain value without affixes.
  • Button group — Buttons joined into one control, without a text input.
  • Combobox — Searching a known list of options rather than typing a free value.

Resources