Input
Material Design 3 form input components with outlined and filled variants
Input
Form inputs allow users to enter text. @duskmoon-dev/core provides Material Design 3 input variants and complete form components.
Basic Usage
Basic Input
html
<input type="text" class="input" placeholder="Enter text" />Input Variants
Filled Input (Default)
Filled inputs have a background color:
Filled Input
html
<input type="text" class="input" placeholder="Filled input" />Outlined Input
Outlined inputs have a border:
Outlined Input
html
<input type="text" class="input input-outlined" placeholder="Outlined input" />Sizes
Three sizes are available:
Input Sizes
html
<input type="text" class="input input-sm" placeholder="Small" />
<input type="text" class="input input-md" placeholder="Medium (default)" />
<input type="text" class="input input-lg" placeholder="Large" />Input States
Error State
Error State
html
<input type="email" class="input input-error" placeholder="email@example.com" />Success State
Success State
html
<input type="email" class="input input-success" value="valid@example.com" />Disabled State
Disabled State
html
<input type="text" class="input" placeholder="Disabled" disabled />Complete Input Group
Combine label, input, and helper text:
Input Group
Choose a unique username
html
<div class="input-group">
<label class="input-label" for="username">Username</label>
<input
type="text"
id="username"
class="input input-outlined"
placeholder="Enter your username"
/>
<span class="input-helper">Choose a unique username</span>
</div>Input with Error
Input with Error
html
<div class="input-group">
<label class="input-label" for="email">Email</label>
<input
type="email"
id="email"
class="input input-outlined input-error"
placeholder="you@example.com"
value="invalid-email"
/>
<span class="input-error-message">Please enter a valid email address</span>
</div>Input with Success
Input with Success
Strong password!
html
<div class="input-group">
<label class="input-label" for="password">Password</label>
<input
type="password"
id="password"
class="input input-outlined input-success"
value="••••••••"
/>
<span class="input-helper text-success">Strong password!</span>
</div>Textarea
Multi-line text input:
Textarea
html
<textarea
class="textarea"
rows="4"
placeholder="Enter your message"
></textarea>
<!-- Outlined textarea -->
<textarea
class="textarea textarea-outlined"
rows="4"
placeholder="Enter your message"
></textarea>Textarea with Label
Textarea with Label
Maximum 500 characters
html
<div class="input-group">
<label class="input-label" for="bio">Bio</label>
<textarea
id="bio"
class="textarea textarea-outlined"
rows="4"
placeholder="Tell us about yourself"
></textarea>
<span class="input-helper">Maximum 500 characters</span>
</div>Select
Dropdown selection:
Select
html
<select class="select">
<option>Select an option</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
<!-- Outlined select -->
<select class="select select-outlined">
<option>Choose...</option>
<option>Red</option>
<option>Green</option>
<option>Blue</option>
</select>Select with Label
Select with Label
html
<div class="input-group">
<label class="input-label" for="country">Country</label>
<select id="country" class="select select-outlined">
<option value="">Select a country</option>
<option value="us">United States</option>
<option value="uk">United Kingdom</option>
<option value="ca">Canada</option>
</select>
</div>Checkbox
Checkbox
html
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" class="checkbox" />
<span>I agree to the terms and conditions</span>
</label>
<!-- Checked checkbox -->
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" class="checkbox" checked />
<span>Subscribe to newsletter</span>
</label>
<!-- Disabled checkbox -->
<label class="flex items-center gap-2 cursor-pointer opacity-50">
<input type="checkbox" class="checkbox" disabled />
<span>Disabled option</span>
</label>Checkbox Group
Checkbox Group
Select your interests:
html
<div class="space-y-2">
<p class="font-medium mb-2">Select your interests:</p>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" class="checkbox" name="interests" value="design" />
<span>Design</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" class="checkbox" name="interests" value="development" />
<span>Development</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" class="checkbox" name="interests" value="marketing" />
<span>Marketing</span>
</label>
</div>Radio Buttons
Radio Buttons
Choose a plan:
html
<div class="space-y-2">
<p class="font-medium mb-2">Choose a plan:</p>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" class="radio" name="plan" value="free" checked />
<span>Free</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" class="radio" name="plan" value="pro" />
<span>Pro - $9.99/month</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" class="radio" name="plan" value="enterprise" />
<span>Enterprise - Custom pricing</span>
</label>
</div>Form Examples
Login Form
Login Form
html
<form class="space-y-4 max-w-sm">
<h2 class="text-2xl font-bold">Sign In</h2>
<div class="input-group">
<label class="input-label" for="login-email">Email</label>
<input
type="email"
id="login-email"
class="input input-outlined"
placeholder="you@example.com"
required
/>
</div>
<div class="input-group">
<label class="input-label" for="login-password">Password</label>
<input
type="password"
id="login-password"
class="input input-outlined"
placeholder="••••••••"
required
/>
</div>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" class="checkbox" />
<span class="text-sm">Remember me</span>
</label>
<button type="submit" class="btn btn-primary btn-block">
Sign In
</button>
<p class="text-sm text-center text-on-surface-variant">
Don't have an account? <a href="/signup" class="text-primary">Sign up</a>
</p>
</form>Contact Form
Contact Form
html
<form class="space-y-4 max-w-lg">
<h2 class="text-2xl font-bold">Contact Us</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="input-group">
<label class="input-label" for="first-name">First Name</label>
<input
type="text"
id="first-name"
class="input input-outlined"
placeholder="John"
required
/>
</div>
<div class="input-group">
<label class="input-label" for="last-name">Last Name</label>
<input
type="text"
id="last-name"
class="input input-outlined"
placeholder="Doe"
required
/>
</div>
</div>
<div class="input-group">
<label class="input-label" for="contact-email">Email</label>
<input
type="email"
id="contact-email"
class="input input-outlined"
placeholder="you@example.com"
required
/>
</div>
<div class="input-group">
<label class="input-label" for="subject">Subject</label>
<select id="subject" class="select select-outlined" required>
<option value="">Select a subject</option>
<option>General Inquiry</option>
<option>Technical Support</option>
<option>Billing</option>
<option>Other</option>
</select>
</div>
<div class="input-group">
<label class="input-label" for="message">Message</label>
<textarea
id="message"
class="textarea textarea-outlined"
rows="5"
placeholder="How can we help you?"
required
></textarea>
<span class="input-helper">Please provide as much detail as possible</span>
</div>
<div class="flex gap-2">
<button type="button" class="btn btn-outlined">Cancel</button>
<button type="submit" class="btn btn-primary">Send Message</button>
</div>
</form>Survey Form
Survey Form
html
<form class="space-y-6 max-w-2xl">
<h2 class="text-2xl font-bold">Product Feedback Survey</h2>
<div class="input-group">
<label class="input-label">How would you rate our product?</label>
<div class="space-y-2">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" class="radio" name="rating" value="5" />
<span>Excellent</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" class="radio" name="rating" value="4" />
<span>Good</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" class="radio" name="rating" value="3" />
<span>Average</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" class="radio" name="rating" value="2" />
<span>Poor</span>
</label>
</div>
</div>
<div class="input-group">
<label class="input-label">Which features do you use most?</label>
<div class="space-y-2">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" class="checkbox" name="features" value="analytics" />
<span>Analytics Dashboard</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" class="checkbox" name="features" value="reporting" />
<span>Reporting Tools</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" class="checkbox" name="features" value="integrations" />
<span>Integrations</span>
</label>
</div>
</div>
<div class="input-group">
<label class="input-label" for="feedback">Additional Feedback</label>
<textarea
id="feedback"
class="textarea textarea-outlined"
rows="4"
placeholder="Tell us what you think..."
></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit Survey</button>
</form>Best Practices
Labels
Always provide labels for inputs:
Input Labels
html
<!-- Good -->
<label class="input-label" for="email-label-example">Email</label>
<input type="email" id="email-label-example" class="input" />
<!-- Also good: Using aria-label for icon inputs -->
<input type="search" class="input" aria-label="Search" placeholder="Search..." />Helper Text
Use helper text for additional guidance:
Helper Text
Must be 3-20 characters, letters and numbers only
html
<div class="input-group">
<label class="input-label" for="username-helper-example">Username</label>
<input type="text" id="username-helper-example" class="input input-outlined" />
<span class="input-helper">Must be 3-20 characters, letters and numbers only</span>
</div>Error Handling
Provide clear error messages:
Error Handling
html
<div class="input-group">
<label class="input-label" for="password-error-example">Password</label>
<input
type="password"
id="password-error-example"
class="input input-outlined input-error"
aria-invalid="true"
aria-describedby="password-error-msg"
/>
<span id="password-error-msg" class="input-error-message" role="alert">
Password must be at least 8 characters
</span>
</div>Accessibility
- Always use proper
<label>elements - Provide helpful error messages
- Use appropriate input types (
email,tel,url, etc.) - Add
aria-describedbyfor helper text - Use
aria-invalidfor error states
Framework Examples
React with Validation
import { useState } from 'react';
export function EmailInput() {
const [email, setEmail] = useState('');
const [error, setError] = useState('');
const validateEmail = (value: string) => {
if (!value) {
setError('Email is required');
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
setError('Please enter a valid email');
} else {
setError('');
}
};
return (
<div className="input-group">
<label className="input-label" htmlFor="email">Email</label>
<input
type="email"
id="email"
className={`input input-outlined ${error ? 'input-error' : ''}`}
value={email}
onChange={(e) => setEmail(e.target.value)}
onBlur={(e) => validateEmail(e.target.value)}
aria-invalid={!!error}
aria-describedby={error ? 'email-error' : undefined}
/>
{error && (
<span id="email-error" className="input-error-message" role="alert">
{error}
</span>
)}
</div>
);
}
API Reference
Class Names
| Class | Description |
|---|---|
.input | Base input styles (filled variant) |
.input-outlined | Outlined input variant |
.input-sm | Small size |
.input-md | Medium size (default) |
.input-lg | Large size |
.input-error | Error state |
.input-success | Success state |
.textarea | Multi-line text input |
.textarea-outlined | Outlined textarea |
.select | Dropdown select |
.select-outlined | Outlined select |
.checkbox | Checkbox input |
.radio | Radio button input |
.input-group | Container for label + input + helper |
.input-label | Input label |
.input-helper | Helper text |
.input-error-message | Error message text |