Skip to main content

Component | Multi Select

Render a multi select dropdown.

ui.multiSelectBox("multi-select-input-key", ["A", "B", "C", "D"], { 
label: "Select options",
onChange: (values) => console.log(values) // e.g. ["A", "B"]
})

Learn more about working with inputs.

Options

Select components support both a "basic" and "detailed" format for options.

Basic

Quick and easy. Pass an array of strings, such as ["A", "B", "C", "D"].

ui.multiSelectBox("multi-select-input-key", ["A", "B", "C", "D"], { 
label: "Select options",
onChange: (values) => console.log(values)
})

Detailed

Use separate label and value fields for each option. The label field will be displayed to the user, and the value field will be passed to hooks such as onChange and validate.

const options = [
{ label: "Google", value: "GOOG" },
{ label: "Apple", value: "APPL" },
{
label: "Microsoft",
value: "MSFT",
// The detailed format also supports an optional "description" field
// to display beneath an option.
description: "Current stock price: $423"
}
]

ui.multiSelectBox("companies-key", options, {
label: "Select companies",
onChange: (values) => console.log(values) // e.g. ["GOOG", "APPL"]
})

Detailed option object properties

label

required string
The user-facing label to use for the option.

value

required string | number | boolean

The internal value to assign to the option and use when submitting a form or executing callbacks such as onChange.


description

optional string
Helpful text to display beneath the label.

API reference

Function signature

type OptionValue = string | number | boolean

type DetailedOption = {
label: string,
value: OptionValue,
description?: string
}

ui.multiSelectBox(
id: string,
options: Array<OptionValue | DetailedOption>,
properties: Partial<{
label: string,
description: string,
required: boolean,
initialValue: DetailedSelectValue,
validate: (values: Array<DetailedSelectValue>) => string | void,
onChange: (values: Array<DetailedSelectValue>) => void,
minSelections: number,
maxSelections: number,
style: Style
}>
)

Parameters

id

required string
A unique identifier for the component. This is necessary so that Compose can properly pass user actions back to the component.

options

required Array<OptionValue | DetailedValue>

The list of options that can be selected. See the options section for more info.


properties.label

optional string

The label to display above the multiselect box. If not provided, the label will be inferred from the id.


properties.description

optional string

A description to display between the label and multiselect box.


properties.required

optional boolean

Validate that the multiselect box is not empty before submitting the form it's part of or calling it's onChange hook. Defaults to true.


properties.initialValue

optional Array<string | number | boolean>

The initial value of the multiselect box. Defaults to [] (empty list).


properties.validate

optional (value: Array<string | number | boolean>) => string | void
Validate the multiselect value before submitting it. If the function returns a string, it will be displayed as an error message.

properties.onChange

optional (value: Array<string | number | boolean>) => void
A callback function that is called when the user changes the value of the multiselect.

properties.minSelections

optional number

Validate that the user has selected at least some number of options. Defaults to 0.


properties.maxSelections

optional number

Validate that the user has selected at most some number of options. Defaults to 1000000000.


properties.style

optional Style

Directly style the underlying element using CSS. See the styling guide for more details on available style properties.