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)}>
itemRendererfunctionCustom renderer function for option items. Receives option, parent component and prefix as parameters.
<rapid-multiselect :itemRenderer=${() => (option, parent, prefix) => html`<span>${option.label}</span>`}>

Slots

NameDescription
labelSlot for the component label
indicatorSlot used for the loading indicator
DefaultUsed for datasource elements
options-headerSlot for adding custom header content above the options list

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

CSS vars

NameDescription
--scrollbar-widthControls the width of the scrollbar.
--scrollbar-thumb-widthControls the width of the scrollbar thumb.

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.