Skip to main content

Multiselect

Use cases:

  • Selecting one or more from a list of options
  • Adding extra information to the options in addition to what is possible with the standard select component

Example

Declaration

<rapid-multiselect></rapid-multiselect>

Usage

@customElement({
name: 'my-element',
template: html`
<rapid-multiselect
${ref('multiselect')}
@selectionChange=${(x) => x.onChange()}
:options=${(x) => x.options}
>
</rapid-multiselect>
`,
})
export class MyElement extends GenesisElement {
@observable multiselect: Multiselect;
const options = [
{
value: 'First value',
label: 'This is the first value',
},
{
value: 'Second value',
label: 'This is the second value',
},
{
value: 'Third value',
label: "This is the third value, and it's disabled",
disabled: true,
},
]
onChange() {
// You can also get the selected options via `event.detail`
console.log(this.multiselect.selectedOptions)
}
}

API

Property and attribute binding examples for Genesis Component syntax. Closing tag omitted.

Attributes

NameTypeDescriptionExample
namestringThe name of the multiselect component.
<rapid-multiselect name="myMultiselect">
autoPositionbooleanControls if dropdown automatically positions based on available space.
<rapid-multiselect autoPosition>
allbooleanWhether to show "Select All" option. Default true.
<rapid-multiselect all>
allSelectedbooleanWhether all options are selected by default.
<rapid-multiselect allSelected>
searchbooleanWhether to enable search functionality. Default true.
<rapid-multiselect search>
disabledbooleanWhether the component is disabled.
<rapid-multiselect disabled>
creatablebooleanWhether new options can be created.
<rapid-multiselect creatable>
asyncbooleanWhether to use async data loading.
<rapid-multiselect async>
debouncenumberDebounce time for async searches.
<rapid-multiselect debounce=300>
filterByContainsbooleanWhether to filter using "contains" vs "starts with". Default false.
<rapid-multiselect filterByContains>
position"below" | "above"Controls dropdown positioning (positioning enum).
<rapid-multiselect position="BELOW">

Properties

NameTypeDescriptionExample
valueFormatterfunctionFunction to format option display values.
<rapid-multiselect :valueFormatter=${() => (option: MultiselectOption) => `${option.label} (${option.value})`}>
optionsMultiselectOption[]Available options.
<rapid-multiselect :options=${() => [
{ value: 'opt1', label: 'Option 1' },
{ value: 'opt2', label: 'Option 2' }
]}>
<rapid-multiselect :options=${(x) => x.options}>
selectedOptionsstring[]Currently selected option values.
<rapid-multiselect :selectedOptions=${() => ['opt1', 'opt3']}>
<rapid-multiselect :selectedOptions=${(x) => x.selectedOptions}>
onAllSelectedCallbackfunctionCallback when "select all" state changes.
<rapid-multiselect :onAllSelectedCallback=${() => (allSelected: boolean) => console.log('All selected:', allSelected)}>

Slots

NameDescription
labelSlot for the component label
indicatorSlot used for the loading indicator
DefaultUsed for datasource elements

Parts

NameDescription
labelPart for the label element
rootPart for the root container
controlPart for the control container
filter-searchPart for the search input field
indicatorPart for the dropdown indicator/arrow
options-olPart for the options list container
checkboxPart for the checkbox components
option-labelPart for the label of each option

Events fired

EventTypeUseExample
selectionChangestring[]Emitted when a single option is selected or deselected, or when the "Select All" functionality is used. The event detail contains an array of selected option values.
<rapid-multiselect @selectionChange="${(e) => handleSelectionChange(e.detail)}">

Events listened to

This component doesn't listen to any events.