Directory
- Welcome
Input Component
The Input component provides a flexible and accessible way to capture user input in forms. With support for different styles, sizes, and states, it adapts to various design requirements while maintaining consistency.
Key Features
-
Multiple Variants: Choose between default and underline styles
-
Flexible Sizing: Three size options to match your design
-
Built-in Validation: Support for required fields and error states
-
Accessibility: ARIA-compliant with label support
Basic Usage
Create a simple input field with minimal configuration:
<Input placeholder="Enter your name" />
Variants
Style Variants
Choose between two distinct visual styles:
<Input variant="default" placeholder="Default variant" /><Input variant="underline" placeholder="Underline variant" />
Size Variants
Select from three size options:
<Input size="sm" placeholder="Small input" /><Input size="default" placeholder="Default input" /><Input size="lg" placeholder="Large input" />
Form Integration
Labels and Validation
Add labels and validation indicators for better user experience, validation is done when the user has left the input field and the input is invalid:
<Input label="Username" placeholder="Enter username" /><Input label="Email" type="email" required placeholder="Enter email" /><Input label="Password" required type="password" minLength={8} sublabel="Must be at least 8 characters" placeholder="Enter password"/>
Input States
Handle different input states gracefully:
<Input placeholder="Normal state" /><Input disabled placeholder="Disabled state" /><Input data-state="error" placeholder="Error state" />
Password Input with Show/Hide Toggle
Add a show/hide toggle button for password inputs:
<Input label="Password" hideInput placeholder="Enter password"/>
Input Component Props API
Prop | Type | Default | Description |
---|---|---|---|
label | string | undefined | Text label above the input |
sublabel | string | undefined | Helper text below the input |
variant | default | underline | default | Visual style variant |
size | sm | default | lg | default | Input size |
showRequirements | boolean | true | Show requirements |
showRequired | boolean | true | Show required symbol |
requirements | string[] | [] | Requirements |
hideInput | boolean | false | Enables show/hide toggle for password inputs (default is hide) |
Limited Time Launch Sale
Build better forms with our Input component. Get started with our AstroJS starter template today!
GET 60% OFF!