MultiSelect API Reference
Complete reference for attributes, options, callbacks, and methods
HTML Attributes (Web Component)
These attributes can be set on the <web-multiselect> custom element.
| Attribute |
Type |
Default |
Description |
multiple |
boolean |
true |
Allow multiple selections. Set to "false" for single-select mode. |
defer |
boolean |
false |
Hold the first render. When present, the component builds nothing on upgrade (reserves space only) — wire options, callbacks (e.g. getCustomStylesCallback) and listeners first, then release with release() (or by removing the attribute) so it builds once, flash-free. Latched; reflects an ready attribute after building. |
enable-search |
boolean |
true |
Enable search/filtering functionality. When false, only keyboard navigation works. |
labels |
JSON object |
— |
Every UI string (placeholders, empty / loading text, hint, counters, popover title, ARIA labels) as a partial map; unset keys stay English. See docs/usage.md → Labels (i18n). |
min-search-length |
number |
0 |
Minimum characters required before triggering async search. |
allow-groups |
boolean |
true |
Enable grouping of options by the group property. |
allow-add-new |
boolean |
false |
Allow adding new options not in the list. |
show-checkboxes |
boolean |
true |
Display checkboxes next to options in multi-select mode. |
actions-sticky |
boolean |
true |
Keep Select All/Clear All buttons fixed while scrolling. |
close-on-select |
boolean |
false |
Close dropdown after selecting an option. |
lock-placement |
boolean |
true |
Lock dropdown placement after first open to prevent jumping. |
badges-display-mode |
string |
'badges' |
How the selection is shown: 'badges', 'count', 'compact', 'partial', or 'none'. |
badges-position |
string |
'bottom' |
Position of badges container: 'top', 'bottom', 'left', or 'right'. |
badges-threshold |
number |
null |
Auto-switch from badges to count when this number is exceeded. |
show-counter |
boolean |
false |
Show count badge next to the toggle icon. |
dropdown-min-width |
string |
null |
Minimum width for dropdown (e.g., '20rem', '300px'). |
max-height |
string |
'20rem' |
Maximum height for dropdown options list. |
value |
string |
undefined |
Initial selection (property defaultValue; also the form-reset target). Parsed per value-format: JSON array (e.g., '["val1","val2"]', bare val1,val2 also accepted) or, with value-format="text", the values joined by value-separator (default ,). The live submitted value is the value property. |
JavaScript Options (MultiSelectEngine)
These options can be passed when instantiating the standalone engine, new MultiSelectEngine(element, options). For the <web-multiselect> element, set them as properties and drive it through el.controller.
| Option |
Type |
Default |
Description |
options |
MultiSelectOption[] |
undefined |
Array of option objects to display in the dropdown. |
container |
HTMLElement |
null |
Container element for dropdown/hint/popover (for Shadow DOM support). |
|
All attributes listed above are also available as JavaScript options with camelCase naming (e.g., isSearchEnabled, maxHeight, etc.)
|
Event Callbacks
Callback functions for handling user interactions and data loading.
| Callback |
Signature |
Description |
searchCallback |
(ctx: { term, signal, entries }) => T[] | Promise<T[]> |
Load options for the typed ctx.term (sync or async). ctx.signal aborts when a newer search supersedes this one — forward it to fetch to cancel the stale request. ctx.searchTerm is the term from getSearchTermCallback; ctx.entries pairs every option with its search value. |
beforeAddCallback |
(ctx: { value }) => T | false | void | Promise<…> |
Runs when the user adds a new option (requires allowAddNew). Return the created option (appended + selected), false to cancel, or nothing — then only the add event fires (create it yourself). |
beforeSearchCallback |
(ctx: { term }) => string | false | void |
Interceptor: pre-process the search term. Return a string to replace the term, false to skip the search, nothing to continue. |
beforeSelectCallback |
(ctx: { option, selectedOptions, selectedValues, source }) => false | void | Promise<false | void> |
Interceptor: runs before an interactive selection. Return false to veto; nothing to allow. No event fires on a veto; to explain it call ctx.controller.showMessage(text, { type: 'warning' }) (a returned string no longer vetoes). Bulk gestures (Select-All, group checkbox, …) run it per option (ctx.source); setSelected and form reset bypass it. |
beforeDeselectCallback |
(ctx: { option, selectedOptions, selectedValues, source }) => false | void | Promise<false | void> |
Interceptor: runs before an interactive deselection (badge ×, Clear-All, inline ✕, …). Same contract as beforeSelectCallback. |
beforeKeydownCallback |
(ctx: KeydownContext) => false | void |
Runs on every keydown before the built-in handling (synchronous). Return false to suppress the built-in handling of the key (call ctx.event.preventDefault() yourself). ctx.controller exposes the focus/selection methods. |
beforeActionCallback |
(detail: MultiSelectActionEventDetail) => false | void | Promise<false | void> |
Runs before an action item activates. Return false to cancel its onClick, the action event and the built-in behaviour. |
onSelect |
(detail: SelectEventDetail) => void |
Called when an option is selected, with the event detail (not the CustomEvent): el.onSelect = ({ option }) => …. addEventListener('select', e => e.detail…) is unchanged. |
onDeselect |
(detail: DeselectEventDetail) => void |
Called when an option is deselected, with the deselect detail (detail.option). |
onChange |
(detail: ChangeEventDetail) => void |
Called whenever the selection changes, with detail.selectedOptions / detail.selectedValues. |
onAdd |
(detail: AddEventDetail) => void |
Called when the user adds a new option (detail.value, detail.option). |
onAction |
(detail: MultiSelectActionEventDetail) => void |
Called for every action-button activation and every data-action element in option / badge content or a showMessage element. |
onReady |
(detail: ReadyEventDetail) => void |
Called once after the first build (detail.controller, detail.element). |
Every callback takes ONE ctx argument; per-option callbacks (getValueCallback, getDisplayValueCallback, getIsDisabledCallback, render callbacks, …) read the option from ctx.option. Every ctx also carries controller, element and the presentation flags. The comparator is selectedOrderCompareCallback({ a, b }).
|
Custom Events (Web Component)
Events dispatched by the <web-multiselect> element that can be listened to via addEventListener.
| Event Name |
Detail Type |
Description |
select |
SelectEventDetail |
Fired when an option is selected. Detail: option, selectedOptions, selectedValues. |
deselect |
DeselectEventDetail |
Fired when an option is deselected. Detail: option, selectedOptions, selectedValues. |
change |
ChangeEventDetail |
Fired when selection changes. Detail: selectedOptions, selectedValues. |
add |
AddEventDetail |
Fired when the user adds a new option from the typed text (requires allow-add-new). Detail: value, option? (when beforeAddCallback returned one), selectedOptions, selectedValues. Not fired when beforeAddCallback returns false. |
action |
MultiSelectActionEventDetail |
Fired for every action button (built-in or custom) and every data-action element inside rendered option content (source: 'option', detail.option), badge content (source: 'badge') or a showMessage element (source: 'message'). Detail: action, id, item, source, sourceEvent, triggerElement, dataset + the selection snapshot. Order: beforeActionCallback → onClick → built-in → action (after the fact; the selection snapshot is re-read). |
ready |
ReadyEventDetail |
Fired once, on the microtask after the first build (a listener added right after createElement still catches it) — at upgrade for a normal element, or when a defer render gate is released for a deferred one. Detail: controller, element, presentation flags. |
input-rejected |
InputRejection |
Fired synchronously (core BlissElement) whenever an attribute or property write is refused — an invalid value, or a setAttributes() key that names no input. The input keeps its previous value (a reflected input writes it back). Detail: configKey, attribute?, value (the raw string on the attribute path), reason?, kept (the value the input kept), source ('attribute' | 'property'). Twin: onInputRejected. |
All events bubble and are not composed (composed: false). Every detail carries controller (= el.controller) and element as non-enumerable properties, so JSON.stringify(e.detail) sees only the data.
|
Public Methods
Methods available on the <web-multiselect> element. The element also exposes el.controller (MultiSelectController) — the public facade also passed as ctx.controller to every callback and event detail: selectedOptions, selectedOption, selectedValue, options, getOptionByValue(value), searchTerm, isOpen, setSelected(values, { notify }), selectAll, clearSelection, toggleValue, selectValue, deselectValue, toggleFocused, open, close, toggle, search, clearSearch, scrollToValue / scrollToGroup / scrollToIndex (return Promise<boolean>), refresh, the focus methods (focusNext, focusPrevious, focusFirst, focusLast, focusPageUp, focusPageDown, focusNextMatch, focusPreviousMatch, focusIndex), showMessage(content, { type, autoHideMs, placement }) and hideMessage.
| Method |
Signature |
Description |
selectedOptions |
T[] (get) |
The currently selected option objects, in selection order (same as controller.selectedOptions). selectedOption is the first one (or null). |
getOptionByValue |
(value: string | number) => T | null |
The option whose value equals value (compared as strings), or null. Also on el.controller. |
setSelected |
(values: (string | number)[]) => void |
Programmatically set selected options by their values. |
selectedValue |
(string | number) | (string | number)[] | null (get) |
The selected value(s) — a single value in single-select mode, an array in multi-select mode (same as controller.selectedValue). |
setAttributes |
(values: Record<string, unknown>) => InputRejection[] |
Apply several inputs as one in-place update (one re-render instead of one per property). Returns the refused writes ([] when everything applied); each also fires input-rejected. Keys are property names (configKey, e.g. maxHeight) or their kebab attribute (max-height); values are typed property values, validated like a direct property assignment — not raw attribute strings. Flushes synchronously. To batch raw attribute strings, use batch(() => { setAttribute(…) }). |
release |
() => void |
Release the defer render gate: build the picker once with everything wired while deferred (flushes pending property writes first). No-op if not deferred or already built. Latched. Fires the ready event. |
isReady |
boolean (get) |
Read-only property: true once the picker has been built (the ready event has fired); false while a defer gate is held. Reflected as the ready attribute. |
destroy |
() => void |
Final teardown (core BlissElement): the picker is torn down for good and the element stays inert (re-inserting it warns and builds nothing — create a new element). Idempotent; isDestroyed turns true. |
whenReady |
() => Promise<void> |
Resolves once the first build is live (right after the ready event); at once when it already is. Never rejects; destroy() settles it too. |
whenSettled |
() => Promise<void> |
Resolves once every pending input write has been applied (the re-render has run) — read rendered state right after it. Immediately when nothing is pending; on the next connect while detached; only after release() while deferred (release first). |
flush |
() => void |
Apply pending input writes synchronously, now. Loose property assignments otherwise coalesce on a microtask; the picker's own imperative methods already flush first. |
batch |
(fn: () => void) => void |
Run fn and coalesce every input change it makes (attributes or properties) into a single re-render, applied synchronously. |
enableLogging |
(level?: LogLevelDesc) => void |
Set THIS element's own log level (default 'debug'; 'error' makes it quieter than its type). Levels coalesce closest first: element → window.components['web-multiselect'].logging (per category) → window.components.logging → warn. Instance debug / trace print through console.log. |
disableLogging |
() => void |
Silence this element (its own level becomes silent). |
resetLogging |
() => void |
Clear this element's own level: it follows its type / the page again. isLoggingEnabled (get) says whether an own level that prints is set. |
Type Definitions
TypeScript interfaces and types used in the API.
MultiSelectOption
| Property |
Type |
Required |
Description |
value |
string |
Yes |
Unique identifier for the option. |
label |
string |
Yes |
Display label for the option. |
icon |
string |
No |
Optional icon or emoji to display. |
subtitle |
string |
No |
Optional subtitle or description text. |
group |
string |
No |
Optional group name for grouping options. |
disabled |
boolean |
No |
Whether the option is disabled. |
SelectEventDetail / ChangeEventDetail
| Property |
Type |
Required |
Description |
selectedOptions |
MultiSelectOption[] |
Yes |
Array of currently selected options. |
selectedValues |
(string | number)[] |
Yes |
Array of selected option values. |
option |
MultiSelectOption |
No |
The specific option that triggered the event (SelectEventDetail / DeselectEventDetail only). |
controller / element |
MultiSelectController / HTMLElement |
Yes |
The public controller and the host element (non-enumerable). |
Display Modes
| Type |
Possible Values |
BadgesDisplayMode |
'badges' | 'count' | 'compact' | 'partial' | 'none' |
BadgesPosition |
'top' | 'bottom' | 'left' | 'right' |
CSS Variables
The component is themed with --ms-* CSS custom properties, set on the <web-multiselect> element itself (Shadow DOM). Most read a --base-* token from @keenmate/base-css-variables and fall back to the contract default. The most-used ones are below; docs/theming.md covers the key variables grouped by area, the complete list with defaults is the variable manifest component-variables.manifest.json (package export @keenmate/web-multiselect/manifest), and vscode.css-custom-data.json / web-types.json give editor completion for all of them.
| Variable |
Default Value |
Description |
--ms-rem |
var(--base-rem, 10px) |
Global scale unit — every size is a multiple of it (8px = 80%, 12px = 120%) |
--ms-accent-color |
var(--base-primary-color, #3b82f6) |
Accent; hover, tint and text-on-accent are derived from it |
--ms-main-bg |
var(--base-main-bg, light-dark(#ffffff, #1e293b)) |
Field / panel background |
--ms-text-color-1 |
var(--base-text-color-1, light-dark(#334155, #f1f5f9)) |
Primary text (--ms-text-color-3 for muted text) |
--ms-input-border-color |
var(--base-input-border-color, light-dark(color-mix(in srgb, var(--ms-text-color-1) 45%, var(--ms-main-bg)), color-mix(in srgb, var(--ms-text-color-1) 35%, var(--ms-main-bg)))) |
Field border (dividers use --ms-border-color) |
--ms-input-height |
calc(var(--base-input-size-md-height, 3.5) * var(--ms-rem)) |
Field height |
--ms-input-font-size |
calc(var(--base-font-size-sm, 1.4) * var(--ms-rem)) |
Field font size |
--ms-input-border-radius |
var(--ms-border-radius-md) |
Field corner radius |
--ms-option-bg-focused |
var(--ms-option-bg-hover) |
Keyboard-focused option fill |
--ms-option-disabled-bg |
var(--ms-disabled-bg) |
Disabled option row background |
--ms-badge-text-bg |
var(--ms-accent-color-light) |
Badge background |
--ms-badge-text-color |
var(--ms-accent-text-color) |
Badge text |
--ms-transition-normal |
var(--base-duration-normal, 0.15s) |
Duration of every transition (0s on the element = motion off) |
--ms-easing-snappy |
var(--base-ease-standard, cubic-bezier(0.4, 0, 0.2, 1)) |
Easing of every transition |
--ms-scroll-behavior |
var(--base-scroll-behavior, smooth) |
Programmatic scrollTo* jumps; keyboard scrolling is always instant |
--ms-disabled-opacity |
var(--base-disabled-opacity, 0.65) |
Disabled dimming |
--ms-loader-duration |
var(--base-loader-duration, 0.8s) |
Loader rotation (async search, add-new pending); 1.5s under reduced motion with base-css-variables |
--ms-z-index-dropdown |
var(--base-z-dropdown, 7500) |
Dropdown stacking |
CSS Classes
All CSS classes used by the component. Use these for custom styling or overrides.
Main Container Classes
| Class |
Description |
.ms |
Main container element |
.ms--open |
Applied when dropdown is open |
.ms--disabled |
Applied when component is disabled |
.ms--no-checkboxes |
Applied when checkboxes are hidden or in single-select mode |
Input & Toggle
| Class |
Description |
.ms__input-wrapper |
Container for input and toggle icon |
.ms__input |
Search input field |
.ms__toggle |
Dropdown toggle icon (arrow) |
.ms__counter |
Counter next to toggle icon (when showCounter is true) |
Hint Popover
| Class |
Description |
.ms__hint |
Search hint popover container |
.ms__hint--visible |
Applied when hint is visible |
Dropdown
| Class |
Description |
.ms__dropdown |
Dropdown container |
.ms__dropdown--visible |
Applied when dropdown is visible |
.ms__actions |
Container for Select All/Clear All buttons |
.ms__actions--sticky |
Applied when actions should stick to top while scrolling |
.ms__action-btn |
Individual action button (Select All/Clear All) |
.ms__options |
Container for all options |
.ms__empty |
Empty state message container |
.ms__loading |
Loading state container |
.ms__loader |
Default spinner drawn by core renderLoader() |
.ms__loading-text |
Loading message text |
Options & Groups
| Class |
Description |
.ms__group |
Group container for grouped options |
.ms__group-label |
Group label/header |
.ms__option |
Individual option container |
.ms__option--focused |
Applied to keyboard-focused option |
.ms__option--selected |
Applied to selected options |
.ms__option--disabled |
Applied to disabled options |
.ms__checkbox |
Checkbox input element |
.ms__option-content |
Container for option content (icon + text) |
.ms__option-icon |
Option icon/emoji container |
.ms__option-text |
Container for option text (title + subtitle) |
.ms__option-title |
Option main label/title |
.ms__option-subtitle |
Option subtitle/description |
Badges Display
| Class |
Description |
.ms__badges |
Container for selected item badges |
.ms__badges--top |
Badges positioned above input |
.ms__badges--bottom |
Badges positioned below input (default) |
.ms__badges--left |
Badges positioned to the left of input |
.ms__badges--right |
Badges positioned to the right of input |
.ms__badge |
Individual badge element |
.ms__badge-text |
Badge label text |
.ms__badge-remove |
Badge remove button (×) |
Count Display
| Class |
Description |
.ms__count-display |
Container for count display mode |
.ms__count-display--top |
Count positioned above input |
.ms__count-display--bottom |
Count positioned below input |
.ms__count-display--left |
Count positioned to the left of input |
.ms__count-display--right |
Count positioned to the right of input |
.ms__counter-wrapper |
Wrapper containing count text and clear button |
.ms__count-text |
Count text button (clickable to show popover) |
.ms__count-clear |
Clear all button in count display (×) |
Selected Items Popover
| Class |
Description |
.ms__selected-popover |
Popover showing selected items (in count mode) |
.ms__selected-popover--visible |
Applied when popover is visible |
.ms__selected-popover-header |
Popover header with title and close button |
.ms__selected-popover-close |
Close button in popover header |
.ms__selected-popover-body |
Scrollable body containing selected badges |