Skip to content
GitSiteEmail

The Dropdown component allows you to create a dropdown menu with selectable options. It works seamlessly with the Dropdown.Options and Dropdown.Option slots.

For detailed information about the Dropdown.Options and Dropdown.Option slots, refer to the Dropdown.Options documentation.

To implement a dropdown in your UI, wrap the Dropdown.Options and Dropdown.Option slots within the Dropdown component:

import Dropdown from '@components/Basic/Dropdown/Dropdown';
<Dropdown style={{ width: '10rem' }}>
<Dropdown.Options>
<Dropdown.Option selected value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
</Dropdown>
Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the component’s root element.
classstring""Additional CSS classes to apply to the component.
refDropdownRef | undefinedundefinedA reference to the component, providing access to its methods and underlying HTML element for programmatic control.
disabledbooleanfalseDisables the dropdown when set to true.
class-disabledstring""Additional CSS classes to apply when the dropdown is disabled.
multiplebooleanfalseEnables multi-select mode. When true, selecting an option toggles it on or off, the options panel stays open after a selection, and onChange reports an array of values.
valuestring | string[]undefinedThe selected value(s) of the dropdown. Pass a string (or a string[] when multiple is enabled) to control or set the selection. The prop is reactive - updating it externally changes the selection. Values that don’t match a registered option are ignored. When provided, it takes precedence over the selected prop on Dropdown.Option.
onChange(value: string | string[]) => voidundefinedCallback function triggered whenever the selection changes. Provides the selected option’s value, or an array of selected values when multiple is enabled.
onActionRecord<string, (scope?: string, ...args: any[]) => void>undefinedExtends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details.
anchorstring | HTMLElementundefinedLinks navigation to another element. When the anchor element is focused, the dropdown’s actions will execute. Can be a CSS selector or HTMLElement.

To interact with the Dropdown programmatically, you can use the DropdownRef interface. This interface provides properties and methods to access and manipulate the component’s state.

PropertyTypeDescription
selectedAccessor<string>Read the currently selected option: ref.selected() returns the value.
selectedValuesAccessor<string[]>Read all currently selected values when the dropdown is in multiple mode: ref.selectedValues() returns the array of values.
elementHTMLDivElementA reference to the dropdown’s root HTML element, useful for DOM access or styling.
MethodParametersReturn ValueDescription
selectOptionvalue: stringvoidSelects an option programmatically. In multiple mode, calling it with an already-selected value toggles it off.
deselectOptionvalue: stringvoidDeselects a single option by its value.
deselectAllnonevoidClears every selected option in one call, firing onChange once with the empty result.
toggleisOpened: booleanvoidProgrammatically opens (true) or closes (false) the dropdown’s options panel.

The Dropdown.Trigger slot allows you to customize the dropdown’s trigger button, which toggles the dropdown’s open or closed state when clicked. Use this slot to modify the trigger’s appearance by applying custom styles or CSS classes.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the trigger element.
classstring""Additional CSS classes to apply to the trigger element.
import Dropdown from '@components/Basic/Dropdown/Dropdown';
const App = () => {
return (
<Dropdown>
<Dropdown.Options>
<Dropdown.Option selected value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
<Dropdown.Trigger style={{ background: '#cccccc' }}/>
</Dropdown>
);
};
export default App;

The Dropdown.Placeholder slot allows you to display a placeholder when no option is selected in the dropdown. If this slot is not used, no placeholder will be shown by default.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the placeholder element.
classstring""Additional CSS classes to apply to the placeholder element.
childrenJSX.Element""Content to display when no option is selected, such as text or JSX.
import Dropdown from '@components/Basic/Dropdown/Dropdown';
const App = () => {
return (
<Dropdown>
<Dropdown.Options>
<Dropdown.Option value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
<Dropdown.Placeholder style={{ color: '#cccccc' }}>Select any option</Dropdown.Placeholder>
</Dropdown>
);
};
export default App;

The Dropdown.Icon slot allows you to add or customize the icon displayed inside the dropdown’s trigger, typically on the right side.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the dropdown trigger’s icon element.
classstring""Additional CSS classes to apply to the dropdown trigger’s icon element.
childrenJSX.Element""Custom content, such as text, HTML, or JSX, to render as the dropdown icon.
import Dropdown from '@components/Basic/Dropdown/Dropdown';
const App = () => {
return (
<Dropdown>
<Dropdown.Options>
<Dropdown.Option selected value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
<Dropdown.Icon style={{ background: '#cccccc' }}>
<img src="my-custom-icon.png" />
</Dropdown.Icon>
</Dropdown>
);
};
export default App;

The Dropdown.Track slot enables you to customize the scroll track of the dropdown when the options overflow the container.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the dropdown’s track element.
classstring""Additional CSS classes to apply to the dropdown’s track element.
childrenJSX.Element""Custom content, such as text, HTML, or JSX, to render inside the track.
import Dropdown from '@components/Basic/Dropdown/Dropdown';
const App = () => {
return (
<Dropdown>
<Dropdown.Options>
<Dropdown.Option selected value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
<Dropdown.Track style={{ background: '#cccccc' }}/>
</Dropdown>
);
};
export default App;

