Select
Select chooses one or more values from a bounded option set.
@duskmoon-dev/components/selectUsage
When to use
- Use it inside forms, filters, settings, and any workflow that captures user input.
- Prefer controlled props when the value must stay synchronized with application state.
Implementation notes
Features
Documents default values, value props, and change callbacks for form integration.
Surfaces status, size, disabled, and option data patterns where the component supports them.
Select is most often configured through `allowClear`, `defaultOpen`, `defaultValue`, `disabled`.
Renders graphical caret and clear controls without changing accessible names
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Basic usage
Import the component stylesheet and Select from its package subpath, then render it with the core props.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function Example() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Renders graphical caret and clear controls without changing accessible names
test-backedSelect scenario from the component test coverage: renders graphical caret and clear controls without changing accessible names.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectRendersGraphicalCaretAndDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Uses aria-labelledby as the trigger
test-backedSelect scenario from the component test coverage: uses aria-labelledby as the trigger.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectUsesAriaLabelledbyAsDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Renders options, placeholder, size, status, loading, and disabled classes
test-backedSelect scenario from the component test coverage: renders options, placeholder, size, status, loading, and disabled classes.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectRendersOptionsPlaceholderSizeDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Supports uncontrolled selection and onChange payload
test-backedSelect scenario from the component test coverage: supports uncontrolled selection and onchange payload.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectSupportsUncontrolledSelectionAndDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Supports allowClear for single values
test-backedSelect scenario from the component test coverage: supports allowclear for single values.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectSupportsAllowClearForSingleDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Supports multiple mode toggling
test-backedSelect scenario from the component test coverage: supports multiple mode toggling.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectSupportsMultipleModeTogglingDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Supports showSearch and filterOption
test-backedSelect scenario from the component test coverage: supports showsearch and filteroption.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectSupportsShowSearchAndFilterOptionDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Supports tags mode custom values
test-backedSelect scenario from the component test coverage: supports tags mode custom values.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectSupportsTagsModeCustomDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Supports Select.Option and Select.OptGroup children
test-backedSelect scenario from the component test coverage: supports select.option and select.optgroup children.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectSupportsSelectOptionAndDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Uses Popover API with popover=
test-backedSelect scenario from the component test coverage: uses popover api with popover=.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectUsesPopoverAPIWithDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Closes when clicking outside the select container
test-backedSelect scenario from the component test coverage: closes when clicking outside the select container.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectClosesWhenClickingOutsideDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Tracks native popover toggle event
test-backedSelect scenario from the component test coverage: tracks native popover toggle event.
Source
import "@duskmoon-dev/components/styles.css";
import { Select } from "@duskmoon-dev/components/select";
export function SelectTracksNativePopoverToggleDemo() {
return (<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>);
}Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
Source
<div data-theme="sunshine">
<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>
</div>
<div data-theme="moonlight">
<Select
options={[
{ label: "React", value: "react" },
{ label: "Astro", value: "astro" },
{ label: "TypeScript", value: "typescript" }
]}
defaultValue="react"
placeholder="Select a stack"
allowClear
/>
</div>API
The API reference below lists every parsed exported type or interface for Select. Start with `allowClear`, `defaultOpen`, `defaultValue`, `disabled` for common usage.
packages/components/src/components/select/Select.types.tsScenarios: packages/components/src/components/select/Select.test.tsx| Prop | Type | Required | Description |
|---|---|---|---|
allowClear | boolean | No | allowClear configures Select. |
children | ReactNode | No | children configures Select. |
defaultOpen | boolean | No | defaultOpen configures Select. |
defaultValue | SelectChangeValue | No | defaultValue configures Select. |
disabled | boolean | No | disabled configures Select. |
loading | boolean | No | loading configures Select. |
mode | SelectMode | No | mode configures Select. |
onChange | ( | No | onChange configures Select. |
value | SelectChangeValue, | Yes | value configures Select. |
option | SelectOptionType | SelectOptionType[], | No | option configures Select. |
onDropdownVisibleChange | (open: boolean) => void | No | onDropdownVisibleChange configures Select. |
onOpenChange | (open: boolean) => void | No | onOpenChange configures Select. |
open | boolean | No | open configures Select. |
options | SelectOptionInput[] | No | options configures Select. |
placeholder | ReactNode | No | placeholder configures Select. |
showSearch | boolean | No | showSearch configures Select. |
size | SelectSize | No | size configures Select. |
status | SelectStatus | No | status configures Select. |
value | SelectChangeValue | No | value configures Select. |
| Prop | Type | Required | Description |
|---|---|---|---|
label | ReactNode | No | label configures Select. |
value | SelectValue | Yes | value configures Select. |
disabled | boolean | No | disabled configures Select. |
className | string | No | className configures Select. |
| Prop | Type | Required | Description |
|---|---|---|---|
label | ReactNode | No | label configures Select. |
options | SelectOptionType[] | Yes | options configures Select. |
className | string | No | className configures Select. |
| Prop | Type | Required | Description |
|---|---|---|---|
children | ReactNode | No | children configures Select. |
disabled | boolean | No | disabled configures Select. |
value | SelectValue | Yes | value configures Select. |
| Prop | Type | Required | Description |
|---|---|---|---|
children | ReactNode | No | children configures Select. |
label | ReactNode | No | label configures Select. |
Type definition
string | numberType definition
"multiple" | "tags"Type definition
"sm" | "md" | "lg"Type definition
"error" | "success"Type definition
SelectOptionType | SelectOptGroupTypeType definition
SelectValue | SelectValue[] | undefinedType definition
ForwardRefExoticComponent< SelectProps & RefAttributes<HTMLDivElement> > & { Option: ForwardRefExoticComponent< SelectOptionProps & RefAttributes<HTMLDivElement> >