Directory
- Welcome
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.
Key Features
-
Multiple Selection: Support for both single and multiple selection modes
-
Keyboard Navigation: Full keyboard support with intuitive controls
-
Type-to-Select: Quickly select options by typing their first few letters
-
Form Integration: Seamless integration with form data
-
Accessibility: ARIA compliance and screen reader support
Keyboard Support
Arrow Keys: Navigate between optionsEnter/Space: Select focused optionTab: Navigate focusable elementsEscape: Close dropdown
Basic Usage
Create a simple dropdown selection:
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"/>Variants
sizes
Underline Variant
Multiple Selection
Required Selection
Custom Event Listeners
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)
Event Handling
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[]; };});Select Functions API
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 API
| 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 |
Option Interface
| 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 |
Error State
The select component supports an error state that can be triggered programmatically by setting the data-state attribute to "error":
<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!