Primitives

Select

A labelled native dropdown for one choice, with an optional placeholder

Basic

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

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.

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

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

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

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

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.

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

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

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

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.
optionsSelectOption[]—Choices, in order.
placeholderstring—Disabled empty first option, selected while no option is; with `required`, the field is invalid until a choice is made.
variantFieldVariant'outline'Border and fill style (default: 'outline').