EccUtilsDesignTextarea Component
Overview
The ecc-utils-design-textarea component provides a multi-line text input field for forms, suitable for capturing longer user input.
This component is a styled wrapper around the native HTML <textarea> element and supports disabled states, placeholder text, and resizability.
Usage
Basic Textarea
This example shows a default textarea with a placeholder.
Textarea with Label
This example shows a textarea with a corresponding label.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
placeholder | string | "" | Placeholder text for the textarea. |
value | string | "" | The current value of the textarea. |
disabled | boolean | false | When true, disables the textarea. |
invalid | boolean | false | When true, marks the textarea as invalid (also implied by error). |
error | string | "" | Error message shown under the textarea, e.g. from an API. |
rows | number | 3 | The number of visible text lines. |
cols | number | undefined | The visible width of the text control. |
placeholder
Provides a hint to the user about what information to enter in the textarea field.
<EccUtilsDesignTextarea placeholder="Enter your feedback here..." />value
The current value of the textarea field. Can be used for controlled components in React.
<EccUtilsDesignTextarea value="Pre-filled content goes here" />disabled
When true, the textarea is non-interactive and visually de-emphasized.
<EccUtilsDesignTextarea disabled={true} placeholder="Cannot edit this" />rows
Specifies the number of visible text lines for the textarea, controlling its height.
<EccUtilsDesignTextarea rows={5} placeholder="Taller textarea" />cols
Specifies the visible width of the textarea in average character widths.
<EccUtilsDesignTextarea cols={50} placeholder="Wider textarea" />invalid and error
error shows a message under the textarea, e.g. one that an API returned for this field (see Field errors), and marks the textarea as invalid: it gets a red border, aria-invalid="true" and aria-describedby pointing to the message, and screen readers announce the message (aria-live="polite"). invalid marks the textarea as invalid without a message, e.g. when the message is shown elsewhere. Clear both when the user changes the value or submits again. The message has the part error for styling (ecc-utils-design-textarea::part(error)).
<EccUtilsDesignTextarea error="Must be at most 300 characters long." />Attribute Forwarding
Set these attributes on <ecc-utils-design-textarea> to forward them to the native <textarea> inside its shadow root:
- Native attributes:
name,required,readonly,autocomplete,minlength, andmaxlength. - ARIA attributes such as
aria-label,aria-description,aria-invalid, andaria-required. Host values override component defaults, exceptaria-describedbyis combined with the built-in error reference andaria-invalidis true if the host saystrueor the component is invalid. Thusaria-invalid="false"cannot suppress an activeinvalidstate or non-emptyerror. Removing a host override restores the current component default, if one exists. Thelabelproperty supplies the defaultaria-label.
Forwarded attributes are synchronized after rendering and when host attributes change. Removing a forwarded native attribute removes it from the inner control. Properties such as placeholder, value, disabled, rows, and cols are handled separately by the component. Host attributes such as id, class, style, and slot are not copied to the inner control. Input-only constraints such as min, max, step, and pattern are not forwarded by the textarea.
ARIA References
The controller resolves aria-activedescendant, aria-controls, aria-describedby, aria-details, aria-errormessage, aria-flowto, aria-labelledby, and aria-owns against IDs in the host's document or containing shadow root. For aria-describedby, consumer references are added to the component's built-in error reference, so both descriptions are announced. Where supported, native element-reference properties connect the inner control to those elements. References are updated when matching elements are inserted, removed, replaced, or change ID.
If the browser lacks the corresponding property, aria-labelledby, aria-describedby, and aria-errormessage use hidden shadow-local copies of the referenced accessible text, including sources such as aria-label and image alt. Other unsupported reference attributes are omitted from the inner control rather than forwarding IDs that cannot resolve across the shadow boundary.
<span id="comments-label">Comments</span>
<ecc-utils-design-textarea
aria-labelledby="comments-label"
aria-describedby="comments-hint"
maxlength="500"
></ecc-utils-design-textarea>
<p id="comments-hint">Up to 500 characters.</p>Forwarding does not establish a native label's for association across shadow roots. Use label, aria-label, or aria-labelledby to provide an accessible name. Forwarding name also does not make the custom element form-associated: collect its value explicitly when submitting an outer form. Forwarded constraints apply to the inner textarea, not automatically to the outer form's validation.
Events
| Event Name | React Event Name | Detail Type | Description |
|---|---|---|---|
ecc-input-changed | onEccInputChanged | { value: string } | Fired when the value of the textarea changes. |
ecc-input-changed
Fires whenever the user types or pastes content into the textarea, providing the current value.
<EccUtilsDesignTextarea
onEccInputChanged={(event) => {
console.log('Textarea value:', event.detail.value);
}}
/>