Components
Textarea
use: best-practiceExamples
Default
View va-textarea default in Storybook
Required
View va-textarea required in Storybook
Hint text
View va-textarea with hint text in Storybook
With Character count
View va-textarea with character count in Storybook
Forms pattern - Single
View va-textarea forms pattern single in Storybook
Forms pattern - Single error
View va-textarea forms pattern single error in Storybook
Forms pattern - Multiple
View va-textarea forms pattern multiple in Storybook
Forms pattern - Multiple error
View va-textarea forms pattern multiple error in Storybook
Error
View va-textarea error in Storybook
Usage
Additional guidance for VA
When to consider something else
- Predictable text. When a short, single line of text is expected and sufficient.
Errors
- Refer to the specific error examples above.
Code usage
Using message-aria-describedby
In HTML, the attribute aria-describedby accepts ids of the elements that describe an object. This is used to establish a relationship between an element and text elsewhere that describes it for screen readers.
However, the VA.gov Design System uses web components and the shadow DOM, which prevents HTML’s aria-describedby from being able to establish the relationship between elements. Because of that, the message-aria-describedby prop is used in our components instead. Instead of accepting ids, it accepts a message string to read out. This message is placed inside the shadow DOM, hidden visually, but made accessible to screen readers. This allows it to function similarly to aria-describedby and have the descriptive text read out when the element is focused.
Native Events
- Native onInput and onBlur events are available on this component. They can be used by adding the event handler to your component and it will then listen to the event and respond accordingly when the event fires.
Accessibility considerations
- Avoid
placeholdertext. Excluding our max characters variation (v1), avoid using placeholder text. Most browsers’ default rendering of placeholder text does not provide a high enough contrast ratio. Also, placeholder text is no longer visible once a user clicks into the field. Thus users will no longer have that text available when they need to review their entries. People who have cognitive or visual disabilities have additional problems with placeholder text. - When using placeholder text, provide screen reader accessible text. When using the placeholder prop, which is used automatically by the Max length variation (v1 only), additional work is required to make the component accessible. Screen readers such as JAWS and NVDA don’t read placeholder text. Placeholder text is a visual addition only. Thus when using placeholder text to provide important information visually you must also convey this information to screen reader users as well. To do this this add screen read only text within a
<span>using the.sr-onlyCSS class and place the span and text where you would like it to be read out, typically after the field label. - Only show error validation messages or stylings after a user has interacted with a particular field. Do not interrupt a user while they are entering text into a textarea.
Privacy guidance
An open text field has a high risk for users to enter Personally Identifiable Information (PII) or Protected Health Information (PHI).
- Responses provided in open text fields should never be tracked in analytics
- If the responses are utilized in elements on follow-on or related pages—such as an H1—ensure that information isn’t tracked in analytics or passed in URLs
Learn more about PII/PHI on the VA Platform website
Provide feedback
Share your feedback, report issues, or suggest improvements for the Textarea component. Your input helps us make the design system better for everyone.
- Get immediate support in #platform-design-system for technical or urgent issues.
- Explore all feedback channels for additional ways to share your input.