Theme
Customize appearance
Components
Input
Collect a single line of text using a styled input.
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.jsonUsage
This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.
import { Input } from "@/components/ui/input";
export default function Example() {
return (
<Input
aria-label="Email address"
type="email"
placeholder="you@example.com"
className="max-w-sm"
/>
);
}
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.
Input
| 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. |
Usage notes
Choose an appropriate HTML type and supply a label. Use value and onChange when managing the field in application state.