Input
Input
A flexible input component with built-in validation, masking, and accessible error states.
Usage
typescript
1import { Input } from '@flint-ui/core'23<Input4 label="Email address"5 type="email"6 placeholder="you@example.com"7 required8 onValidate={(value) => isEmail(value) ? null : 'Invalid email'}9/>
Basic email input with inline validation
Variants
typescript
1// Text input2<Input label="Name" placeholder="Enter your name" />34// Password with visibility toggle5<Input type="password" label="Password" showToggle />67// Textarea mode8<Input as="textarea" label="Bio" rows={4} maxLength={280} />910// Number with increment/decrement11<Input type="number" label="Quantity" min={0} max={99} step={1} />
Input supports text, password, textarea, and number variants
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | — | Accessible label text |
| type | 'text' | 'email' | 'password' | 'number' | 'text' | HTML input type |
| placeholder | string | — | Placeholder text |
| required | boolean | false | Marks as required |
| disabled | boolean | false | Disables interaction |
| error | string | — | Error message to display |
| onValidate | (value) => string | null | — | Custom validation function |
| showToggle | boolean | false | Shows visibility toggle for password |
| as | 'input' | 'textarea' | 'input' | Renders as textarea when set |
| maxLength | number | — | Maximum character count with indicator |
Validation States
typescript
1// Real-time validation2<Input3 label="Username"4 onValidate={(value) => {5 if (value.length < 3) return 'Too short'6 if (!/^[a-z0-9_]+$/.test(value)) return 'Only lowercase, numbers, underscores'7 return null8 }}9 validateOn="change"10/>1112// Server-side validation13<Input14 label="Email"15 error={serverErrors.email}16 onBlur={() => validateOnServer()}17/>
Validation runs on change or blur — configure per input
<callout>Tip: Use validateOn="blur" for expensive validations like API calls. Use "change" for instant feedback on format rules.
Accessibility
Input automatically associates labels via htmlFor/id. Error messages are announced via aria-describedby. Required fields show both visual and aria-required indicators.
<callout>All error messages are live regions. Screen readers announce validation errors as they appear.