TextInput
A comprehensive input component with support for text, password, search, numbers, validation states, and icons.
Installation
npx vayu-ui-cli@latest add text-inputUsage
TextInput and Select share field heights: sm is 36px, md is 44px, and lg is 52px at the default root font size. Set size and disabled on the root. Disabled fields share the same muted background, opacity, and border behavior; clear and password visibility actions are disabled too.
TextInput Examples
Basic Input
We'll never share your email.
Required & Optional Fields
Password (with visibility toggle)
Must be at least 8 characters.
Search (with clear button)
Number Inputs
Value constrained between 0 and 10 on blur.
Validation States
Please enter a valid email address.
Password is weak. Consider adding special characters.
Username is available!
Character Count
0 / 50
Sizes
States
With Form Actions
Choose a unique name for your project.
Anatomy
import { TextInput } from 'vayu-ui';
<TextInput>
<TextInput.Label />
<TextInput.Field>
<TextInput.Icon />
<TextInput.Input /> {/* Standard Input */}
<TextInput.PasswordInput /> {/* OR Password Input */}
<TextInput.SearchInput /> {/* OR Search Input */}
<TextInput.NumberInput /> {/* OR Number Input */}
<TextInput.ClearButton />
<TextInput.LoadingSpinner />
</TextInput.Field>
<TextInput.Description />
<TextInput.ErrorMessage />
<TextInput.WarningMessage />
<TextInput.SuccessMessage />
<TextInput.CharacterCount />
</TextInput>;Accessibility
- Keyboard support: Full keyboard navigation. Input fields are accessible via
Tab. The internal clear button and password toggle button can be fully operated usingSpaceorEnter. - ARIA attributes: Uses
aria-invalidfor validation states. The label, description, and error messages are programmatically tied to the inputs usingaria-labelledbyandaria-describedby, correctly mapping compound components behind the scenes. - Focus behavior: Clear visual focus indicates the active field based on the internal Field container, not just the Input.
Screen reader behavior
Screen readers will announce the input's label, its current value or a placeholder, any help descriptions, and the validation state error message. For example, a missing required field might be announced as "Email, required, edit text, invalid entry, Email is required."
Component Folder Structure
packages/ui/src/components/ui/TextInput/
├── Input.tsx
├── README.md
├── TextInput.tsx
├── TextInputCharacterCount.tsx
├── TextInputClearButton.tsx
├── TextInputDescription.tsx
├── TextInputErrorMessage.tsx
├── TextInputField.tsx
├── TextInputIcon.tsx
├── TextInputLabel.tsx
├── TextInputLoadingSpinner.tsx
├── TextInputNumberInput.tsx
├── TextInputPasswordInput.tsx
├── TextInputSearchInput.tsx
├── TextInputSuccessMessage.tsx
├── TextInputWarningMessage.tsx
├── index.ts
└── types.tsProps
TextInput
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | - | The controlled state component value. |
defaultValue | string | "" | The uncontrolled starting value. |
onChange | (value: string) => void | - | Handler that is called when the value changes. |
inputType | "text" | "email" | "password" | "number" | "tel" | "url" | "search" | "text" | Specifies the primary input style format. |
size | "sm" | "md" | "lg" | "md" | The size of the input elements. |
validationState | "default" | "error" | "warning" | "success" | "default" | Defines the current validation styling. |
disabled | boolean | false | Whether the input is completely disabled. |
readOnly | boolean | false | Whether the input value is read only. |
required | boolean | false | Marks the field as required. |
loading | boolean | false | Visually marks the input as loading. |
className | string | - | Additional class names for styling. |
TextInput.Label
| Prop | Type | Default | Description |
|---|---|---|---|
optional | boolean | false | Displays an internal "Optional" hint next to the label. |
className | string | - | Additional class names for styling. |
TextInput.Input
| Prop | Type | Default | Description |
|---|---|---|---|
leftIcon | ReactNode | - | Deprecated/Alternative icon passing. |
rightIcon | ReactNode | - | Deprecated/Alternative icon passing. |
type | InputType | - | Overrides context's inputType if needed. |
... | InputHTMLAttributes<HTMLInputElement> | - | Supports any standard native input attributes. Avoid value and onChange. |
TextInput.PasswordInput
| Prop | Type | Default | Description |
|---|---|---|---|
... | InputProps | - | Inherits all properties from normal inputs. Includes toggle action built-in. |
TextInput.NumberInput
| Prop | Type | Default | Description |
|---|---|---|---|
numberType | "integer" | "decimal" | "positive" | "natural" | - | Sets constraints format parameters on input values. |
format | boolean | false | Group digits with commas; root onChange receives the unformatted string. |
min | number | - | Minimum value allowed visually / bound. |
max | number | - | Maximum value allowed visually / bound. |
step | number | - | Step intervals. |
TextInput.CharacterCount
| Prop | Type | Default | Description |
|---|---|---|---|
maxLength | number | - | Re-define the overall max character total for display (used purely for text display). |
showCount | "always" | "focus" | "near-limit" | - | Dictates when the counter is visible. |
threshold | number | - | Triggers display change based upon 'near-limit'. |
className | string | - | Additional class names for styling. |
Formatted numbers
Use format on TextInput.NumberInput to group digits with commas. Leading zeros normalize (01 → 1, 00 → 0) and 1212 displays as 1,212. The root onChange receives the unformatted string, so validation and submission use "1212". Empty input stays empty. Decimal fractions and large integers keep their precision; min and max apply on blur.
<TextInput value={amount} onChange={setAmount}>
<TextInput.Label>Amount</TextInput.Label>
<TextInput.Field>
<TextInput.NumberInput format numberType="natural" />
</TextInput.Field>
</TextInput>Initialize amount with useState(''). Leave format false for ungrouped numeric entry. This is numeric input, so use a regular TextInput.Input for identifiers where leading zeros must be preserved.