The Dropdown.Handle slot lets you customize the scroll handle for the dropdown when the options overflow the container.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the handle element.
classstring""Additional CSS classes to apply to the handle element.
childrenJSX.Element""Custom content, such as text, HTML, or JSX, to render inside the handle.
import Dropdown from '@components/Basic/Dropdown/Dropdown';
const App = () => {
return (
<Dropdown>
<Dropdown.Options>
<Dropdown.Option selected value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
<Dropdown.Handle style={{ background: '#cccccc' }}/>
</Dropdown>
);
};
export default App;

The Dropdown component implements the following navigation actions by default:

Action NameBehavior
selectOpens the dropdown when closed. When open, collapses the dropdown (options handle selection)
backCloses the dropdown and returns focus to the trigger or anchor element

You can extend the Dropdown with additional navigation actions or override the default behavior using the onAction prop:

import Dropdown from '@components/Basic/Dropdown/Dropdown';
<Dropdown
onAction={{
'select': () => console.log('Custom select behavior!'),
'back': () => console.log('Custom back behavior!')
}}
>
<Dropdown.Options>
<Dropdown.Option value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
</Dropdown>

For more information about navigation actions, check the Navigation component documentation.

Retrieve the selected option’s value on change

Section titled “Retrieve the selected option’s value on change”

To capture the value of the selected option:

  • Use the onChange prop to handle changes in the selected option.
  1. Pass a callback function to the onChange prop to handle state updates.
  2. Access the selected option’s value through the selected parameter in the callback.
import Dropdown from '@components/Basic/Dropdown/Dropdown';
const App = () => {
const handleSelectionChange = (selected: string) => {
console.log(selected);
};
return (
<Dropdown onChange={handleSelectionChange}>
<Dropdown.Options>
<Dropdown.Option selected value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
</Dropdown>
);
};
export default App;

To let users select more than one option at a time, enable the multiple prop.

  • Clicking an option toggles it on or off instead of replacing the current selection.
  • The options panel stays open after a selection so several options can be picked in a row.
  • onChange receives an array of the selected values.
import Dropdown from '@components/Basic/Dropdown/Dropdown';
const App = () => {
const handleSelectionChange = (selected: string[]) => {
console.log(selected); // e.g. ["red", "blue"]
};
return (
<Dropdown multiple onChange={handleSelectionChange}>
<Dropdown.Options>
<Dropdown.Option value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
</Dropdown>
);
};
export default App;

Control the selected value (two-way binding)

Section titled “Control the selected value (two-way binding)”

The value prop is reactive: pass a signal to it and update that signal from onChange to keep your state and the dropdown in sync in both directions.

  • Updating the signal externally moves the selection (state → dropdown).
  • Selecting an option in the UI fires onChange, which updates the signal (dropdown → state).
  1. Create a signal to hold the selected value.
  2. Bind it to the value prop.
  3. Update it from the onChange callback.
import Dropdown from '@components/Basic/Dropdown/Dropdown';
import { createSignal } from 'solid-js';
const App = () => {
const [selected, setSelected] = createSignal('red');
return (
<>
<Dropdown value={selected()} onChange={(value) => setSelected(value as string)}>
<Dropdown.Options>
<Dropdown.Option value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
</Dropdown>
{/* Updating the signal here also moves the dropdown's selection */}
<button onClick={() => setSelected('blue')}>Select blue</button>
</>
);
};
export default App;

In multiple mode, bind value to a string[] signal instead. Any values that don’t match a registered option are filtered out:

const [selected, setSelected] = createSignal<string[]>(['red', 'blue']);
<Dropdown multiple value={selected()} onChange={(value) => setSelected(value as string[])}>
<Dropdown.Options>
<Dropdown.Option value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
</Dropdown>

The Dropdown component allows you to programmatically update the selected option.

  1. Create a ref variable of type DropdownRef and assign it to the Dropdown component.
  2. Use the ref.selectOption() method to programmatically set a new selected option, such as in response to a button click or keyboard event.
import Dropdown, { DropdownRef } from '@components/Basic/Dropdown/Dropdown';
const App = () => {
let dropdownRef!: DropdownRef;
const handleKeyPress = (e: KeyboardEvent) => {
if (e.keyCode !== 13) return
dropdownRef.selectOption('green');
};
return (
<Dropdown ref={dropdownRef} keypress={handleKeyPress}>
<Dropdown.Options>
<Dropdown.Option selected value="red">red</Dropdown.Option>
<Dropdown.Option value="green">green</Dropdown.Option>
<Dropdown.Option value="blue">blue</Dropdown.Option>
</Dropdown.Options>
</Dropdown>
);
};
export default App;