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.
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.jsonUsage
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
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLDivElement> | undefinedReact.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 | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLDivElement> | undefinedReact.FocusEventHandler<HTMLDivElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLDivElement> | undefinedReact.FocusEventHandler<HTMLDivElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLDivElement, Element> | undefinedReact.ChangeEventHandler<HTMLDivElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLDivElement> | undefinedReact.KeyboardEventHandler<HTMLDivElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLDivElement> | undefinedReact.MouseEventHandler<HTMLDivElement> | undefined | — | Called when the element is activated. |
InputGroupAddon
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLDivElement> | undefinedReact.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 | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLDivElement> | undefinedReact.FocusEventHandler<HTMLDivElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLDivElement> | undefinedReact.FocusEventHandler<HTMLDivElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLDivElement, Element> | undefinedReact.ChangeEventHandler<HTMLDivElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLDivElement> | undefinedReact.KeyboardEventHandler<HTMLDivElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLDivElement> | undefinedReact.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
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | ((state: ButtonState) => string | undefined) | undefinedstring | ((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> | undefinedReact.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 | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.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 | undefinedboolean | undefined | — | Prevents user interaction. |
name | string | undefinedstring | undefined | — | Field name used in form data. |
value | string | number | readonly string[] | undefinedstring | 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 | undefinedboolean | undefined | false | Whether the button should be focusable when disabled. |
nativeButton | boolean | undefinedboolean | undefined | true | Whether 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
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLSpanElement> | undefinedReact.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 | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLSpanElement> | undefinedReact.FocusEventHandler<HTMLSpanElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLSpanElement> | undefinedReact.FocusEventHandler<HTMLSpanElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLSpanElement, Element> | undefinedReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLSpanElement> | undefinedReact.KeyboardEventHandler<HTMLSpanElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLSpanElement> | undefinedReact.MouseEventHandler<HTMLSpanElement> | undefined | — | Called when the element is activated. |
InputGroupInput
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLInputElement> | undefinedReact.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 | undefinedstring | undefined | — | Accessible text alternative for the image. |
checked | boolean | undefinedboolean | undefined | — | Current checked state when controlled. |
disabled | boolean | undefinedboolean | undefined | — | Prevents user interaction. |
max | string | number | undefinedstring | number | undefined | — | Maximum allowed value. |
maxLength | number | undefinednumber | undefined | — | Maximum number of input characters. |
min | string | number | undefinedstring | number | undefined | — | Minimum allowed value. |
multiple | boolean | undefinedboolean | undefined | — | Allows more than one value to be selected. |
name | string | undefinedstring | undefined | — | Field name used in form data. |
placeholder | string | undefinedstring | undefined | — | Hint shown when the control has no value. |
required | boolean | undefinedboolean | undefined | — | Whether the user must provide a value before form submission. |
src | string | undefinedstring | undefined | — | URL of the displayed resource. |
step | string | number | undefinedstring | number | undefined | — | Increment between valid values. |
type | React.HTMLInputTypeAttribute | undefinedReact.HTMLInputTypeAttribute | undefined | — | The native input or button behavior. |
value | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | The current value when controlled by the application. |
onChange | React.ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefinedReact.ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLInputElement> | undefinedReact.FocusEventHandler<HTMLInputElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLInputElement> | undefinedReact.FocusEventHandler<HTMLInputElement> | undefined | — | Called when the control loses focus. |
onKeyDown | React.KeyboardEventHandler<HTMLInputElement> | undefinedReact.KeyboardEventHandler<HTMLInputElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLInputElement> | undefinedReact.MouseEventHandler<HTMLInputElement> | undefined | — | Called when the element is activated. |
InputGroupTextarea
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLTextAreaElement> | undefinedReact.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 | undefinedboolean | undefined | — | Prevents user interaction. |
maxLength | number | undefinednumber | undefined | — | Maximum number of input characters. |
name | string | undefinedstring | undefined | — | Field name used in form data. |
placeholder | string | undefinedstring | undefined | — | Hint shown when the control has no value. |
required | boolean | undefinedboolean | undefined | — | Whether the user must provide a value before form submission. |
rows | number | undefinednumber | undefined | — | Initial number of visible text rows. |
value | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | The current value when controlled by the application. |
onChange | React.ChangeEventHandler<HTMLTextAreaElement, HTMLTextAreaElement> | undefinedReact.ChangeEventHandler<HTMLTextAreaElement, HTMLTextAreaElement> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLTextAreaElement> | undefinedReact.FocusEventHandler<HTMLTextAreaElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLTextAreaElement> | undefinedReact.FocusEventHandler<HTMLTextAreaElement> | undefined | — | Called when the control loses focus. |
onKeyDown | React.KeyboardEventHandler<HTMLTextAreaElement> | undefinedReact.KeyboardEventHandler<HTMLTextAreaElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLTextAreaElement> | undefinedReact.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.