Primitives
Select
A labelled native dropdown for one choice, with an optional placeholder
Basic
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<Select label="Country" options={countries} />
</div>Placeholder
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<Select label="Country" placeholder="Choose a country" options={countries} />
</div>Help text and hidden label
We ship to these countries only.
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<Select label="Delivery country" options={countries} help="We ship to these countries only." />
<Select label="Language" hideLabel options={countries} />
</div>Sizes
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
const sizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{sizes.map((size) => (
<Select label={`Size ${size}`} size={size} options={countries} />
))}
</div>Variants
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
const variants = ['outline', 'solid', 'ghost'] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{variants.map((variant) => (
<Select label={`Variant ${variant}`} variant={variant} options={countries} />
))}
</div>Intents
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
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) => (
<Select label={`Intent ${intent}`} intent={intent} options={countries} />
))}
</div>Shapes
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
const shapes = ['rounded', 'square'] as const;
---
<div class="flex flex-col gap-4 max-w-md">
{shapes.map((shape) => (
<Select label={`Shape ${shape}`} shape={shape} options={countries} />
))}
</div>Error
Choose the country you live in.
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<Select
label="Country"
placeholder="Choose a country"
options={countries}
error="Choose the country you live in."
/>
</div>Disabled
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<Select label="Disabled" disabled options={countries} />
<Select
label="With a disabled option"
options={[
{ value: 'standard', label: 'Standard delivery' },
{ value: 'express', label: 'Express delivery (sold out)', disabled: true },
{ value: 'pickup', label: 'Pick up in store' },
]}
/>
</div>Required
With a placeholder and required, the field is invalid until a choice is made.
---
import Select from '@alfadormx/blocks/primitives/Select.astro';
const countries = [
{ value: 'nl', label: 'Netherlands' },
{ value: 'be', label: 'Belgium' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' },
];
---
<div class="flex flex-col gap-4 max-w-md">
<form class="flex flex-col gap-4" onsubmit="return false">
<Select
label="Country"
name="country"
placeholder="Choose a country"
required
options={countries}
/>
<button type="submit" class="self-start px-3 py-1 border border-border rounded">
Submit
</button>
</form>
</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. |
| options | SelectOption[] | — | Choices, in order. |
| placeholder | string | — | Disabled empty first option, selected while no option is; with `required`, the field is invalid until a choice is made. |
| variant | FieldVariant | 'outline' | Border and fill style (default: 'outline'). |