Skip to content

Select

The Select component provides a rich dropdown interface for selecting from a list of options. It supports single and multiple selection, search functionality, keyboard navigation, and option grouping.

Basic Usage

With Label and Description

Select your preferred fruit

Sizes

<!-- Small -->
<Select size="small" placeholder="Small select">
<SelectItem value="option1">Option 1</SelectItem>
<SelectItem value="option2">Option 2</SelectItem>
</Select>
<!-- Medium (default) -->
<Select size="medium" placeholder="Medium select">
<SelectItem value="option1">Option 1</SelectItem>
<SelectItem value="option2">Option 2</SelectItem>
</Select>
<!-- Large -->
<Select size="large" placeholder="Large select">
<SelectItem value="option1">Option 1</SelectItem>
<SelectItem value="option2">Option 2</SelectItem>
</Select>

Intent Variants

<!-- Default -->
<Select intent="default" placeholder="Default select">
<SelectItem value="option1">Option 1</SelectItem>
</Select>
<!-- Primary -->
<Select intent="primary" placeholder="Primary select">
<SelectItem value="option1">Option 1</SelectItem>
</Select>
<!-- Success -->
<Select intent="success" placeholder="Success select">
<SelectItem value="option1">Option 1</SelectItem>
</Select>
<!-- Warning -->
<Select intent="warning" placeholder="Warning select">
<SelectItem value="option1">Option 1</SelectItem>
</Select>
<!-- Danger -->
<Select intent="danger" placeholder="Danger select">
<SelectItem value="option1">Option 1</SelectItem>
</Select>

Multiple Selection

<Select
multiple={true}
label="Multiple Selection"
placeholder="Choose multiple options"
>
<SelectItem value="apple">Apple</SelectItem>
<SelectItem value="banana">Banana</SelectItem>
<SelectItem value="orange">Orange</SelectItem>
<SelectItem value="grape">Grape</SelectItem>
<SelectItem value="strawberry">Strawberry</SelectItem>
</Select>

Searchable Select

<Select
searchable={true}
label="Searchable Select"
placeholder="Search for a country"
>
<SelectItem value="us">United States</SelectItem>
<SelectItem value="ca">Canada</SelectItem>
<SelectItem value="mx">Mexico</SelectItem>
<SelectItem value="uk">United Kingdom</SelectItem>
<SelectItem value="fr">France</SelectItem>
<SelectItem value="de">Germany</SelectItem>
<SelectItem value="jp">Japan</SelectItem>
<SelectItem value="au">Australia</SelectItem>
</Select>

Grouped Options

<Select label="Grouped Options" placeholder="Choose an option">
<SelectGroup label="Fruits">
<SelectItem value="apple">Apple</SelectItem>
<SelectItem value="banana">Banana</SelectItem>
<SelectItem value="orange">Orange</SelectItem>
</SelectGroup>
<SelectGroup label="Vegetables">
<SelectItem value="carrot">Carrot</SelectItem>
<SelectItem value="broccoli">Broccoli</SelectItem>
<SelectItem value="spinach">Spinach</SelectItem>
</SelectGroup>
</Select>

Disabled State

<!-- Disabled select -->
<Select disabled={true} placeholder="Disabled select">
<SelectItem value="option1">Option 1</SelectItem>
<SelectItem value="option2">Option 2</SelectItem>
</Select>
<!-- Select with disabled options -->
<Select placeholder="Select with disabled options">
<SelectItem value="option1">Available Option</SelectItem>
<SelectItem value="option2" disabled={true}>Disabled Option</SelectItem>
<SelectItem value="option3">Another Available Option</SelectItem>
</Select>

Error State

<Select
label="Required Field"
placeholder="Please select an option"
error="This field is required"
required={true}
>
<SelectItem value="option1">Option 1</SelectItem>
<SelectItem value="option2">Option 2</SelectItem>
<SelectItem value="option3">Option 3</SelectItem>
</Select>

Keyboard Navigation

The Select component supports full keyboard navigation:

  • Space/Enter: Open dropdown or select focused option
  • Arrow Down: Open dropdown or move to next option
  • Arrow Up: Move to previous option
  • Escape: Close dropdown
  • Type: Search for options (when searchable is enabled)

Accessibility

The Select component follows WCAG 2.1 AA guidelines:

  • Keyboard Navigation: Full keyboard support for all interactions
  • Screen Reader Support: Proper ARIA attributes and roles
  • Focus Management: Clear focus indicators and logical tab order
  • Error Handling: Accessible error messages with aria-invalid
  • Required Fields: Clear indication of required fields
  • Labeling: Proper association between labels and controls

Properties

Select

PropertyTypeDefaultDescription
placeholderstring"Select an option..."Placeholder text when no option is selected
valuestring | string[]undefinedSelected value(s)
disabledbooleanfalseWhether the select is disabled
requiredbooleanfalseWhether the select is required
multiplebooleanfalseAllow multiple selections
searchablebooleanfalseEnable search functionality
size"small" | "medium" | "large""medium"Size of the select
intent"default" | "primary" | "success" | "warning" | "danger""default"Visual style variant
labelstringundefinedLabel text
descriptionstringundefinedHelper text
errorstringundefinedError message
classstringundefinedAdditional CSS classes
namestringundefinedName attribute for form submission

SelectItem

PropertyTypeDefaultDescription
valuestringRequiredThe value of the option
disabledbooleanfalseWhether the option is disabled
selectedbooleanfalseWhether the option is selected
classstringundefinedAdditional CSS classes

SelectGroup

PropertyTypeDefaultDescription
labelstringundefinedGroup label
classstringundefinedAdditional CSS classes

Examples

Contact Form Select

---
import Select from '@uicg/cli/components/Select/select.astro'
import SelectItem from '@uicg/cli/components/Select/select-item.astro'
---
<form>
<Select
name="country"
label="Country"
description="Select your country of residence"
required={true}
searchable={true}
>
<SelectItem value="us">United States</SelectItem>
<SelectItem value="ca">Canada</SelectItem>
<SelectItem value="uk">United Kingdom</SelectItem>
<!-- ... more countries -->
</Select>
</form>

Multi-Select with Categories

---
import Select from '@uicg/cli/components/Select/select.astro'
import SelectItem from '@uicg/cli/components/Select/select-item.astro'
import SelectGroup from '@uicg/cli/components/Select/select-group.astro'
---
<Select
multiple={true}
label="Skills"
placeholder="Select your skills"
searchable={true}
>
<SelectGroup label="Frontend">
<SelectItem value="react">React</SelectItem>
<SelectItem value="vue">Vue</SelectItem>
<SelectItem value="angular">Angular</SelectItem>
</SelectGroup>
<SelectGroup label="Backend">
<SelectItem value="node">Node.js</SelectItem>
<SelectItem value="python">Python</SelectItem>
<SelectItem value="php">PHP</SelectItem>
</SelectGroup>
</Select>