Skip to content

Input

Text fields with floating labels, helper text, and validation.

Installation

Terminal
pnpm dlx shadcn@latest add https://react-toolbox.io/r/input.json

New here? Set up your project first. Styles, fonts, and required components are included.

Usage

Use multiline for a text area and error for validation feedback. Setting maxLength also displays a character counter.

Composition

Persistent help, prefix and suffix content, password reveal, validation, and reset compose around Input. The editable form’s onSubmitData callback receives FormData; connect it to your application or form library.

Terminal
pnpm dlx shadcn@latest add https://react-toolbox.io/r/example-recipes.json

Amount in euros. You can change it at any time.

Use at least eight characters.

Show composition code
tsx
'use client';

import { InputFormRecipe } from '@/components/ui/examples/recipes';

export default function InputComposition() {
  return <InputFormRecipe />;
}

State and callbacks

  • Use value/onChange for controlled input, or defaultValue for native form state and reset. Changing the default does not replace edited text. Keep the same state model throughout the field's lifetime.
  • onChange receives the text value, then the React change event, including with multiline.
tsx
// Controlled: the parent owns the current value.
const [name, setName] = useState("");
<Input label="Name" value={name} onChange={setName} />

// Uncontrolled: Input owns the value after initialization.
<Input label="Name" defaultValue="Javi" name="name" />

API reference

Key props and defaults. Full types and inline documentation are included with the source in material/input.

Input

Property Type Default
error React.ReactNode —
floating boolean true
hint React.ReactNode ''
label React.ReactNode —
multiline boolean false
onChange (value: string, event: React.ChangeEvent<InputElement>) => void —

Material guidelines

  • Labels identify a field throughout entry; a placeholder alone is insufficient. Keep helper text concise and describe how to resolve an error.
  • Align related fields to common keylines. Multiline text uses the same type family as other fields, while its content area grows vertically.

Material Design 1: Text fields