[ Forms ]
Input
A text field with a built-in label, helper text, error message and optional icons. It wraps a native <input>, so every input type works (text, email, password, number, search, date…).
Import#
import { Input } from 'reusify-ui';When to use#
- Collecting short, single-line text such as names, emails, passwords or search queries.
- Use Textarea for multi-line text and Select for picking from a fixed list.
- Always give the field a visible label. Placeholders disappear when typing and are not a substitute.
Examples#
Basic#
label and helperText are wired to the input automatically: the label is clickable and the hint is announced by screen readers.
We'll never share your email.
<Input
label="Email"
type="email"
placeholder="you@example.com"
helperText="We'll never share your email."
/>With icons#
leftIcon and rightIcon render inside the field. rightIcon can be interactive, like a show/hide password toggle.
Validation & errors#
Pass error={true} to only highlight the field, or a string to show a message in place of the helper text. Try typing a valid email.
Enter a valid email address
function EmailField() {
const [email, setEmail] = useState('mukesh@');
const valid = /^\S+@\S+\.\S+$/.test(email);
return (
<Input
label="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
error={!valid && 'Enter a valid email address'}
helperText="Looks good!"
/>
);
}Sizes#
Match input size to the buttons around it: sm, md (default) and lg.
<Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" />Required & disabled#
<Input label="Full name" required />
<Input label="Username" defaultValue="mukesh" disabled />With React Hook Form#
Input forwards its ref to the native <input>, so register() works directly.
Used in designs#
Input in real layouts: these 8 designs use it. Open one to try it and copy the code.
- Activity feedTasks & workflow
- Pattern sign-upAuthentication
- Sign inAuthentication
- Forgot passwordAuthentication
- Reset passwordAuthentication
- Invite teammatesAuthentication
- Pro welcomeAnnouncements & modals
- Job cardsProductivity
API reference#
<Input />
Also accepts every native <input> attribute and forwards its ref to the <input>.
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | 'md' | Field height and font size. |
leftIcon | ReactNode | - | Element rendered inside the field, before the text. |
rightIcon | ReactNode | - | Element rendered inside the field, after the text. |
label | ReactNode | - | Label rendered above the control and linked to it via htmlFor. |
helperText | ReactNode | - | Hint shown below the control. |
error | boolean | string | - | Marks the field invalid (red border, aria-invalid). A string also replaces the helper text. |
fullWidth | boolean | false | Makes the field fill its container. |
containerClassName | string | - | Class for the outer wrapper. className goes on the native element. |
required | boolean | false | Native required, plus a red asterisk after the label. |
disabled | boolean | false | Disables and dims the field. |
size'md''sm' | 'md' | 'lg'Field height and font size.
leftIcon-ReactNodeElement rendered inside the field, before the text.
rightIcon-ReactNodeElement rendered inside the field, after the text.
label-ReactNodeLabel rendered above the control and linked to it via htmlFor.
helperText-ReactNodeHint shown below the control.
error-boolean | stringMarks the field invalid (red border, aria-invalid). A string also replaces the helper text.
fullWidthfalsebooleanMakes the field fill its container.
containerClassName-stringClass for the outer wrapper. className goes on the native element.
requiredfalsebooleanNative required, plus a red asterisk after the label.
disabledfalsebooleanDisables and dims the field.
Accessibility#
- The label is a real <label htmlFor> tied to the input id (auto-generated with useId if you don't pass one).
- Helper and error text are linked with aria-describedby, so they are read when the field gets focus.
- error sets aria-invalid="true".
- The required asterisk is aria-hidden; the native required attribute conveys the requirement.