Select Menu

View on GitHub

Introduction

The SelectMenu component is an advanced interaction pattern which allows selection of multiple items from a dropdown list. It can be used as a substitute for the native multiple select element.

Implementation details

The SelectMenu builds on top of the Popover component and uses react-tiny-virtual-list for the rendering of the virtualized list of options.

Multiselect

The SelectMenu is unopinionated in how many items are selected in the list. Pass an array to the selected prop to select more items.

Close on select

The SelectMenu by default will stay open when an option is selected. This can be configured so that the menu closes on selection. This will not apply for Multiselect menus.

Options prop structure

const options = [
{
label: 'String',
value: 'String or Number'
}
]

Single selected item

This example shows basic usage with a single selected item.

The `Component` component is not part of Evergreen. It is only used in examples to create state. Learn more.
Hide code

Remove title and filter

  • hasFilter={false}: to remove the search input filter.
  • hasTitle={false}: to remove the title from the popover.
The `Component` component is not part of Evergreen. It is only used in examples to create state. Learn more.
Hide code

Change the height and width

The `Component` component is not part of Evergreen. It is only used in examples to create state. Learn more.
Hide code

Change the position of the popover

Available positions:

  • Position.TOP
  • Position.TOP_LEFT
  • Position.TOP_RIGHT
  • Position.BOTTOM
  • Position.BOTTOM_LEFT
  • Position.BOTTOM_RIGHT
The `Component` component is not part of Evergreen. It is only used in examples to create state. Learn more.
Hide code

Empty view

It's possible to display a custom empty view instead of options list via emptyView, when there are no properties supplied. Note that empty view won't be shown when options are being filtered and there are no search results.

Hide code

It's also possible to close <SelectMenu> from within empty view:

Hide code

Menu with icons

It's possible to include icons in the menu list.

Hide code

Multiselect with deselect example

This example shows usage with multiple selected items.

This pattern is only an example. Selected values and the formatting of their names should be managed wherever you choose to manage state. The onDeselect method is provided to assist with this.

As users click on selected values to remove them, you can update state.

The `Component` component is not part of Evergreen. It is only used in examples to create state. Learn more.
Hide code

onFilterChange example

This example shows basic usage with onFocusChange.

Filter value:
The `Component` component is not part of Evergreen. It is only used in examples to create state. Learn more.
Hide code

Disabled option example

This example shows basic usage for disabling some options. Options that are disabled cannot be clicked and their labels are muted.

The `Component` component is not part of Evergreen. It is only used in examples to create state. Learn more.
Hide code

Custom Title Example

This example shows how one should use titleView to pass in a custom title.

The `Component` component is not part of Evergreen. It is only used in examples to create state. Learn more.
Hide code

Custom Filter PlaceHolder and Icon Example

It's possible to change the filter placeholder and filter icon through the filterPlaceholder and filterIcon props.

Note that the icon can be one found in Segment's various icons, or none.

The `Component` component is not part of Evergreen. It is only used in examples to create state. Learn more.
Hide code

SelectMenu Props

titlestring
The title of the Select Menu.
widthstring | number
The width of the Select Menu.
heightstring | number
The height of the Select Menu.
optionsArray<custom>OptionShapePropType
The options to show in the menu. [{ label: String, value: String | Number }]
onSelectfunc
Function that is called when an option is selected.
onDeselectfunc
Function that is called when an option is deselected.
selectedcustom
The selected value/values.
isMultiSelectbool
When true, multi select is accounted for.
hasTitlebool
When true, show the title.
hasFilterbool
When true, show the filter.
filterPlaceholderstring
The placeholder of the search filter.
filterIconelementType | element
The icon of the search filter.
onFilterChangefunc
Function that is called as the onChange() event for the filter.
positionPosition.TOP | Position.TOP_LEFT | Position.TOP_RIGHT | Position.BOTTOM | Position.BOTTOM_LEFT | Position.BOTTOM_RIGHT
The position of the Select Menu.
detailViewfunc | node
Can be a function that returns a node, or a node itself, that is rendered on the right side of the Select Menu to give additional information when an option is selected.
titleViewfunc | node
Can be a function that returns a node, or a node itself, that is rendered in the header section of the Select Menu to customize the header.
emptyViewfunc | node
Can be a function that returns a node, or a node itself, that is rendered instead of the options list when there are no options.
closeOnSelectbool