[ 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…).

6 examplesDark modeAccessible

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.

<Input label="Search" placeholder="Search components…" leftIcon={<FiSearch />} />

function PasswordInput() {
  const [show, setShow] = useState(false);
  return (
    <Input
      label="Password"
      type={show ? 'text' : 'password'}
      leftIcon={<FiLock />}
      rightIcon={
        <button type="button" onClick={() => setShow(!show)}
          aria-label={show ? 'Hide password' : 'Show password'}>
          {show ? <FiEyeOff /> : <FiEye />}
        </button>
      }
    />
  );
}

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.

Email is required

import { useForm } from 'react-hook-form';

function SignupForm() {
  const { register, handleSubmit, formState: { errors } } = useForm();

  return (
    <form onSubmit={handleSubmit(console.log)}>
      <Input
        label="Email"
        {...register('email', { required: 'Email is required' })}
        error={errors.email?.message}
        leftIcon={<FiAtSign />}
      />
      <Button type="submit">Sign up</Button>
    </form>
  );
}

Used in designs#

Input in real layouts: these 8 designs use it. Open one to try it and copy the code.

API reference#

<Input />

Also accepts every native <input> attribute and forwards its ref to the <input>.

size'md'
'sm' | 'md' | 'lg'

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.

fullWidthfalse
boolean

Makes the field fill its container.

containerClassName-
string

Class for the outer wrapper. className goes on the native element.

requiredfalse
boolean

Native required, plus a red asterisk after the label.

disabledfalse
boolean

Disables 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.