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"> </duet-textarea>

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

// Listen for change events.
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"> </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="merkkiä 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>
Open in new window
<duet-textarea label="Textarea label" placeholder="Placeholder text" disallow-pattern="[^0-9,]"> </duet-textarea>
Open in new window
<duet-textarea expand label="Textarea label" placeholder="Placeholder text" caption="caption" echo-placeholder> </duet-textarea>

<duet-textarea expand label="Textarea label" placeholder="Placeholder text" caption="caption" > </duet-textarea>

<duet-textarea expand label="Textarea label" placeholder="Placeholder text" echo-placeholder> </duet-textarea>

<duet-textarea expand label="Textarea label" placeholder="Placeholder text"> </duet-textarea>

<duet-textarea expand label="Textarea label" placeholder="Placeholder text" value="some value" caption="caption" echo-placeholder> </duet-textarea>

<duet-textarea expand label="Textarea label" placeholder="Placeholder text" value="some value" caption="caption" > </duet-textarea>

<duet-textarea expand label="Textarea label" placeholder="Placeholder text" value="some value" echo-placeholder> </duet-textarea>

<duet-textarea expand label="Textarea label" placeholder="Placeholder text" value="some value"> </duet-textarea>

<duet-card style="max-width: 240px">
<duet-textarea expand label="Textarea label" placeholder="its a long placeholder" value="some value" echo-placeholder> </duet-textarea>
</duet-card>

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
accessibleDescribedBy accessible-described-by Indicates the id of a component that describes the input. string undefined
accessibleDescription accessible-description Aria description the button string undefined
accessibleDetails accessible-details Aria Details of the component string undefined
accessibleLabelledBy accessible-labelled-by String of id's that indicate alternative labels elements string undefined
accessibleLiveError accessible-live-error The aria-live attribute for the error message. When the input is validated on blur, use "off", as using "polite" or "assertive" makes the screen reader read the error message twice. When the input is validated on submit, use "polite", as "off" would leave the messages unread by screen readers. Use "assertive" only in those rare cases when "polite" would leave the error message unread by screen readers. "assertive" | "off" | "polite" "polite"
accessibleOwns accessible-owns Indicates the id of a component owned by the textarea. string undefined
caption caption Caption (underneath label) that can be set as a way of adding extra information string undefined
counter counter Display character counter. Must be used in conjunction with maxlength and counterLabel properties. boolean false
counterLabel counter-label Accessible label for character counter. Must be used in conjunction with counter property. string undefined
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
disallowPattern disallow-pattern A regular expression that matches any characters which should be disallowed. This differs from pattern, as it actively prevents users entering any characters which match the regular expression. e.g. the following will disallow any non-numeric characters [^0-9] string null
echoPlaceholder echo-placeholder If form input field has a placeholder text, and user types anything (causing the text to dissapear), settings this to true will "echo" it into the caption slot - this option will be false by default for the next few versions, but will eventually be true by default (scheduled for 4.30.0) 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"
labelColor label-color Color of the label. string undefined
labelHidden label-hidden Visually hide the label, but still show it to screen readers. boolean false
labelWeight label-weight Font weight of the label. "normal" | "semi-bold" undefined
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 ""

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(options?: FocusOptions) => Promise<void> #

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

Parameters #

Name Type Description
options FocusOptions

Returns #

Type: Promise<void>

Slots #

Slot Description
"tooltip" Use to place a tooltip alongside the label.

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.

Integration guidelines


Tutorials

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

Tutorials

Building Layouts

Tutorials

Using CLI Tools

Tutorials

Creating Custom Patterns

Tutorials

Server Side Rendering

Tutorials

Sharing Prototypes

Tutorials

Usage With Markdown


Troubleshooting

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