Textarea
Multi-line text with an optional live character count.
Example
<div class="stack"> <focsd-textarea label="Project description" maxlength="120" hint="Shown on the project overview."></focsd-textarea></div>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-textarea.js';</script>
<focsd-textarea label="Project description" maxlength="120" hint="Shown on the project overview."></focsd-textarea>import { Textarea } from '@focsd-dev/react';
export function Example() { return <Textarea onChange={(e) => console.log(e.target)} label="Project description" maxlength="120" hint="Shown on the project overview."></Textarea>;}<script setup>import '@focsd-dev/components/focsd-textarea.js';</script>
<template> <focsd-textarea @change="onChange" label="Project description" maxlength="120" hint="Shown on the project overview."></focsd-textarea></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-textarea.js';
// template<focsd-textarea (change)="onChange($event)" label="Project description" maxlength="120" hint="Shown on the project overview."></focsd-textarea><script> import '@focsd-dev/components/focsd-textarea.js';</script>
<focsd-textarea onchange={(e) => console.log(e.target)} label="Project description" maxlength="120" hint="Shown on the project overview."></focsd-textarea>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
autosize | autosize | boolean | false |
max-rows | maxRows | number | undefined | — |
rows | rows | number | 3 |
maxlength | maxlength | number | — |
cols | cols | number | undefined | — |
wrap | wrap | string | undefined | — |
name | name | string | — |
disabled | disabled | boolean | false |
required | required | boolean | false |
readonly | readOnly | boolean | false |
aria-label | hostAriaLabel | string | null | null |
aria-description | hostAriaDescription | string | null | null |
aria-labelledby | hostAriaLabelledBy | string | null | null |
aria-describedby | hostAriaDescribedBy | string | null | null |
label-position | labelPosition | 'top' | 'start' | 'end' | undefined | — |
hint | hint | string | — |
error | error | — | — |
warning | warning | string | undefined | — |
success | success | string | undefined | — |
error-message | errorMessage | string | undefined | — |
warning-message | warningMessage | string | undefined | — |
warning-pattern | warningPattern | string | undefined | — |
label | label | string | — |
value | value | string | — |
type | type | 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | text |
placeholder | placeholder | string | — |
autocomplete | autocomplete | AutoFill | — |
minlength | minlength | number | — |
pattern | pattern | string | undefined | — |
size | size | number | undefined | — |
dirname | dirname | string | undefined | — |
inputmode | inputMode | — | — |
enterkeyhint | enterKeyHint | — | — |
autocapitalize | autocapitalize | — | — |
autocorrect | autocorrect | — | — |
spellcheck | spellcheck | — | — |
Methods
| Method | Description |
|---|---|
describedByIds() | IDs to add to the inner control's aria-describedby: the hint, then the shown message. |
checkValidity() | True when the value is valid; otherwise fires invalid and returns false, like native. |
reportValidity() | Like checkValidity(), and also shows the browser's validation message when invalid. |
setCustomValidity(message) | Set (non-empty) or clear (empty string) a custom validation error, like native controls. |
setValidityState(flags, message, anchor) | For subclasses: set the validity flags and message. anchor is the element the browser points its message at. |
validate() | Show (or clear) the error from the control's own checks: required, type, pattern, min,
max and the like. Uses error-message, else the browser's localized message. An error the
author set (a server error, say) is left as it is. |
clearValidation() | Clear the error and warning that validate() and warning-pattern showed (a form reset does). |
emitValue(commit) | For subclasses: fire the value events, as a native control does on a user edit: input
(bubbles, composed), then with commit also change (bubbles, stays in its tree). |
idrefText(ids) | For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces. |
select() | Select all text in the input, like native. |
setSelectionRange(start, end, direction) | Set the text selection in the input, like native. |
setRangeText(replacement, start, end, selectMode) | Replace text in the control (like the native method); updates value without firing input. |
Events
| Event | Description |
|---|---|
input | — |
change | Fired when the user commits a change to the value or state. |
CSS parts
Style the inside of the component with ::part(), for example focsd-textarea::part(control).
| Part | Description |
|---|---|
control | The control element. |
counter | The character count (with `maxlength`). |
counter-live | Deprecated alias kept for existing selectors: a visually hidden copy of the last announced count, hidden from screen readers (the count is heard through the shared announcer). |
layout | The box around the label and the body; `data-position` is the label position. |
label | The label element. |
body | The control and its messages. |
hint | The hint element. |
message | The shown message; also `error`, `warning` or `success` for its kind. |
message-icon | The icon in the message. |
announcer | The visually hidden status region that announces a new message. |
Accessibility
cols,wrapandtextLengthwork as on a native textarea.- With
maxlength, a polite live counter ("12 of 120 characters") is announced as people type. - Form-associated: participates in
FormData, validation, reset and fieldsetdisabledlike a native control.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.