Input
A versatile and accessible input field with multiple variants including floating labels and outlined styles for modern form interfaces.
Installation
Install the component directly into your project using the Pittaya CLI.
npx pittaya@latest add input
When to use
Use the Input component when you need to collect textual data from users. It's ideal for forms, search interfaces, and any scenario where users need to enter information like names, emails, passwords, or other text-based data.
The component offers multiple variants to match different design patterns: floating labels for modern interfaces, outlined style for Material Design aesthetics, and traditional inputs for classic forms.
Best practices
- Always provide descriptive labels for accessibility, using the
labelprop for floating/outlined variants or theLabelcomponent for default inputs. - Use appropriate
typeattributes (email, password, number) to enable browser validation and mobile keyboard optimization. - Provide helpful placeholders that exemplify the expected format, but don't rely on them as the only form of instruction.
- Validate data on both client and server sides for better UX and security.
- Choose the variant that best fits your design system: floating for modern apps, outlined for Material Design, or default for traditional forms.
- Provide clear error messages using
aria-invalidand error text when validation fails.
Accessibility
The Input component is built with accessibility in mind, following WAI-ARIA best practices for form controls.
- Always associate inputs with labels using the
labelprop orhtmlForattributes. - The component automatically handles
aria-invalidstates with visual feedback through ring colors. - Floating and outlined variants maintain label visibility at all times, improving accessibility for users with cognitive disabilities.
- The component supports
disabledstate with proper styling and cursor behavior. - Focus states are clearly visible with ring indicators for keyboard navigation users.
Variants
The Input component offers four distinct variants:
- Default - Standard input field with traditional styling, best paired with an external Label component.
- Floating - Label starts inside the input and animates to float above the border when focused or filled. Creates a modern, space-efficient design.
- Floating Inside - Label starts centered in the input and animates to the top-left corner when focused or filled, remaining within the input boundaries.
- Outlined - Material Design style with the label positioned on the border, creating a clean outlined appearance. Label animates from inside to the border on focus/fill.
Examples
Combine variants and sizes to meet your needs.
Default input
Standard input field with traditional styling, best used with an external Label component.
Floating label
Label starts inside the input and floats above the border when focused or filled, creating a modern space-efficient design.
Floating label inside
Label animates from center to top-left corner, remaining within the input boundaries. Perfect for compact forms.
Outlined input
Material Design style with label positioned on the border. Label animates from inside to the border on focus or when filled.
Disabled state
Inputs can be disabled to prevent user interaction, with appropriate visual feedback.
Complete form
A complete form example demonstrating different input variants working together.
Variants comparison
Visual comparison of all available input variants side by side.
Properties
TSX interface that combines variants and default attributes.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'floating' | 'floatingInside' | 'outlined' | 'default' | Defines the visual style and label behavior of the input. Each variant offers unique animations and positioning. |
label | string | — | Label text for floating, floatingInside, and outlined variants. If not provided, falls back to the placeholder value. |
type | 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | ... | 'text' | Defines the input type, controlling validation behavior and mobile keyboard type. |
placeholder | string | — | Example text displayed when the field is empty (for default variant) or used as fallback label. |
disabled | boolean | false | Disables interaction with the field and applies disabled styling. |
className | string | — | Additional CSS classes to customize the input appearance. |