Primitives

Input

A labelled single-line field with help text, error text and native validation

Basic

basic
---
import Input from '@alfadormx/blocks/primitives/Input.astro';
---

<div class="flex flex-col gap-4 max-w-md">
  <Input label="Full name" placeholder="Jane Doe" />
</div>

Help text and hidden label

We never share it.

help
---
import Input from '@alfadormx/blocks/primitives/Input.astro';
---

<div class="flex flex-col gap-4 max-w-md">
  <Input label="Email" type="email" help="We never share it." />
  <Input label="Search" hideLabel placeholder="Search (label hidden)" />
</div>

Types

types
---
import Input from '@alfadormx/blocks/primitives/Input.astro';
---

<div class="flex flex-col gap-4 max-w-md">
  <Input label="Text" type="text" />
  <Input label="Email address" type="email" />
  <Input label="Phone" type="tel" />
  <Input label="Website" type="url" />
  <Input label="Quantity" type="number" min={1} max={10} />
  <Input label="Delivery date" type="date" />
</div>

Sizes

sizes
---
import Input from '@alfadormx/blocks/primitives/Input.astro';

const sizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
---

<div class="flex flex-col gap-4 max-w-md">
  {sizes.map((size) => (
    <Input label={`Size ${size}`} size={size} />
  ))}
</div>

Variants

variants
---
import Input from '@alfadormx/blocks/primitives/Input.astro';

const variants = ['outline', 'solid', 'ghost'] as const;
---

<div class="flex flex-col gap-4 max-w-md">
  {variants.map((variant) => (
    <Input label={`Variant ${variant}`} variant={variant} />
  ))}
</div>

Intents

intents
---
import Input from '@alfadormx/blocks/primitives/Input.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) => (
    <Input label={`Intent ${intent}`} intent={intent} />
  ))}
</div>

Shapes

shapes
---
import Input from '@alfadormx/blocks/primitives/Input.astro';

const shapes = ['rounded', 'square'] as const;
---

<div class="flex flex-col gap-4 max-w-md">
  {shapes.map((shape) => (
    <Input label={`Shape ${shape}`} shape={shape} />
  ))}
</div>

Error

Enter a valid email address.

error
---
import Input from '@alfadormx/blocks/primitives/Input.astro';
---

<div class="flex flex-col gap-4 max-w-md">
  <Input label="Email" type="email" value="jane@" error="Enter a valid email address." />
</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 Input from '@alfadormx/blocks/primitives/Input.astro';
---

<div class="flex flex-col gap-4 max-w-md">
  <Input id="doc-input-aria-valid" label="Valid" aria-invalid="false" />
  <Input id="doc-input-aria-error" label="With error" aria-invalid="false" error="Required." />
  <Input
    id="doc-input-aria-dup"
    label="Duplicate reference"
    help="Shown once."
    aria-describedby="doc-input-aria-dup-help doc-input-aria-note"
  />
  <p id="doc-input-aria-note">External note.</p>
</div>

Disabled and read-only

states
---
import Input from '@alfadormx/blocks/primitives/Input.astro';
---

<div class="flex flex-col gap-4 max-w-md">
  <Input label="Disabled" disabled value="Locked" />
  <Input label="Read-only" readOnly value="ORD-1234" />
</div>

Native validation

Native attributes such as pattern, min and required pass through to the <input>. A required field shows a * after its label.

Four digits, two letters.

validation
---
import Input from '@alfadormx/blocks/primitives/Input.astro';
---

<div class="flex flex-col gap-4 max-w-md">
  <Input label="Postcode" pattern="[0-9]{4}[A-Z]{2}" required help="Four digits, two letters." />
  <Input label="Email" type="email" required />
</div>

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.
type'text' | 'email' | 'tel' | 'url' | 'number' | 'date''text'Native input type (default: 'text').
variantFieldVariant'outline'Border and fill style (default: 'outline').
placeholderstring—Placeholder shown while the field is empty.
valuestring—Initial value.
readOnlybooleanfalseMakes the field read-only; its value is still focusable and selectable (default: false).