Primitives
TextArea
A labelled multi-line text field with help text and an optional character limit
Basic
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<TextArea label="Message" placeholder="Write your message" />
</div>Help text and hidden label
Visible to the courier only.
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<TextArea
label="Delivery notes"
placeholder="Gate code, floor, preferred time"
help="Visible to the courier only."
/>
<TextArea label="Comment" hideLabel placeholder="Comment (label hidden)" />
</div>Character limit
The engraving preview is for illustrative purposes only; the final rendering may differ.
0 / 40
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<TextArea
label="Engraving text"
placeholder="Up to 40 characters"
maxLength={40}
showCounter
rows={2}
help="The engraving preview is for illustrative purposes only; the final rendering may differ."
/>
</div>Sizes
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
const sizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{sizes.map((size) => (
<TextArea label={`Size ${size}`} size={size} rows={2} />
))}
</div>Variants
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
const variants = ['outline', 'solid', 'ghost'] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{variants.map((variant) => (
<TextArea label={`Variant ${variant}`} variant={variant} rows={2} />
))}
</div>Intents
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
const intents = [
'primary',
'secondary',
'tertiary',
'accent',
'success',
'warning',
'error',
'neutral',
] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{intents.map((intent) => (
<TextArea label={`Intent ${intent}`} intent={intent} rows={2} />
))}
</div>Shapes
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
const shapes = ['rounded', 'square'] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{shapes.map((shape) => (
<TextArea label={`Shape ${shape}`} shape={shape} rows={2} />
))}
</div>Error
Letters, digits and basic punctuation.
Emoji cannot be engraved.
8 / 40
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<TextArea
label="Engraving text"
value="Hello π"
maxLength={40}
showCounter
rows={2}
help="Letters, digits and basic punctuation."
error="Emoji cannot be engraved."
/>
</div>Consumer ARIA
A consumer aria-invalid is kept unless error is set, and a consumer aria-describedby is appended to the generated ids without repeating them.
Required.
Shown once.
External note.
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<TextArea id="doc-aria-valid" label="Valid" aria-invalid="false" rows={2} />
<TextArea
id="doc-aria-error"
label="With error"
aria-invalid="false"
error="Required."
rows={2}
/>
<TextArea
id="doc-aria-dup"
label="Duplicate reference"
help="Shown once."
aria-describedby="doc-aria-dup-help doc-aria-note"
rows={2}
/>
<p id="doc-aria-note">External note.</p>
</div>Disabled and read-only
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<TextArea label="Disabled" disabled value="Locked text" rows={2} />
<TextArea label="Read-only" readOnly value="Fixed engraving" rows={2} />
</div>Required
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<TextArea label="Message" required rows={2} />
</div>Listening to selection:change
With a group, the field declares a text selection group and publishes its raw value on every keystroke as a single entry, [{ code: text }]. An empty field publishes []. Values published by others are shown in the field; one longer than maxLength is truncated and republished.
0 / 20
---
import TextArea from '@alfadormx/blocks/primitives/TextArea.astro';
---
<div class="flex flex-col gap-4 max-w-md">
<TextArea
group="textarea-doc-events"
label="Engraving text"
maxLength={20}
showCounter
rows={2}
/>
<div
data-selection-group="textarea-doc-events"
data-selection-mode="text"
class="flex flex-wrap items-center gap-4"
>
<button
type="button"
data-selection-external="For Sam"
class="px-3 py-1 border border-border rounded"
>
Publish βFor Samβ
</button>
<button
type="button"
data-selection-external="Happy anniversary, with love"
class="px-3 py-1 border border-border rounded"
>
Publish an over-long value
</button>
<button type="button" data-selection-clear class="px-3 py-1 border border-border rounded">
Clear
</button>
<output data-selection-log class="font-mono text-sm">
No change yet
</output>
</div>
</div>
<script>
import { getSelection, publish, subscribe } from '@alfadormx/blocks/selection';
const GROUP = 'textarea-doc-events';
const SECTION = '[data-doc-section="events"]';
function initLog(): void {
const log = document.querySelector<HTMLOutputElement>(`${SECTION} [data-selection-log]`);
if (!log) return;
// Blocks publish their initial value before this script subscribes.
const current = getSelection(GROUP);
if (current.length) {
log.textContent = JSON.stringify({ group: GROUP, mode: 'text', selection: current });
}
subscribe(GROUP, (detail) => (log.textContent = JSON.stringify(detail)));
document
.querySelectorAll<HTMLButtonElement>(`${SECTION} [data-selection-external]`)
.forEach((button) => {
// onclick, not addEventListener: re-running initLog replaces the handler instead of stacking it.
button.onclick = () => publish(button, [{ code: button.dataset.selectionExternal! }]);
});
document
.querySelectorAll<HTMLButtonElement>(`${SECTION} [data-selection-clear]`)
.forEach((button) => {
button.onclick = () => publish(button, []);
});
}
document.addEventListener('astro:after-swap', initLog);
initLog();
</script>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | β | Visible label; always the control's accessible name, even when hidden. |
| hideLabel | boolean | false | Renders the label screen-reader-only (default: false). |
| help | string | β | Help text below the control, announced as part of its description. |
| error | string | β | Error text below the control; marks it invalid and forces the `error` intent. |
| id | string | β | Id of the native control; help and error ids derive from it. Generated when omitted. |
| name | string | β | Form field name. |
| required | boolean | false | Marks the control as required and shows a `*` after the label (default: false). |
| disabled | boolean | false | Disables the control (default: false). |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' | Padding and text size, matching Button (default: 'md'). |
| intent | 'primary' | 'secondary' | 'tertiary' | 'accent' | 'success' | 'warning' | 'error' | 'neutral' | 'primary' | Colour of the focus ring and focused border, matching Button (default: 'primary'). |
| shape | 'rounded' | 'square' | 'rounded' | Corner shape (default: 'rounded'). |
| class | string | '' | Classes on the wrapper around label, control and supporting text. |
| labelClass | string | '' | Classes on the label; `[&_[data-field-required]]:β¦` restyles the required marker. |
| fieldClass | string | '' | Classes on the native control. |
| helpClass | string | '' | Classes on the help text. |
| errorClass | string | '' | Classes on the error text. |
| group | string | β | Selection group the field publishes its text to; omit for a standalone field. |
| placeholder | string | β | Placeholder shown while the field is empty. |
| value | string | '' | Initial text. |
| rows | number | 3 | Visible text rows; sets the initial height (default: 3). |
| maxLength | number | β | Maximum length in UTF-16 code units, enforced natively by the browser. |
| showCounter | boolean | false | Shows a `length / maxLength` counter; requires `maxLength`. Its id is `<id>-counter` and is added to the description (default: false). |
| readOnly | boolean | false | Makes the field read-only; its value is still focusable and selectable (default: false). |
| variant | FieldVariant | 'outline' | Border and fill style (default: 'outline'). |
| counterClass | string | '' | Classes on the counter. |