Input
A text field that passes through native input attributes.
Overview
Input renders a native input. The default type is text. It does not wrap the control, so labels, descriptions, and validation attributes use normal HTML.
Preview
Customize
Installation
Add the component with the CLI. It copies the files in and installs anything they depend on.
npx vinyaas add inputUsage
import { Input } from "@/components/ui/input";
export function EmailField() {
return (
<label htmlFor="email" className="flex flex-col gap-2 text-sm">
Email
<Input id="email" name="email" type="email" placeholder="name@example.com" />
</label>
);
}Examples
Basic
A text input with an accessible name from aria-label.
type controls the native input. Email asks for an email address.
Label and description
Associate a label with htmlFor and id. Point aria-describedby at the help text.
We use this for account recovery.
Required
required is the native constraint. The label should say that the field is required.
Disabled
A disabled input cannot be edited and uses the not-allowed cursor.
Invalid
aria-invalid is forwarded to the input. The component does not change its border for that state.
In practice
Email and password fields sit above a remember checkbox and a Sign in button.
API
Other attributes for the underlying element are passed through.
| Name | Type | Default | Description |
|---|---|---|---|
type | string | "text" | Native input type. |
className | string | — | Merged onto the input with cn. |
disabled | boolean | — | Native disabled state. Uses a not-allowed cursor and reduced opacity. |
placeholder | string | — | Placeholder text. It is not a label. |
required | boolean | — | Native required state. |
value | string | — | Controlled value. Pair it with onChange. |
defaultValue | string | — | Uncontrolled initial value. |
aria-invalid | "true" | "false" | — | Passed through. Input does not add a separate invalid color. |
Accessibility
Input is a native input. It does not add an ARIA role.
- Name it with a label and matching id, or with aria-label.
- Placeholder text is not a replacement for the label.
- Use the native type, such as email or password, when it matches the data.
- disabled prevents editing. Focus uses a visible focus-visible ring.
- aria-invalid and aria-describedby are passed through.