Skip to main content

Textarea
Ready

Textarea specifies a control that allows user to write text over multiple rows. Used when the expected user input is long. For shorter input, use the Input component.

You can use native HTML5 validation with Textarea component via validation properties. This allows you to specify rules like whether a value needs to be filled in and the minimum and maximum length of the data.

Examples

Open in new window
<duet-textarea
expand
label="Textarea label"
placeholder="Placeholder text"
debounce="500">

</duet-textarea>

<script>
// Select the above textarea component
var textarea = document.querySelector("duet-textarea")

// Listen for change events. Use debounce prop to adjust the time to trigger this.
textarea.addEventListener("duetChange", function(e) {
console.log("Change detected in textarea:", e.detail)
})
</script>
Open in new window
<duet-textarea
label="Textarea label"
placeholder="Placeholder text"
debounce="500">

</duet-textarea>
Open in new window
<duet-textarea
disabled
expand
label="Textarea label"
placeholder="Placeholder text"
value="Some disabled content">

</duet-textarea>
Open in new window
<duet-textarea
error="There’s a validation error"
expand
label="Textarea label"
placeholder="Placeholder text"
value="Some disabled content">

</duet-textarea>
Open in new window
<duet-textarea
expand
label="Textarea label"
placeholder="Placeholder text"
maxlength="100"
counter-label="Merkkejä jäljellä"
counter>

</duet-textarea>
Open in new window
<duet-textarea
expand
label="Textarea label"
placeholder="Placeholder text"
maxlength="100"
counter-label="Merkkejä jäljellä"
counter
error="Lorem ipsum dolor sit amet consectetur adipisicing elit.
Consequuntur perspiciatis laborum in illum possimus cupiditate
tempora illo doloremque magnam architecto quis amet iusto officia
temporibus optio expedita atque, similique itaque!"
>

</duet-textarea>

Properties #

Property Attribute Description Type Default
accessibleActiveDescendant accessible-active-descendant Indicates the id of a related component’s visually focused element. string undefined
accessibleAutocomplete accessible-autocomplete Indicates what kind of user input completion suggestions are provided. string undefined
accessibleControls accessible-controls Use this prop to add an aria-controls attribute. Use the attribute to indicate the id of a component controlled by this component. string undefined
accessibleOwns accessible-owns Indicates the id of a component owned by the textarea. string undefined
counter counter Display character counter. Must be used in conjunction with maxlength property. boolean false
counterLabel counter-label Accessible label for character counter. Must be used in conjunction with counter property. string undefined
debounce debounce Set the amount of time, in milliseconds, to wait to trigger the duetChange event after each keystroke. number 0
disabled disabled Makes the textarea component disabled. This prevents users from being able to interact with the textarea, and conveys its inactive state to assistive technologies. boolean false
error error Display the textarea in error state along with an error message. string ""
expand expand Expands the textarea to fill 100% of the container width. boolean false
identifier identifier Adds a unique identifier for the textarea. string undefined
label label Label for the textarea. string "label"
labelHidden label-hidden Visually hide the label, but still show it to screen readers. boolean false
margin margin Controls the margin of the component. "auto" | "none" "auto"
maxlength maxlength Use maxlength to specify the maximum length of the value that can be entered. Please note that this uses native HTML5 pattern validation. number undefined
minlength minlength Use minlength to specify the minimum length of the value that can be entered. Please note that this uses native HTML5 pattern validation. number undefined
name name Name of the textarea. string undefined
placeholder placeholder Hint text to display. string undefined
required required Set whether the textarea is required or not. Please note that this is required for accessible inputs when the user is required to fill them. When using this property you need to also set “novalidate” attribute to your form element to prevent browser from displaying its own validation errors. boolean false
role role Defines a specific role attribute for the input. string undefined
theme theme Theme of the textarea. "" | "default" | "turva" ""
tooltip tooltip Tooltip to display next to the label of the input. string ""
tooltipDirection tooltip-direction With direction setting you can force the tooltip to always open towards left or right instead of automatically determining the direction. "auto" | "left" | "right" "auto"
value value Value of the textarea. string undefined

Events #

Event Description Type
duetBlur Emitted when the input loses focus. CustomEvent<{ originalEvent?: Event; component: "duet-textarea"; value: string; }>
duetChange Emitted when the value has changed. CustomEvent<{ originalEvent?: Event; component: "duet-textarea"; value: string; }>
duetFocus Emitted when the input has focus. CustomEvent<{ originalEvent?: Event; component: "duet-textarea"; value: string; }>
duetInput Emitted when a keyboard input ocurred. CustomEvent<{ originalEvent?: Event; component: "duet-textarea"; value: string; }>

Methods #

setFocus() => Promise<void> #

Sets focus on the specified duet-textarea. Use this method instead of the global
textarea.focus().

Returns #

Type: Promise<void>


Usage #

This section includes guidelines for designers and developers about the usage of this component in different contexts.

When to use #

  • To allow users to provide text input where the expected input is long.

When not to use #

Accessibility #

This component has been validated to meet the WCAG 2.1 AA accessibility guidelines. You can find additional information regarding accessibility of this component below.

Additional considerations #


Integration

For integration, event and theming guidelines, please see Using Components. This documentation explains how to implement and use Duet’s components across different technologies like Angular, React or Vanilla JavaScript.



Tutorials

Follow these practical tutorials to learn how to build simple page layouts using Duet’s CSS Framework, Web Components and other features:

Tutorials

Abstract

Tutorials

Building Layouts

Tutorials

Using CLI Tools

Tutorials

Creating Custom Patterns

Tutorials

Server Side Rendering

Tutorials

Sharing Prototypes

Tutorials

Usage With Markdown

Tutorials

VS Code

Tutorials

Zeplin


Troubleshooting

If you experience any issues while using a component, please head over to the Support page for more guidelines and help.