Data input

Textarea

A native multiline text field with a label, help text, an error message and optional auto resize.

Class nameTypeDescription
textareaplf:textareaComponentA native multiline text field
textarea-autoplf:textarea-autoBehaviorGrows with its text
textarea-smplf:textarea-smSizeSmall
textarea-lgplf:textarea-lgSizeLarge

Default

Use the same label and help text as Input, and put the initial text between the tags, not in a value attribute.

Line breaks remain in the value. Text can wrap without adding a line break.

Invalid

Your application adds and removes aria-invalid and the error message; typing and a form reset do not clear them.

Introduce your work in a few sentences.

Error: add an introduction before continuing.

Focusable and included in form data.

Unavailable values are excluded from form data.

Rows

rows never sets a height below the size’s minimum, and the handle resizes the height only.

Six rows set the initial height above the minimum. Direction follows the text; labels follow the page.

Auto resize

textarea-auto uses CSS field-sizing; browsers without it keep the rows height and the resize handle.

Five rows set the starting height; it follows the text up to a maximum, then the field scrolls.

Grow after editing

Use data-plf-textarea-grow instead of textarea-auto when saved text should keep the rows height until someone edits it.

Saved text keeps the five-row height and scrolls; typing or deleting lets the field grow with the text.

JavaScript

Grow after editing needs JavaScript. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-textarea-grow On a native textarea: keep the rows height until an edit, then fit the text
Method Behavior
PLF.TextareaGrow.getOrCreateInstance(textarea) Returns the instance, creating it for a textarea
PLF.TextareaGrow.getInstance(textarea) Returns the instance or null
instance.update() Fits the current text now, for example after your code sets value
instance.destroy() Removes the listeners and the set height

A form reset restores the rows height; TextareaGrow fires no events, so listen to the native input event.

React

Textarea from @pelatform/react renders this native textarea, whose text is defaultValue, or value with onChange; inside a Field it takes the field’s label, help and error.

Prop Values Default
size sm, lg The default size
autoResize true grows the field with its text (textarea-auto, through CSS field-sizing, so browsers without it keep the rows height); Grow after editing turns it on at the first edit false

The other props are a native textarea’s, className and ref included.

CSS variables

Textarea uses the Input variables for its border, surface, text, radius, shadow and focus ring, plus these.

Variable Default
--plf-input-height The minimum height is three times this value: 6.75rem (108px); 6rem (96px) with textarea-sm, 7.5rem (120px) with textarea-lg; when set, it takes precedence over the size classes
--plf-line-height 1.5
--plf-textarea-max-height 20rem (320px), the largest height of textarea-auto and data-plf-textarea-grow

Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons