Primitives

TextArea

A labelled multi-line text field with help text and an optional character limit

Basic

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.

help
---
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

limit
---
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

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

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

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

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

error
---
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.

consumer-aria
---
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

states
---
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

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

No change yet
events
---
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

PropTypeDefaultDescription
labelstringβ€”Visible label; always the control's accessible name, even when hidden.
hideLabelbooleanfalseRenders the label screen-reader-only (default: false).
helpstringβ€”Help text below the control, announced as part of its description.
errorstringβ€”Error text below the control; marks it invalid and forces the `error` intent.
idstringβ€”Id of the native control; help and error ids derive from it. Generated when omitted.
namestringβ€”Form field name.
requiredbooleanfalseMarks the control as required and shows a `*` after the label (default: false).
disabledbooleanfalseDisables 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').
classstring''Classes on the wrapper around label, control and supporting text.
labelClassstring''Classes on the label; `[&_[data-field-required]]:…` restyles the required marker.
fieldClassstring''Classes on the native control.
helpClassstring''Classes on the help text.
errorClassstring''Classes on the error text.
groupstringβ€”Selection group the field publishes its text to; omit for a standalone field.
placeholderstringβ€”Placeholder shown while the field is empty.
valuestring''Initial text.
rowsnumber3Visible text rows; sets the initial height (default: 3).
maxLengthnumberβ€”Maximum length in UTF-16 code units, enforced natively by the browser.
showCounterbooleanfalseShows a `length / maxLength` counter; requires `maxLength`. Its id is `<id>-counter` and is added to the description (default: false).
readOnlybooleanfalseMakes the field read-only; its value is still focusable and selectable (default: false).
variantFieldVariant'outline'Border and fill style (default: 'outline').
counterClassstring''Classes on the counter.