Input

A text input field with optional start/end icon decoration and an interactive in-field action slot.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/input.json

Usage

import { Input } from "@/components/ui/input"

Examples

Default

The plain field. It is full-width, so give it a width or a cap (max-w-xs here) or it takes whatever its container happens to be.

Sizes

Heights are 24/28/32/40, the same ramp and the same names as Button, so the same size on a field and the button beside it gives one height and one corner radius. The pair at the bottom is the case this exists for: a field and its submit, stacked at the same width.

With Icons

iconStart and iconEnd render decorative, non-interactive icons inside the field. Same two forms as Button: an element (<Search />) or a bare component (Search).

With Action

actionEnd renders an interactive control inside the field: a copy, clear, or reveal-password button. Pass an icon-sm Button.

States

Default, read-only and disabled side by side. Read-only sits flat on the muted fill at full opacity and still takes focus, so its value can be selected and copied; disabled dims to 70% and does not.

Clear button

Press the X: the old text sinks and fades as the field empties. The value clears at once; the fade is a picture only, and typing never plays it. Needs a controlled value. Show the clear button only while there is text.

API Reference

PropTypeDefaultDescription
variant"default" | "ghost""default"default is the bordered form field. ghost is borderless and transparent with no forced height or font-size and minimal focus, for title composers and inline-edit fields; size it via className.
size"xs" | "sm" | "default" | "lg""default"Control height (24/28/32/40), using Button's size names so the same size on a field and the button beside it gives the same height and the same corner radius. Height, side padding, radius, and adornment icon size (12/14/14/16px, Button's ramp) move together. Ignored by ghost, which has no chrome. Note that this replaces the native HTML size attribute, which sets character width and is superseded by className="w-*".
iconStartTablerIcon | ReactNodeNoneDecorative, non-interactive icon rendered at the leading edge of the field. Prefer an element (<Search />); a bare component (Search) still works but cannot be passed from a Server Component.
iconEndTablerIcon | ReactNodeNoneDecorative, non-interactive icon rendered at the trailing edge of the field. Prefer an element (<Mail />); a bare component still works but cannot be passed from a Server Component.
actionEndReact.ReactNodeNoneInteractive element rendered inside the field at the trailing edge: a copy, clear, or reveal-password button. Pass an icon-sm Button. Its glyph is resized to the field's icon size, the same as iconStart.
clearEchobooleanfalseWhen the value goes from text to empty without a keystroke (a clear button, a reset), the old text sinks 8px and fades out over 200ms, then the placeholder fades in. The real value is empty at once. Needs a controlled value; off under reduced motion.
classNamestringNoneApplied to the input itself, or to the wrapper div when any icon/action adornment or clearEcho is present.
variant"default" | "ghost" = "default"default is the bordered form field. ghost is borderless and transparent with no forced height or font-size and minimal focus, for title composers and inline-edit fields; size it via className.
size"xs" | "sm" | "default" | "lg" = "default"Control height (24/28/32/40), using Button's size names so the same size on a field and the button beside it gives the same height and the same corner radius. Height, side padding, radius, and adornment icon size (12/14/14/16px, Button's ramp) move together. Ignored by ghost, which has no chrome. Note that this replaces the native HTML size attribute, which sets character width and is superseded by className="w-*".
iconStartTablerIcon | ReactNodeDecorative, non-interactive icon rendered at the leading edge of the field. Prefer an element (<Search />); a bare component (Search) still works but cannot be passed from a Server Component.
iconEndTablerIcon | ReactNodeDecorative, non-interactive icon rendered at the trailing edge of the field. Prefer an element (<Mail />); a bare component still works but cannot be passed from a Server Component.
actionEndReact.ReactNodeInteractive element rendered inside the field at the trailing edge: a copy, clear, or reveal-password button. Pass an icon-sm Button. Its glyph is resized to the field's icon size, the same as iconStart.
clearEchoboolean = falseWhen the value goes from text to empty without a keystroke (a clear button, a reset), the old text sinks 8px and fades out over 200ms, then the placeholder fades in. The real value is empty at once. Needs a controlled value; off under reduced motion.
classNamestringApplied to the input itself, or to the wrapper div when any icon/action adornment or clearEcho is present.