Skip to content

Select

The Select component provides a dropdown for choosing a single value from a list of options. It supports both controlled and uncontrolled modes, clearable selections, async loading, search filtering, grouped options, and the usual form-field affordances (label, caption, error/warning).

Variations

Clearable selection

Set clearable to show a clear button when a value is selected. Clearing the field resets the value to undefined, calls onChange(undefined), and invokes onClear when provided.

Suffix

The Select component can be customized with a suffix element that appears on the right side of the input.

Form integration

The Select component integrates seamlessly with form elements like labels, captions, and validation messages.

Enable client-side search filtering to help users find options quickly in large or structured lists.

Async loading

Options can be loaded asynchronously by passing a function that returns a Promise.

Disabled states

Both the entire select and individual options can be disabled.

Open callback

The onOpen callback is triggered when the dropdown menu opens. This is useful for lazy loading data, logging analytics, or triggering side effects when users interact with the select.

Loading states

The Select component provides clear loading indicators for different scenarios.

Complex option labels

Options can have ReactNode labels for rich content display.

Custom option renderer

Customize how individual options are rendered using the optionRenderer prop. This allows advanced layouts or UI elements for each option.

Grouped options and separators

Sizes

The Select component supports two sizes: md (default) and sm. The default size is suitable for most use cases, while the sm size is useful for compact layouts.

With tooltip

tooltipContent is used to display the content of the tooltip. tooltipProps is used to pass additional props to the tooltip.

Orientation

The Select component accepts an optional orientation prop, which defines the layout direction of the input and its label. Available options are horizontal and vertical (default).

Installation

import { Select } from "@harnessio/ui/components";
//...
return (
<Select
options={[
{ label: "One", value: "one" },
{ label: "Two", value: "two" },
{ label: "Three", value: "three" },
{ label: "Four", value: "four", disabled: true },
]}
defaultValue="three"
onChange={(value) => console.log(value)}
/>
)