Input

A single-line text field, built on the headless Field primitive. Monochrome by design — it shares the Button size steps but none of its colour sets.

src/components/ui/input.tsx

About

From the component's own source, where it was written.

Built on the headless Field primitive, so clicking the padding or an icon focuses the control rather than doing nothing.

Deliberately monochrome: an input is a surface you type on, not an accent, so it uses only the theme's own background, border and foreground tokens and has no color or tint. It also takes no focus ring and no border change — the caret is the focus indicator. error is the single exception: the one state that earns a colour.

Install

npx astralyx-ui add input

Usage

import { Input } from '@/components/ui/input'
import { Search } from 'lucide-react'

<Input placeholder="Search components" icon={<Search />} />

Composer

Change the props and the source below follows.

Props
tsx
<Input
  placeholder="Search components"
  icon={<Search />}
  clearable
/>

Examples

Variants

Sizes

Icon position

Clearable

States

Aligned with a Button

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

Input

Extends Omit<ComponentProps<'input'>, 'size' | 'style'>.

PropTypeDefaultDescription
errorbooleanfalseThe only colour the component takes: a red border. Also sets aria-invalid on the field.
variant'default' | 'secondary' | 'ghost''default'Bordered, filled, or no chrome until hover.
size'sm' | 'default' | 'xs' | 'lg' | 'xl''default'Height, padding, text and corner radius — the same steps a Button uses, so the two align in a row.
iconReactNode—Rendered inside the field. Padding tightens automatically on the icon side.
iconPosition'start' | 'end''start'Which side the icon sits on.
clearablebooleanfalseShows a clear button on the trailing side once the field has content. Works controlled or uncontrolled.
onClear() => void—Fires after the clear button empties the field, in addition to the usual onChange.
clearLabelstring'Clear'Accessible label for the clear button.
containerClassNamestring—Styles the wrapper. className goes to the <input> itself, so both are reachable.
styleComponentProps<'div'>['style']——

Functions

FunctionSignatureDescription
inputVariants(props?: { variant?: 'default' | 'secondary' | 'ghost'; size?: 'sm' | 'default' | 'xs' | 'lg' | 'xl'; error?: boolean }) => stringBuilt on the headless Field primitive, so clicking the padding or an icon focuses the control rather than doing nothing.