Select

Selected .
open

The select and search controls allow the user to select an option or options.

Select menus in Base hover atop of a selection menu while providing a simple list of options. Proper spacing, color, and a check-mark are clear indicators of a selection. Each menu is scrollable, if applicable.

Note: by default, id and label are default properties that Select components look for in options array objects. To adapt to custom properties, use the labelKey and valueKey to override the defaults.

Examples

Select basic usage

Select...
open

Things to note in the example source code:

  • the value is always an Array to provide a consistent interface - no matter if you use multi or single selects,
  • you have to call setState with the entire object, not just the id value.

Disabled select

Select...
open

Basic Grouped usage

You are currently using a collapsible grouped menu. To move to next group press Shift and down arrow. To move to previous group press Shift and up arrow. Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
Select...
open

Things to note:

  • keys should be unique b/w group options

Grouped usage with Select All

You are currently using a collapsible grouped menu. To move to next group press Shift and down arrow. To move to previous group press Shift and up arrow. Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
Select...
open
search
Choose a color

Label with loading state in single select

Selected AliceBlue.
open

Label with loading state in multi select

Selected AliceBlue. Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
open

Limit number of tags rendered

Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
Select...
open

Select with searchTags

search
Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
Choose a color

When type is 'search' a magnifying glass icon will be rendered to the input's left and a dropdown arrow will not be rendered to the right.

Select with custom labels

Select...
open

Select in different sizes

XSmall
open
Small
open
Medium
open

Select creatable

Select...
open

The creatable select enables users to create new options along with choosing existing options.

search
Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
Choose a color

Select creatable multi-pick

Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
Select...
open

Add values when delimiter is encountered

Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
Select...
open

Separate values by delimiter

Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
Select...
open

Add values on paste event

Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
Select...
open

Select as overlay

When type is 'overlay', select renders in overlay. Child element works as target element for overlay select.

Create Overlay Select with confirmation using overrides

