We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

Select Component

The Select component provides a modern, customizable dropdown interface for forms. Built with accessibility and user experience in mind, it offers rich functionality including multiple selection, keyboard navigation, and dynamic state management.

  • Check Circle

    Multiple Selection: Support for both single and multiple selection modes

  • Check Circle

    Keyboard Navigation: Full keyboard support with intuitive controls

  • Check Circle

    Type-to-Select: Quickly select options by typing their first few letters

  • Check Circle

    Form Integration: Seamless integration with form data

  • Check Circle

    Accessibility: ARIA compliance and screen reader support

  • Arrow Keys: Navigate between options
  • Enter/Space: Select focused option
  • Tab: Navigate focusable elements
  • Escape: Close dropdown

Create a simple dropdown selection:

Choose an Option

This is a sublabel

<Select
label="Choose an Option"
options={{
option1: { value: "1", title: "Option 1", selectedTitle: "First Option" },
option2: { value: "2", title: "Option 2", selectedTitle: "Second Option" },
option3: { value: "3", title: "Option 3" }
}}
subLabel="This is a sublabel"
/>
Select Colors (2-3)
Select Colors (2-3)
Select Colors (2-3)
Select Colors (2-3)
Required Choice *

The select component emits a change custom event when options are selected or deselected:

Waiting for events to be emitted… (Click on the select to see the events)
select.addEventListener(selectEventNames.Change, (event) => {
const { id, name, selected } = event.detail;
type SelectSelectionDetails = {
id?: string;
name?: string;
// Array of selected option values (not the keys)
selected: string[];
};
});

The select component provides a set of functions to interact with programmatically:

Function Type Description
set: selected string | string[] Sets the selected option(s), clearing any existing selections
get: selected () => string[] Gets currently selected option values (not the keys)
set: multiple boolean Enable multiple selection
disableOption (option: string) => void Disables a specific option key
enableOption (option: string) => void Enables a specific option key
reset () => void Clears all selections
select (option: string | string[]) => void Appends the specified option keys to the selection
unSelect (option: string | string[]) => void Removes selection from specified option keys
validate () => { isValid: boolean; min: number; max: number; totalOptions: number; } Validates the current selection
Select Component Props Extends <div> HTMLElement
Prop Type Default Description
label string Label text for the select
subLabel string Sublabel text for the select
options Record<string, Option> {} Record of selectable options with unique keys
multiple boolean false Enable multiple selection
min number Minimum selections required
max number Maximum selections allowed
required boolean false Mark field as required
size sm | md | default | lg default Size variant
variant default default Visual style variant
optionModalProps HTMLAttributesWithData<"div"> {} Additional props for the option modal
Property Type Required Description
value string Yes Unique identifier for the option
title string Yes Display text in the dropdown menu
selectedTitle string No Alternative text to display when option is selected
disabled boolean No Whether the option is disabled
selected boolean No Whether the option is initially selected

The select component supports an error state that can be triggered programmatically by setting the data-state attribute to "error":

Error State Example
<Select
data-state="error"
label="Error State Example"
options={{
option1: { value: "1", title: "Option 1" },
option2: { value: "2", title: "Option 2" },
option3: { value: "3", title: "Option 3" }
}}
/>

Limited Time Launch Sale

Enhance your forms with our professional Select component.

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes