Input
Text fields with floating labels, helper text, and validation.
Something worth making
Installation
Terminal
pnpm dlx shadcn@latest add https://react-toolbox.io/r/input.jsonNew 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.jsonShow composition code
tsx
'use client';
import { InputFormRecipe } from '@/components/ui/examples/recipes';
export default function InputComposition() {
return <InputFormRecipe />;
}
State and callbacks
- Use
value/onChangefor controlled input, ordefaultValuefor native form state and reset. Changing the default does not replace edited text. Keep the same state model throughout the field's lifetime. onChangereceives the text value, then the React change event, including withmultiline.
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.