No colors selected

    Mobile Select (with children)

    Mobile Select (without children)

    Choose a color
    open

    Usage of controlRef prop

    Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
    Choose a color
    open

    Usage of controlRef prop with OverlaySelect

    Select with grouped options

    Select...
    open

    Select similar to native select

    Select...
    open

    Overlay Select with grouped options

    Select uncontrolled example

    Select...
    open

    Select with many options

    Select...
    open

    Virtualization is enabled in Select by default. Select uses react-virtual.

    Select in a modal dialog

    Select with scroll lock

    Select...
    open

    Select with custom placement and popoverMinWidth

    Select...
    open

    Select with overridden menu items and Value

    Use Left and Right arrow keys to navigate between selected values. Enter BackSpace to remove currently focused value
    Select...
    open

    Select with overridden placeholder

    Select...
    open

    To override the Popover that's being used by the Dropdown subcomponent, you have to use a nested override.

    Clear As Option

    Select...
    open

    Setting clearAsOption will render an additional option in the popover whenever a value is selected. This additional option can be used to clear the selected value. Whenever clearAsOption is set, ClearIcon will not be rendered irrespective of the value of clearable prop. By default the label for this clear option will be Unassign, a custom label can be set using clearAsOptionLabel prop.

    API

    Select props

    NameTypeDefaultDescription
    aria-describedby
    string
    Sets the aria-describedby attribute.
    aria-label
    string
    Sets the aria-label attribute.
    aria-labelledby
    string
    Sets the aria-describedby attribute.
    autoFocus
    boolean
    Defines if select element is focused on the first mount.
    backspaceClearsInputValue
    boolean
    falseBy default, backspace will only remove the last character of the input value. If true, the input value will be cleared.
    backspaceRemoves
    boolean
    trueDefines if options can be removed by pressing backspace.
    captureScroll
    boolean
    falseWhen the user reaches top/bottom of the menu, prevents scroll to the body/scroll-parent
    children
    react node
    When type is 'overlay', Select is opened in overlay and children works as target element for the popover. For all other types, children is simply ignored.
    className
    string
    Enriched style to be provided to Select Root
    clearAsOption
    boolean
    falseAdd option to clear selected value in the popover instead of clearable icon.
    clearAsOptionLabel
    string
    UnassignDefines the label for the option which clears the selected values.
    clearable
    boolean
    trueDefines if the select value can be cleared. If true a clear icon is rendered when a value is set.
    closeOnSelect
    boolean
    trueDefines if the menu closes after a selection if made.
    controlRef
    ref
    Exposes methods to control select's dropdown and other internal state. Check types and examples for more information.
    creatable
    boolean
    Defines if new options can be created along with choosing existing options.
    createOption
    function
    A custom handler that returns options to be created from the input value (label) entered by the user. It should return Options or Promise<Options>.
    deleteRemoves
    boolean
    trueDefines if options can be removed by pressing backspace.
    delimiter
    string
    If defined, select will create option and call onChange whenever delimeter is encountered when input changes.
    disabled
    boolean
    Defines if the control is disabled.
    escapeClearsValue
    boolean
    trueDefines if the value is cleared when escape is pressed and the dropdown is closed.
    filterOptions
    function
    A custom method to filter options to be displayed in the dropdown.
    filterOutSelected
    boolean
    trueDefines if currently selected options are filtered out in the dropdown options. Only for `multi` select.
    getOptionLabel
    function
    A custom method to get a display value for a dropdown option.
    getValueLabel
    function
    A custom method to get a display value for a selected option.
    hideSelectAll
    boolean
    falseHides select all option for multi select box.
    id
    string
    Sets the id attribute of the internal input element. Allows for usage with labels.
    ignoreBoundary
    boolean
    If true, popover element will overflow outside anchor's scrollParent.
    inputRef
    ref
    A ref to access an input element.
    intent
    'default'| 'success'| 'warning'| 'error'
    Defines the intent of the Select.
    isLoading
    boolean
    Defines if the select is in a loading (async) state.
    label
    react node
    Sets label of Select when type is 'mobile'
    labelKey
    string
    Defines an option key name for a default label value.
    limitTags
    number
    Number of tags which should be rendered rest of the tag will be shown as a popover
    maxDropdownHeight
    string
    Sets max height of the dropdown list.
    mountNode
    ref
    Where to mount the popover.
    multi
    boolean
    Defines if multiple options can be selected.
    noResultsMsg
    react node
    Message to be displayed if no options is found for a search query.
    noTooltipOnTruncation
    boolean
    falseBy default, tooltip will be visible when content gets truncated
    onBlur
    function
    Called the onBlur event triggers.
    onBlurResetsInput
    boolean
    trueDefines if the input value is reset to an empty string when a blur event happens on the select.
    onChange
    function
    Change handler of the select to be called when a value is changed.
    onClose
    function
    A function that is called when the dropdown closes.
    onCloseResetsInput
    boolean
    trueDefines if the input value is reset to an empty string when dropdown is closed.
    onFocus
    function
    Called the onFocus event triggers.
    onInputChange
    function
    Change handler of the search input.
    onOpen
    function
    A function that is called when the dropdown opens.
    onPaste
    function
    A function that is called when a paste event occurs on the select's input. It receives a single argument of the clipboard event and expects options to be returned.return values from onPaste won't trigger onChange if creatable is false
    onSelectResetsInput
    boolean
    trueDefines if the input value is reset to an empty string when a selection is made.
    openOnClick
    boolean
    trueDefines if the dropdown opens on a click event on the select.
    options
    array
    Options to be displayed in the dropdown. If an option has a disabled prop value set to true it will be rendered as a disabled option in the dropdown.
    overlayWidth
    string
    Sets width of select when type is 'overlay'. Default is '300px'.
    overrides
    custom
    Lets you customize all aspects of the component.
    placeholder
    string
    Sets the placeholder.
    placement
    'auto'| 'topLeft'| 'top'| 'topRight'| 'rightTop'| 'right'| 'rightBottom'| 'bottomRight'| 'bottom'| 'bottomLeft'| 'leftTop'| 'left'| 'leftBottom'
    Controls how to position the dropdown relative to the select. Defaults to `bottom`
    popoverMinWidth
    string
    Sets the minWidth of the dropdown container.
    required
    boolean
    Defines if the select field is required to have a selection.
    searchable
    boolean
    trueDefines if the search functionality is enabled.
    selectOnTab
    boolean
    falseWhen enabled allows to click on/select highlighted item on Tab key press.
    size
    'xs'| 'sm'| 'md'
    Input's size. SPACIOUS | COMFORTABLE -> md, COMPACT -> xxxs, DEFAULT -> md
    startOpen
    boolean
    If true, opens the dropdown when the select mounts.
    style
    string
    Enriched style to be provided to Select Root
    type
    'search'| 'select'| 'overlay'| 'mobile'
    Defines type of the component to be in a select or search mode. When set to 'search' the search icon is rendered on the left and the select arrow icon is not rendered. When set to 'overlay' the select is rendered in overlay.
    value
    array
    A current selected value(s). If a selected value has a clearableValue prop set to false it will be rendered as a disabled selected option that can't be cleared.
    valueKey
    string
    Defines a key name for an option's unique identifier value. The value of the 'valueKey' prop is used to identify what options are selected or removed from the selection, it also used for default filtering out the selected options from the dropdown list.
    virtual
    boolean
    trueAdd virtualization to select options

    You can check the implementation of the component for more details.

    Select exports

    You can import this module like so:

    import {CLEARABLE_KEY} from 'spaceweb/select'

    It exports the following components or utility functions:

    • CLEARABLE_KEY
    • CLEAR_OPTION_ID
    • CollapsibleSelectMenu
    • GroupedSelect
    • LOADING_KEY
    • MobileSheet
    • MultiSelect
    • MultiValue
    • NoResults
    • SELECT_ALL_ID
    • STATE_CHANGE_TYPE
    • Select
    • SelectMenuAdapter
    • SingleSelect
    • SingleValue
    • StatefulSelect
    • StyledClearIcon
    • StyledControlContainer
    • StyledDropdownContainer
    • StyledIconsContainer
    • StyledInput
    • StyledInputContainer
    • StyledInputSizer
    • StyledOverlayContentContainer
    • StyledPlaceholder
    • StyledRoot
    • StyledSearchIconContainer
    • StyledSelectArrow
    • StyledSingleValue
    • StyledValueContainer
    • defaultFilterOptions