Theme

Customize appearance

Components

Input Group

Attach labels, icons, or actions to a text control.

View component source ↗

Preview

A minimal example to get started.

https://

Installation

Install this component and its dependencies in a project initialized with shadcn.

pnpm dlx shadcn@latest add https://ui.hyunjoon.net/r/input-group.json

Usage

This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.

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

export default function Example() {
  return (
    <InputGroup className="max-w-sm">
      <InputGroupAddon>
        <InputGroupText>https://</InputGroupText>
      </InputGroupAddon>
      <InputGroupInput aria-label="Website" placeholder="example.com" />
    </InputGroup>
  );
}

API reference

Derived from the installed component types. Native DOM props are also supported where applicable. A dash means no explicit default is documented. Some props depend on the selected mode.

InputGroup
InputGroup properties
PropTypeDefaultDescription
ref
React.Ref<HTMLDivElement> | undefined
React.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).
defaultChecked
boolean | undefined
boolean | undefined
—Initial checked state for an uncontrolled control.
defaultValue
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—Initial value for an uncontrolled component.
className
string | undefined
string | undefined
—Additional CSS classes merged with the component styles.
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
React.FocusEventHandler<HTMLDivElement> | undefined
React.FocusEventHandler<HTMLDivElement> | undefined
—Called when the control receives focus.
onBlur
React.FocusEventHandler<HTMLDivElement> | undefined
React.FocusEventHandler<HTMLDivElement> | undefined
—Called when the control loses focus.
onChange
React.ChangeEventHandler<HTMLDivElement, Element> | undefined
React.ChangeEventHandler<HTMLDivElement, Element> | undefined
—Called when the underlying form control changes; inspect the event for its value.
onKeyDown
React.KeyboardEventHandler<HTMLDivElement> | undefined
React.KeyboardEventHandler<HTMLDivElement> | undefined
—Called when a key is pressed while this element is focused.
onClick
React.MouseEventHandler<HTMLDivElement> | undefined
React.MouseEventHandler<HTMLDivElement> | undefined
—Called when the element is activated.
InputGroupAddon
InputGroupAddon properties
PropTypeDefaultDescription
ref
React.Ref<HTMLDivElement> | undefined
React.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).
defaultChecked
boolean | undefined
boolean | undefined
—Initial checked state for an uncontrolled control.
defaultValue
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—Initial value for an uncontrolled component.
className
string | undefined
string | undefined
—Additional CSS classes merged with the component styles.
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
React.FocusEventHandler<HTMLDivElement> | undefined
React.FocusEventHandler<HTMLDivElement> | undefined
—Called when the control receives focus.
onBlur
React.FocusEventHandler<HTMLDivElement> | undefined
React.FocusEventHandler<HTMLDivElement> | undefined
—Called when the control loses focus.
onChange
React.ChangeEventHandler<HTMLDivElement, Element> | undefined
React.ChangeEventHandler<HTMLDivElement, Element> | undefined
—Called when the underlying form control changes; inspect the event for its value.
onKeyDown
React.KeyboardEventHandler<HTMLDivElement> | undefined
React.KeyboardEventHandler<HTMLDivElement> | undefined
—Called when a key is pressed while this element is focused.
onClick
React.MouseEventHandler<HTMLDivElement> | undefined
React.MouseEventHandler<HTMLDivElement> | undefined
—Called when the element is activated.
align
"inline-end" | "inline-start" | "block-start" | "block-end" | null | undefined
"inline-end" | "inline-start" | "block-start" | "block-end" | null | undefined
"inline-start"Alignment relative to the anchor or surrounding content.
InputGroupButton
InputGroupButton properties
PropTypeDefaultDescription
className
string | ((state: ButtonState) => string | undefined) | undefined
string | ((state: ButtonState) => string | undefined) | undefined
—CSS class applied to the element, or a function that returns a class based on the component's state.
style
React.CSSProperties | ((state: ButtonState) => React.CSSProperties | undefined) | undefine…
React.CSSProperties | ((state: ButtonState) => React.CSSProperties | undefined) | undefined
—Style applied to the element, or a function that returns a style object based on the component's state.
ref
React.Ref<HTMLButtonElement> | undefined
React.Ref<HTMLButtonElement> | 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).
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined
((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined
—Called when the control receives focus.
onBlur
((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined
((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined
—Called when the control loses focus.
onChange
((event: BaseUIEvent<React.ChangeEvent<HTMLButtonElement, Element>>) => void) | undefined
((event: BaseUIEvent<React.ChangeEvent<HTMLButtonElement, Element>>) => void) | undefined
—Called when the underlying form control changes; inspect the event for its value.
onKeyDown
((event: BaseUIEvent<React.KeyboardEvent<HTMLButtonElement>>) => void) | undefined
((event: BaseUIEvent<React.KeyboardEvent<HTMLButtonElement>>) => void) | undefined
—Called when a key is pressed while this element is focused.
onClick
((event: BaseUIEvent<React.MouseEvent<HTMLButtonElement, MouseEvent>>) => void) | undefine…
((event: BaseUIEvent<React.MouseEvent<HTMLButtonElement, MouseEvent>>) => void) | undefined
—Called when the element is activated.
disabled
boolean | undefined
boolean | undefined
—Prevents user interaction.
name
string | undefined
string | undefined
—Field name used in form data.
value
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—The current value when controlled by the application.
variant
"link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined
"link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined
"ghost"Visual treatment of the component.
render
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ButtonState> | undefined
—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
focusableWhenDisabled
boolean | undefined
boolean | undefined
falseWhether the button should be focusable when disabled.
nativeButton
boolean | undefined
boolean | undefined
trueWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).
size
"xs" | "sm" | "icon-xs" | "icon-sm" | null | undefined
"xs" | "sm" | "icon-xs" | "icon-sm" | null | undefined
"xs"Visual size of the component.
type
"button" | "submit" | "reset" | undefined
"button" | "submit" | "reset" | undefined
"button"The native input or button behavior.
InputGroupText
InputGroupText properties
PropTypeDefaultDescription
ref
React.Ref<HTMLSpanElement> | undefined
React.Ref<HTMLSpanElement> | 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).
defaultChecked
boolean | undefined
boolean | undefined
—Initial checked state for an uncontrolled control.
defaultValue
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—Initial value for an uncontrolled component.
className
string | undefined
string | undefined
—Additional CSS classes merged with the component styles.
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
React.FocusEventHandler<HTMLSpanElement> | undefined
React.FocusEventHandler<HTMLSpanElement> | undefined
—Called when the control receives focus.
onBlur
React.FocusEventHandler<HTMLSpanElement> | undefined
React.FocusEventHandler<HTMLSpanElement> | undefined
—Called when the control loses focus.
onChange
React.ChangeEventHandler<HTMLSpanElement, Element> | undefined
React.ChangeEventHandler<HTMLSpanElement, Element> | undefined
—Called when the underlying form control changes; inspect the event for its value.
onKeyDown
React.KeyboardEventHandler<HTMLSpanElement> | undefined
React.KeyboardEventHandler<HTMLSpanElement> | undefined
—Called when a key is pressed while this element is focused.
onClick
React.MouseEventHandler<HTMLSpanElement> | undefined
React.MouseEventHandler<HTMLSpanElement> | undefined
—Called when the element is activated.
InputGroupInput
InputGroupInput properties
PropTypeDefaultDescription
ref
React.Ref<HTMLInputElement> | undefined
React.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).
alt
string | undefined
string | undefined
—Accessible text alternative for the image.
checked
boolean | undefined
boolean | undefined
—Current checked state when controlled.
disabled
boolean | undefined
boolean | undefined
—Prevents user interaction.
max
string | number | undefined
string | number | undefined
—Maximum allowed value.
maxLength
number | undefined
number | undefined
—Maximum number of input characters.
min
string | number | undefined
string | number | undefined
—Minimum allowed value.
multiple
boolean | undefined
boolean | undefined
—Allows more than one value to be selected.
name
string | undefined
string | undefined
—Field name used in form data.
placeholder
string | undefined
string | undefined
—Hint shown when the control has no value.
required
boolean | undefined
boolean | undefined
—Whether the user must provide a value before form submission.
src
string | undefined
string | undefined
—URL of the displayed resource.
step
string | number | undefined
string | number | undefined
—Increment between valid values.
type
React.HTMLInputTypeAttribute | undefined
React.HTMLInputTypeAttribute | undefined
—The native input or button behavior.
value
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—The current value when controlled by the application.
onChange
React.ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefined
React.ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefined
—Called when the underlying form control changes; inspect the event for its value.
defaultChecked
boolean | undefined
boolean | undefined
—Initial checked state for an uncontrolled control.
defaultValue
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—Initial value for an uncontrolled component.
className
string | undefined
string | undefined
—Additional CSS classes merged with the component styles.
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
React.FocusEventHandler<HTMLInputElement> | undefined
React.FocusEventHandler<HTMLInputElement> | undefined
—Called when the control receives focus.
onBlur
React.FocusEventHandler<HTMLInputElement> | undefined
React.FocusEventHandler<HTMLInputElement> | undefined
—Called when the control loses focus.
onKeyDown
React.KeyboardEventHandler<HTMLInputElement> | undefined
React.KeyboardEventHandler<HTMLInputElement> | undefined
—Called when a key is pressed while this element is focused.
onClick
React.MouseEventHandler<HTMLInputElement> | undefined
React.MouseEventHandler<HTMLInputElement> | undefined
—Called when the element is activated.
InputGroupTextarea
InputGroupTextarea properties
PropTypeDefaultDescription
ref
React.Ref<HTMLTextAreaElement> | undefined
React.Ref<HTMLTextAreaElement> | 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).
disabled
boolean | undefined
boolean | undefined
—Prevents user interaction.
maxLength
number | undefined
number | undefined
—Maximum number of input characters.
name
string | undefined
string | undefined
—Field name used in form data.
placeholder
string | undefined
string | undefined
—Hint shown when the control has no value.
required
boolean | undefined
boolean | undefined
—Whether the user must provide a value before form submission.
rows
number | undefined
number | undefined
—Initial number of visible text rows.
value
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—The current value when controlled by the application.
onChange
React.ChangeEventHandler<HTMLTextAreaElement, HTMLTextAreaElement> | undefined
React.ChangeEventHandler<HTMLTextAreaElement, HTMLTextAreaElement> | undefined
—Called when the underlying form control changes; inspect the event for its value.
defaultChecked
boolean | undefined
boolean | undefined
—Initial checked state for an uncontrolled control.
defaultValue
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—Initial value for an uncontrolled component.
className
string | undefined
string | undefined
—Additional CSS classes merged with the component styles.
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
React.FocusEventHandler<HTMLTextAreaElement> | undefined
React.FocusEventHandler<HTMLTextAreaElement> | undefined
—Called when the control receives focus.
onBlur
React.FocusEventHandler<HTMLTextAreaElement> | undefined
React.FocusEventHandler<HTMLTextAreaElement> | undefined
—Called when the control loses focus.
onKeyDown
React.KeyboardEventHandler<HTMLTextAreaElement> | undefined
React.KeyboardEventHandler<HTMLTextAreaElement> | undefined
—Called when a key is pressed while this element is focused.
onClick
React.MouseEventHandler<HTMLTextAreaElement> | undefined
React.MouseEventHandler<HTMLTextAreaElement> | undefined
—Called when the element is activated.

Usage notes

Place the editable input inside InputGroup. Use addons for context without replacing a proper field label.