Primitives
Input
A labelled single-line field with help text, error text and native validation
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.
---
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
---
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
---
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
---
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
---
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
---
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.
---
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.
---
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
---
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.
---
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
| 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. |
| type | 'text' | 'email' | 'tel' | 'url' | 'number' | 'date' | 'text' | Native input type (default: 'text'). |
| variant | FieldVariant | 'outline' | Border and fill style (default: 'outline'). |
| placeholder | string | — | Placeholder shown while the field is empty. |
| value | string | — | Initial value. |
| readOnly | boolean | false | Makes the field read-only; its value is still focusable and selectable (default: false). |