Field Wrapper
Field Wrapper Component
The Field Wrapper component provides a consistent container for form fields with built-in support for labels, helper text, error messages, character counting, and accessibility attributes.
Example
We'll never share your email
This username is already taken
Tell us about yourself
Usage
The Field Wrapper is typically used by form field components internally, but you can also use it directly to wrap custom inputs:
import FieldWrapper from "@altitude/ui/react/components/field-wrapper";import TextInput from "@altitude/ui/react/ui/text-input";
export default function CustomField() { return ( <FieldWrapper id="email" name="email" label="Email Address" helperText="We'll never share your email" errorMessage="Please enter a valid email" required={true} > <TextInput /> </FieldWrapper> );}Props
| Prop | Type | Required | Description |
|---|---|---|---|
| id | string | No | HTML ID for the field |
| name | string | No | HTML name attribute for the field |
| label | string | No | Label text for the field |
| helperText | string | No | Helper text displayed below the field |
| errorMessage | string | No | Error message displayed when aria-invalid is true |
| placeholder | string | No | Placeholder text for the input |
| required | boolean | No | Whether the field is required (default: false) |
| aria-invalid | boolean | No | Whether the field has an error (default: false) |
| disabled | boolean | No | Whether the field is disabled (default: false) |
| maxlength | number | No | Maximum character count for the field |
| children | ReactNode | Yes | The input component to wrap |
Features
- Automatically sets appropriate aria attributes for accessibility
- Displays “Required” or “Optional” indicators based on the required prop
- Shows character count for fields with maxlength
- Handles error states with error messaging
- Maintains consistent styling and layout for all form fields