ProPro components are coming soon. Stay tuned!

Input Component

The Input component provides a flexible text input field with support for labels, validation, icons, and helper text.

Basic Usage

import { Input } from 'nebula-ui';
 
export default function Example() {
  return (
    <Input 
      label="Email" 
      placeholder="Enter your email" 
      type="email"
    />
  );
}

With Label

Always provide a label for accessibility:

<Input 
  label="Username" 
  placeholder="@username" 
/>

Helper Text

Add helpful instructions below the input:

<Input 
  label="Password" 
  type="password"
  helperText="Must be at least 8 characters"
/>

Error State

Display validation errors:

<Input 
  label="Email" 
  type="email"
  error="Please enter a valid email address"
/>

With Icons

Add icons to provide visual context:

import { Input } from 'nebula-ui';
import { Mail, Lock } from 'lucide-react';
 
<Input 
  label="Email"
  leftIcon={<Mail />}
  placeholder="email@example.com"
/>
 
<Input 
  label="Password"
  type="password"
  rightIcon={<Lock />}
/>

Input Types

Support for all standard HTML input types:

<Input type="text" placeholder="Text input" />
<Input type="email" placeholder="Email input" />
<Input type="password" placeholder="Password input" />
<Input type="number" placeholder="Number input" />
<Input type="tel" placeholder="Phone input" />
<Input type="url" placeholder="URL input" />

Full Width

Make the input span the full width:

<Input 
  fullWidth
  label="Full Width Input"
  placeholder="This input spans full width"
/>

Props

PropTypeDefaultDescription
labelstring-Label text displayed above input
errorstring-Error message to display
helperTextstring-Helper text displayed below input
leftIconReactNode-Icon displayed on the left
rightIconReactNode-Icon displayed on the right
fullWidthbooleanfalseMakes input full width
typestring'text'HTML input type
placeholderstring-Placeholder text
disabledbooleanfalseDisables the input

Accessibility

The Input component is fully accessible:

  • Proper label association using htmlFor and id
  • Error messages are announced to screen readers
  • Keyboard navigation support
  • Focus management

Validation Examples

Email Validation

const [email, setEmail] = useState('');
const [error, setError] = useState('');
 
const validateEmail = (value: string) => {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  if (!emailRegex.test(value)) {
    setError('Please enter a valid email address');
  } else {
    setError('');
  }
};
 
<Input 
  label="Email"
  type="email"
  value={email}
  onChange={(e) => {
    setEmail(e.target.value);
    validateEmail(e.target.value);
  }}
  error={error}
/>

Required Field

<Input 
  label="Name"
  required
  helperText="This field is required"
/>

Best Practices

  1. Always use labels for accessibility
  2. Provide helper text for complex inputs
  3. Show clear error messages when validation fails
  4. Use appropriate input types for better mobile UX
  5. Add icons when they clarify the expected input

Examples

Login Form

<div className="space-y-4 max-w-md">
  <Input 
    label="Email"
    type="email"
    placeholder="you@example.com"
    leftIcon={<Mail />}
  />
  <Input 
    label="Password"
    type="password"
    placeholder="Enter your password"
    leftIcon={<Lock />}
  />
</div>

Search Input

<Input 
  placeholder="Search..."
  leftIcon={<Search />}
  fullWidth
/>

Was this page helpful?

Let us know if this documentation helped you.