This component is based on the <textarea> element and can take in any additional HTML attributes through the use of the inputProps property. The following are the custom props that can be passed to the component.
Prop
Type
Default
name *
Unique name of the textarea. Should follow a kebab-case naming convention (e.g. "first-name")
string
—
label *
Visual or assistive label for the textarea
string
—
labelHidden
Whether to visually hide the label or not. When hidden, the label will still be available to screen readers
boolean
false
sublabel
Sub-label content for the textarea
string
—
instructions
Instructions for the textarea that will be placed below the input
string
—
placeholder
Placeholder text for the textarea
string
—
disabled
Whether the textarea is disabled or not
boolean
false
required
Whether the textarea is required or not. If set to "long", the textarea will be marked as required and include explicit "required" text.
boolean | "long"
false
inputProps
Additional attributes to pass to the textarea field
HTMLAttributes<textarea>
—
errorMessages
Error messages to display below the textarea
string[]
—
Accessibility
The <TextArea> component is designed with accessibility in mind and extends much of the accessibility features from the <Field Group> component. The following are some of the field specific accessibility features that are included in the component and worth considering:
The aria-labelledby attribute is used to associate the label and instructions elements with the input field. This is an important consideration specifically for the instructions so that they are read out by screen readers when the field is focused, rather than after the input field.
Examples
Required
Use the required prop to mark a field as required. You can also use the required prop to mark a field as required and include explicit “required” text by passing the value "long".
It’s recommended that an element like this is made as a reusable component. In this case, we have put together the following Astro component to serve as a blueprint for how you could possibly set up a textarea component, and what properties to consider.