Components
Input
A versatile text input component for forms and user input
Input
The Input component is a versatile text input field for collecting user data. It supports all standard HTML input types and provides consistent styling across your application.
Installation
npm install @nqlib/nquiImport
import { Input } from '@nqlib/nqui';Basic Usage
import { Input } from '@nqlib/nqui';
export default function Example() {
return <Input type="text" placeholder="Enter your name" />;
}Examples
Basic Input
With Label
Input Types
States
With Error State
Please enter a valid email address
Example Code
With Label
Always pair inputs with labels for accessibility
Loading preview…
example.tsx
'use client';import { Input, Label } from '@nqlib/nqui';export default function Example() { return ( <div className="space-y-2"> <Label htmlFor="email">Email</Label> <Input id="email" type="email" placeholder="name@example.com" /> </div> );}Error State
Show error feedback with styling and message
Loading preview…
example.tsx
'use client';import { Input, Label } from '@nqlib/nqui';export default function Example() { return ( <div className="space-y-2"> <Label htmlFor="email">Email</Label> <Input id="email" type="email" placeholder="name@example.com" className="border-destructive focus-visible:ring-destructive" aria-invalid="true" /> <p className="text-sm text-destructive">Please enter a valid email address</p> </div> );}Input Types
The Input component supports all standard HTML input types:
text- Single-line text inputemail- Email address inputpassword- Password input (masked)number- Numeric inputdate- Date pickertime- Time pickerdatetime-local- Date and time pickersearch- Search inputtel- Telephone number inputurl- URL inputfile- File upload (with special styling)
States
Disabled
<Input type="text" placeholder="Disabled input" disabled />Read Only
<Input type="text" value="Read only value" readOnly />Props
The Input component accepts all standard HTML input attributes:
| Prop | Type | Default | Description |
|---|---|---|---|
type | string | "text" | Input type (text, email, password, etc.) |
placeholder | string | - | Placeholder text |
disabled | boolean | false | Whether the input is disabled |
readOnly | boolean | false | Whether the input is read-only |
value | string | - | Controlled input value |
defaultValue | string | - | Uncontrolled input default value |
className | string | - | Additional CSS classes |
All standard input props | - | - | Accepts all HTML input attributes |
Styling
Inputs use the following design tokens:
- Border:
border-input - Background:
bg-background - Text:
text-foreground - Placeholder:
text-muted-foreground - Focus ring:
ring-ringwithring-offset-background - Disabled:
opacity-50withcursor-not-allowed
You can customize the appearance using Tailwind classes:
<Input className="border-2 border-primary focus-visible:ring-primary" />Accessibility
- Proper label association via
htmlForandid - ARIA attributes for error states (
aria-invalid) - Keyboard navigation support
- Screen reader friendly
- Focus management with visible focus rings
Best Practices
- Always use labels: Pair every input with a label for accessibility
- Use appropriate types: Choose the correct input type for better UX (email, password, etc.)
- Provide placeholders: Use helpful placeholder text to guide users
- Handle errors: Show clear error messages and highlight invalid inputs
- Consider validation: Use HTML5 validation attributes (
required,pattern, etc.)
Next Steps
- Learn about Textarea for multi-line input
- Explore Field component for form field wrapper with error handling
- Check out InputGroup for inputs with addon elements
- See Form Components for other form elements