Overview

The <web-multiselect> web component provides a rich, accessible multiselect interface with extensive customization options.

Public Properties

PropertyTypeDescription
optionsT[]Array of items to display in the dropdown
selectedValuestring | number | (string | number)[] | nullGet selected value(s). Returns single value in single-select mode, array in multi-select mode
selectedItemT | nullGet the first selected item object
Properties Example
 

Public Methods

getValue()

Returns the current selected value(s) in a form-ready format.

  • Returns: string | number | (string | number)[] | null
  • Behavior: Mode-dependent. Returns single value in single-select mode, array in multi-select mode
 

getSelected()

Returns array of selected item objects.

  • Returns: T[]
  • Behavior: Always returns an array of full item objects
 

setSelected(values)

Set selected values programmatically.

  • Parameters: values: (string | number)[]
  • Returns: void
 

destroy()

Clean up the component and remove all event listeners.

  • Returns: void
 

Callback Properties

Set these properties to customize data extraction and behavior:

PropertyTypeDescription
getValueCallback(item: T) => string | numberExtract unique ID from item
getDisplayValueCallback(item: T) => stringExtract display text from item
getBadgeDisplayCallback(item: T) => stringExtract custom badge display text (defaults to display value)
getBadgeClassCallback(item: T) => string | string[]Get CSS classes for individual badges
getSearchValueCallback(item: T) => stringExtract searchable text from item
getIconCallback(item: T) => stringExtract icon/emoji from item
getSubtitleCallback(item: T) => stringExtract subtitle/description from item
getGroupCallback(item: T) => stringExtract group name from item
renderGroupLabelContentCallback(groupName: string) => string | HTMLElementCustom rendering for group labels
getDisabledCallback(item: T) => booleanDetermine if item is disabled
getValueFormatCallback(values: (string | number)[]) => stringCustom form value formatting
beforeSearchCallback(searchTerm: string) => string | nullTransform search term before searching (return null to cancel)
searchCallback(searchTerm: string) => Promise<T[]>Async function to load data
addNewCallback(value: string) => T | Promise<T>Create new option when adding
selectCallback(option: T) => voidCalled when option is selected
deselectCallback(option: T) => voidCalled when option is deselected
changeCallback(selectedOptions: T[]) => voidCalled when selection changes
customStylesCallback() => stringInject custom CSS into Shadow DOM
Callbacks Example
 

Rendering Callbacks

Customize how options, badges, and selected items are rendered:

PropertyTypeDescription
renderOptionContentCallback(item: T, context: OptionContentRenderContext) => string | HTMLElementCustom rendering for dropdown options
renderBadgeContentCallback(item: T, context: BadgeContentRenderContext) => string | HTMLElementCustom rendering for selected item badges
renderSelectedItemContentCallback(item: T) => string | HTMLElementCustom rendering for items in "more" popover
getSelectedItemClassCallback(item: T) => string | string[]Get CSS classes for selected items in popover
getCounterCallback(count: number, moreCount?: number) => stringCustom counter text formatting
Rendering Example
 

Tooltip Callbacks

Customize badge and remove button tooltips:

PropertyTypeDescription
getBadgeTooltipCallback(item: T) => string | HTMLElementCustom tooltip content for badges
getRemoveButtonTooltipCallback(item: T) => stringCustom tooltip for remove button

Action Buttons

Configure action buttons in the dropdown:

PropertyTypeDescription
actionButtonsActionButton<T>[]Array of action button configurations
Action Buttons Example
 

Custom Events

The component dispatches these custom events:

EventDetail TypeDescription
selectMultiSelectEventDetail<T>Dispatched when an option is selected
deselectMultiSelectEventDetail<T>Dispatched when an option is deselected
changeMultiSelectEventDetail<T>Dispatched when selection changes
Events Example
 

TypeScript Support

The component is fully typed with generic support:

TypeScript Example
 

Global API

Access component functionality through the global API namespace window.keenmate.multiselect:

Method / PropertyReturnsDescription
version()stringReturns the component version
configobjectPackage metadata (name, version, author, license, repository, homepage)
register()voidManually register the custom element (if not auto-registered)
getInstances()HTMLElement[]Get all active multiselect instances on the page

Usage Examples

Check Component Version

Version Info
 

Get All Instances

Instance Management
 

Manual Registration

Manual Registration
 
💡 Use Cases:
  • Version Detection: Check component version in bundled projects
  • Global State: Access all instances for batch operations
  • Debugging: Inspect instances in browser console
  • Testing: Programmatically interact with all instances

📝 Important Notes

  • Generic Types: Component supports any data structure via T parameter
  • Reactive: All properties are reactive - changes update the UI automatically
  • Shadow DOM: Component uses Shadow DOM for encapsulation
  • Form Integration: Works seamlessly with HTML forms via hidden inputs
  • Cleanup: Always call destroy() when removing from DOM