Skip to main content

Input

A text input component for collecting user text data with built-in support for labels, helper text, and validation states.

Overview​

The Input component provides a semantic wrapper around HTML's native <input type="text"> element with support for different validation states and helper text.

Examples​

Default Input​

<Input label="Email" placeholder="Enter your email" />

With Helper Text​

Username must be at least 3 characters
<Input label="Username" placeholder="Enter username" helperText="Username must be at least 3 characters" />

Error State​

Invalid email format
<Input variant="error" label="Email" value="invalid" helperText="Invalid email format" />

Success State​

Username is available
<Input variant="success" label="Username" value="john_doe" helperText="Username is available" />

Disabled State​

<Input label="Disabled" placeholder="This is disabled" disabled />

Props​

PropTypeDefaultDescription
variant"default" | "error" | "success""default"Visual style variant
labelstring—Label text
helperTextstring—Helper text below input
disabledboolean—Disable the input
placeholderstring—Placeholder text
...propsInputHTMLAttributes—All native input attributes

Usage​

import { Input } from "@milfushi/ui";

export function LoginForm() {
const [email, setEmail] = useState("");
const [error, setError] = useState("");

const handleChange = (e) => {
setEmail(e.target.value);
setError(""); // Clear error on input
};

return (
<Input
label="Email"
type="email"
value={email}
onChange={handleChange}
variant={error ? "error" : "default"}
helperText={error || "We'll never share your email"}
/>
);
}

Styling​

The Input component renders with semantic HTML that you can style:

<div data-variant="default">
<label>Email</label>
<input type="email" placeholder="..." />
<span>Helper text</span>
</div>

Style using the data attributes:

div[data-variant="default"] input {
/* Your styles */
}

div[data-variant="error"] input {
border-color: #ef4444;
}

div[data-variant="success"] input {
border-color: #10b981;
}

Or import the pre-built component styles:

@import "@milfushi/ui/dist/components.css";

Accessibility​

  • Automatically associates labels with inputs using unique IDs
  • Supports aria-label and aria-describedby for unlabeled inputs
  • Helper text is semantically marked as role="status" for screen readers
  • Full keyboard support (Tab, Enter, etc.)
  • Visual focus indicators for keyboard navigation