Usage
Textarea lets users write text across multiple rows. Reach for it when the expected input is long; for shorter, single-line input use an Input instead.
The textarea renders its built-in label, hint and error on its own. Wrapped in a Field, the Field takes over with a Field Label, Field Description and Field Error, and the built-in versions step aside automatically.
import "@nordhealth/components/lib/Textarea"
import "@nordhealth/components/lib/Field"
import "@nordhealth/components/lib/FieldLabel"
import "@nordhealth/components/lib/FieldDescription"
Standalone or inside a Field
Use the control on its own with its built-in label, hint and error, or wrap it in a Field — the Field then provides the labelling. Both render the same control:
Examples
Sizes
Use the size attribute to render a small, medium (default) or large textarea.
Character counter
Set character-counter to show a count of the characters entered. When combined with maxlength, both the count and the maximum are shown.
Error
Show validation with a Field Error and mark the Field invalid.
Disabled and read-only
A disabled textarea cannot be focused or edited and is excluded from form submission. A readonly textarea can be focused but not edited, and its value is still submitted.
Expand
Use expand to make the textarea fill the width of its container.
Hint
Add a Field Hint to give the user extra guidance about what to enter.
Required
Set required on the Field Label to mark the field as mandatory and show the required indicator.
Hidden label
Use a visually hidden label when the context already makes the textarea's purpose clear. The label stays available to assistive technology.
Auto resize
Let the textarea grow to fit its content as the user types instead of showing a scrollbar.
Custom height
Set a fixed height with the rows attribute or a CSS custom property.
Text selection
Programmatically select text within the textarea using the selection APIs.
RTL
Textarea follows the document or container direction. Toggle the direction to see the layout mirror.
Accessibility
- Always give the textarea an accessible name with a Field Label connected via
for. - Convey validation with a Field Error rather than colour alone — it is associated with the textarea and announced to assistive technology.
- Mark required fields by setting
requiredon the Field Label; it shows the indicator and marks the control required. - When using
character-counterwithmaxlength, the remaining-character count is exposed as a live region so screen reader users are informed as they approach the limit. - Prefer
readonlyoverdisabledwhen the value is still relevant but not editable, as disabled controls are removed from the tab order and not submitted with the form.
API reference
Textarea
Textarea is a component that allows user to write text over multiple rows. Used when the expected user input is long. For shorter input, use the Input component.
<nord-textarea></nord-textarea>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
resize | resize | Controls whether the textarea is resizable. By default is manually resizable vertically. Set to "auto" to enable auto-resizing as content grows. | 'vertical' | 'auto' | 'vertical' |
expand | expand | Controls whether the textarea expands to fill the width of its container. | boolean | false |
maxLength | maxlength | Controls the max allowed length for the textarea. | number | undefined | — |
characterCounter | character-counter | Controls whether to show a count of the number of characters in the textarea.
When combined with maxlength, both the count and the max length are shown. | boolean | false |
size | size | The size of the component. | 's' | 'm' | 'l' | 'm' |
placeholder | placeholder | Placeholder text to display within the control. | string | undefined | — |
required | required | Determines whether the control is required or not.
A required control is announced as such to assistive technology and, inside
a <nord-field>, drives the required indicator on the <nord-field-label>.
When using this property you need to also set “novalidate” attribute on a form element to prevent browser from displaying its own validation errors. | boolean | false |
autocomplete | autocomplete | Specifies the data type of the field, so that the browser may attempt to fill out the field automatically on behalf of the user. | AutocompleteAttribute | 'off' |
readonly | readonly | Makes the component readonly, so that it is not editable. Readonly differs from disabled in that readonly fields are still focusable and will be submitted with a form. | boolean | false |
disabled | disabled | Makes the component disabled. This prevents users from being able to interact with the component, and conveys its inactive state to assistive technologies. | boolean | false |
name | name | The name of the form component. | string | undefined | — |
value | value | The value of the form component. | string | '' |
form | form | Gets the form, if any, associated with the form element. The setter accepts a string, which is the id of the form. | HTMLFormElement | null | — |
Field properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
label | label | Label for the control. Ignored when the control is wrapped in a
<nord-field>, which provides the label via <nord-field-label>. | string | '' |
hint | hint | Optional hint text shown with the control. Ignored inside a <nord-field>,
which provides it via <nord-field-description>. | string | undefined | — |
hintBelow | hint-below | Renders the hint below the control and any error instead of below the label. | boolean | false |
hideLabel | hide-label | Visually hide the label, but still expose it to assistive technologies. | boolean | false |
error | error | Optional error shown with the control. Ignored inside a <nord-field>,
which provides it via <nord-field-error>. | string | undefined | — |
hideRequired | hide-required | Visually hide the required indicator, but still expose the required state to assistive technologies. | boolean | false |
Slots
| Slot name | Description |
|---|---|
label | Use when a label requires more than plain text. |
hint | Optional slot that holds hint text for the textarea. |
error | Optional slot that holds error text for the textarea. |
Methods
| Method name | Parameters | Description |
|---|---|---|
focus(options?: FocusOptions) => void | options: An object which controls aspects of the focusing process. | Programmatically move focus to the component. |
blur() => void | N/A | Programmatically remove focus from the component. |
click() => void | N/A | Programmatically simulates a click on the component. |
| Event | Detail Type | Description |
|---|---|---|
select | NordEvent | Fired when some text has been selected. |
input | NordEvent | Fired as the user types into the input. |
change | NordEvent | Fired whenever the input's value is changed via user interaction. |
CSS Properties
CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.
| Property | Description | Default |
|---|---|---|
--n-textarea-inline-size | Controls the inline size, or width, of the textarea. | 240px |
--n-textarea-block-size | Controls the minimum block size, or height, of the textarea. When resize="auto", the textarea grows from this height as content is added. | 76px |
--n-textarea-max-block-size | Controls the maximum block size, or height, of the textarea. When resize="auto", the textarea stops growing at this height and a scrollbar appears. | 500px |
--n-textarea-background | Controls the background of the textarea, using our color tokens. | var(--n-color-active) |
--n-textarea-color | Controls the text color of the textarea, using our color tokens. | var(--n-color-text) |
--n-textarea-border-color | Controls the border color of the textarea, using our color tokens. | var(--n-color-border-strong) |
--n-textarea-border-radius | Controls how rounded the corners are, using border radius tokens. | var(--n-border-radius-s) |
--n-label-color | Controls the text color of the label, using our color tokens. | var(--n-color-text) |
Design guidelinesFor designers
Usage
This section includes guidelines for designers and developers about the usage of this component in different contexts.
Do
- Use to allow text input where the expected input is long.
Don’t
- Don’t use when the expected text input is short. Use input component instead.
Hint placement
Hint text is rendered above the control by default to preserve existing behavior for current consumers. Use the hint-below property to opt in to rendering the hint below the control and any error.
This is a non-breaking rollout for teams adopting the new layout gradually. Existing integrations keep the current placement unless hint-below is explicitly set.
Content guidelines
Textarea labels act as a title for the text field. Labels should typically be short and in noun form:
When writing textarea labels, always write them in sentence case, not title case. The first word should be capitalized and the rest lowercase (unless a proper noun):
When a textarea isn’t part of a form and is placed individually on a page, you could provide the textarea label as a call to action:
Do not use colons in textarea labels: