A lightweight, themeable multi-select web component with typeahead search, RTL support, rich content, and full keyboard navigation.
- 🚀 Showcase
- 🧪 Live demo
- 📘 Usage / API reference — attributes, properties, methods, events.
- 🎨 Theming —
--ms-*variables, dark mode, cascade layers, Theme Designer integration. - 📚 Examples / cookbook — rich content, async search, virtual scroll, custom rendering, forms.
- ♿ Accessibility — keyboard model, ARIA labels, focus behavior.
@keenmate/web-multiselect is a custom element (<web-multiselect>) that turns a list of options into a searchable, themeable multi-select dropdown. Framework-agnostic — works in React, Vue, Svelte, Blazor, plain HTML.
Reads the --base-* tokens from @keenmate/base-css-variables 2.0 when the page loads them (the shared layer behind pure-admin and the Theme Designer), falls back to sensible OS-aware defaults otherwise, and ships with first-class dark-mode and per-instance theming.
Headline features:
- Declarative
<option>/<optgroup>markup — no JavaScript required for simple cases. - Virtual scrolling for 10,000+ option datasets (25× faster opening, 99.8% memory reduction).
- Filter or navigate search modes; async / hybrid search.
- Five badge display modes (badges, count, compact, partial, none) with positioning on any side.
- Tree mode with cascade / independent checkboxes; phone-friendly fullscreen presentation.
- Full keyboard navigation, RTL language support, badge tooltips.
- Custom rendering callbacks for options, badges, and group headers.
- Form integration via standard hidden inputs (FormData-compatible).
Upgrade guide: the 3.0.0-rc04 release notes; full list: the CHANGELOG 3.0.0-rc04 section.
- Labels — flat
<elementType>.<name>keys, page-wide dictionary,translateCallback— Every UI string now resolves through core/locale, so thelabelskeys take core's flat shape:noResultsismessages.noResults,searchPlaceholderisplaceholders.search,selectAllisbuttons.selectAll. A string that fed both anaria-labeland a tooltip is split into anariaLabels.*/tooltips.*pair, and an unset twin follows a customized one, so translating one translates both. A dynamic text passes its context, so templates read{ctx.*}—'+{ctx.count} more','Add "{ctx.value}"','Picked {ctx.selectedCount} of {ctx.totalCount}'for a placeholder — andctx.countis the number the noun agrees with, ready for an i18n library's plurals. A whole page translates withwindow.components.locale.labels = { 'web-multiselect.messages.noResults': '…' }or atranslateCallback({ key, template, params, locale })that gets the context raw asparams.ctx— page-wide, or on one element through the newtranslateCallbackproperty, asked first. The old keys and{count}/{item}/{value}templates have no aliases. - Selection —
max-selected-count— A new limit on the user's picks in multiple mode: at the limit the other options turnaria-disabledand can't be picked by click, keyboard, a group checkbox or "add new", Select All picks only up to the limit in display order, and reaching it is announced. The placeholder reads the picks left —labels: { 'placeholders.search': 'Select up to {ctx.remaining} more' }— andctx.countis that number, so atranslateCallbackplural agrees with it. A value the app sets (el.value,setSelected()) is not truncated. - Forms —
required,min-selected-count, validity —requiredmakes an empty selection invalid (validity.valueMissing) so the form won't submit and the browser's bubble points at the input;min-selected-count="3"flags 1–2 picks asrangeUnderflow, and a value set abovemax-selected-countisrangeOverflow, each its own flag so an app can tell "empty" from "too few". Messages are labels (errors.required,errors.minSelected,errors.maxSelected) and the placeholder can count down with{ctx.missing}. Readonly and disabled controls are never invalid. - Locale —
localeinput and formatted counts — A newlocaleattribute (cs-CZ, BCP-47) sets the instance locale; unset, it followswindow.components.locale, then the browser. Counts in labels and the[N]count chip are formatted for it (1 234in Czech,1,234in en-US), whiletranslateCallbackandgetCountLabelCallbackstill get the raw numbers. Changing it, or assigningwindow.components.locale, re-renders the labels with the selection kept. - Icons — core's icon order,
renderIconCallback— Optionicon,getIconCallbackand action-buttoniconstrings render through corerenderIcon: markup is inserted raw, a built-in name (check,close,settings, …) draws the masked--base-icon-*glyph, the element's newrenderIconCallback(name, ctx)and then the page-wide one may map anything else, and remaining ASCII class names become<i class="ms__icon fa-solid fa-flag">. A one-word name that is not a built-in (star) is therefore an icon-font class now. Changing either hook after the picker rendered repaints the icons in place, keeping the selection, search and an open dropdown. - Accessibility — combobox / listbox — The search field is a
role="combobox"over arole="listbox"ofrole="option"rows witharia-selected/aria-disabled, andaria-activedescendantfollows the keyboard highlight while focus stays in the field (core/a11y). The row checkboxes are decorative now. Typing is IME-safe: composing doesn't search, and the Enter that confirms a candidate doesn't pick. The group count chip is finally spoken as10 selectedinstead of[10]. - API —
MultiSelectEngineremoved, render callbacks on core's contract —MultiSelectEngineis no longer exported; it drew the same UI without the element, so use<web-multiselect>withel.controllerandel.setAttributes(). The render callbacks (renderOptionContentCallback,renderGroupLabelContentCallback,renderBadgeContentCallback,renderSelectedItemContentCallback,renderBadgeCallback) follow core's one result contract:null/undefinednow draws the built-in content instead of an empty slot, andfalseleaves it empty. - Forms and stacking — no hidden-input
id, the sheet is the modal tier — The single hidden form input no longer getsid = name, which put duplicate ids in the page and made<label for>/getElementByIdfind it; select it by name. The fullscreen phone sheet stacks at--base-z-modal(7000) like every Keenmate dialog and drawer, so page toasts and tooltips stay visible over it. - Motion — tooltips fade out too — Badge and option tooltips take their motion from core
createTooltip: a short fade and slide toward the anchor on show and on hide, timed by--base-duration-fastand instant undermotion="none"or OS reduced motion.showMessage()also fades out instead of vanishing, and is announced through coreannounce().
Upgrade guide: the 3.0.0-rc03 release notes; full list: the CHANGELOG 3.0.0-rc03 section.
- Phone sheets — core's sheet chrome,
--ms-sheet-*variables — The fullscreen dropdown and the fullscreen selected-items popover now draw their top bar, title and ✕ with core's shared sheet chrome, so they look like every other Keenmate phone sheet (a 44px close chip, the--base-icon-closeglyph). The bar's variables are renamed from--ms-fullscreen-header-*/-title-*/-close-*to--ms-sheet-*, with the same 19 suffixes as core's page-wide--km-sheet-*. They are unset by default, and the--ms-fullscreen-header-paddingshorthand is gone. Back still closes the sheet, now through coreclaimBackEntry(), and the page keeps its scroll position. - Dropdown — closes on scroll, says why it closed — The dropdown runs on core
createPopover()and, like a native select, now closes when the page or a scroller around it scrolls (close-on-scroll, defaulttrue; a scroll inside the list never closes it). Thecloseevent carriesdetail.reason(escape,outside-click,scroll,select,reference-removed, …). The selected-items popover moved to core's overlay tree too, so opening another overlay closes it. - Inputs — length inputs are CSS lengths —
dropdown-min-width,dropdown-max-width,max-height,dropdown-widthandselected-popover-widthare parsed by coretoCssLength(). A bare number means px, an invalid length ornullis refused with aninput-rejectedevent, and removing the attribute resets it. - Messages —
variantanddanger—showMessage()takes{ variant }instead of{ type }, and'error'is now'danger', matching the rest of Keenmate. The class is.ms__message--dangerand the variables are--ms-message-danger-bg/-color. There are no aliases. - Scrolling —
beforeScrollCallback— Every scroll the dropdown does on its own (keyboard moves, navigate-mode search, revealing the selection on open,scrollToIndex/scrollToValue/scrollToGroup) now goes throughbeforeScrollCallback(ctx). Returnfalseto skip it, or{ block, behavior }to change it.ctx.sourcesays what triggered it. Virtual lists also honour--ms-options-paddingandscroll-paddingon a jump, so the last row comes fully into view. - Theming — page-wide custom CSS, tooltip widths, dropdown gap —
window.components['web-multiselect'].customStylesstyles every instance (an instance's owncustomStylesstill wins), and an@importin it now registers icon fonts. New--ms-tooltip-width/--ms-tooltip-min-width(with option-tooltip twins) complete the tooltip width model. The field-to-panel gap is the page token--base-dropdown-offset. - Fixes — controller under disabled / readonly, WebKit Backspace —
el.controller.selectAll(),selectValue(),clearSelection()and the other selection methods used to be silently ignored on a disabled or readonly control; calls from code now work, and only user gestures are blocked. In Safari, Backspace in a read-only input no longer navigates the page Back.
Earlier releases: 3.0.0-rc02, 3.0.0-rc01, 2.6.0-rc03, 2.6.0-rc02, CHANGELOG.
npm install @keenmate/web-multiselectDeclarative — no JavaScript required:
<script type="module">
import '@keenmate/web-multiselect';
</script>
<web-multiselect labels='{"placeholders.select": "Pick a country"}'>
<option value="cz">Czech Republic</option>
<option value="sk">Slovakia</option>
<option value="at">Austria</option>
</web-multiselect>Programmatic — dynamic data + events:
<web-multiselect id="picker" labels='{"placeholders.search": "Search…"}'></web-multiselect>
<script type="module">
import '@keenmate/web-multiselect';
const picker = document.getElementById('picker');
picker.options = [
{ value: 'js', label: 'JavaScript', icon: '🟨' },
{ value: 'ts', label: 'TypeScript', icon: '🔷' },
{ value: 'py', label: 'Python', icon: '🐍' }
];
picker.addEventListener('change', (e) => {
console.log('Selected:', e.detail.selectedValues);
});
</script>See docs/usage.md for the full API and docs/examples.md for advanced patterns (async data, virtual scrolling, custom rendering, form integration).
Tune what the picker does per device or window width without app-side viewport code — a map
of partial configs, or a callback that computes one. A map has two axes, each keyed
mobile / tablet / desktop:
device— the device class (classifyDevice): a phone / tablet by capability (touch-primary, then the short side); a mouse device isdesktopat any width.breakpoint— the window width bucket (768 / 1024px lines,--base-breakpoint-*): a narrowed desktop window ismobilebelow 768px.
Within one map the breakpoint entry applies first and the device entry over it (device wins
on the same key). Own widths or combinations (ctx.env.viewportWidth, device class AND
width, …) go in a responsiveCallback. Keys are configKeys; set them page-wide, per tag
or per instance
(the generic core mechanism, core SPEC §6.7):
// page-wide (every Keenmate component) and per tag — may be set before the script loads
window.components.responsive = { device: { mobile: { presentation: 'fullscreen' } } };
window.components['web-multiselect'].responsiveCallback = (ctx) =>
ctx.deviceClass === 'mobile' ? { actionsLayout: 'wrap' } : undefined;
// per instance (property, or the JSON attribute responsive='{"device":{"tablet":{…}}}')
el.responsive = {
device: { tablet: { presentation: 'fullscreen' } }, // a touch tablet
breakpoint: { mobile: { badgesDisplayMode: 'count' } }, // any window under 768px
};
el.responsiveCallback = (ctx) => (ctx.env.orientation === 'landscape' ? { badgesThreshold: 5 } : undefined);Precedence (later wins, key by key): global map → global callback → per-tag map → per-tag
callback → the instance's own attributes / properties → instance map → instance callback.
An attribute written on an element is never overridden by a page rule; null from the
instance callback ignores every page rule. Maps re-run when the device class / breakpoint
changes, callbacks also on every viewport resize; overrides never reflect to attributes. The
pre-rc15 device-keyed shape ({ mobile: … }) warns and is ignored. Typed as MultiSelectResponsiveMap /
MultiSelectResponsiveCallback. Demo: examples-responsive.html, examples-action-buttons.html.
Errors and warnings print out of the box (the default level is warn); info / debug / trace are
opt-in. Levels coalesce, closest first:
| Scope | API |
|---|---|
| Element | el.enableLogging(level?) (default debug; 'error' makes it quieter than its type), el.disableLogging() silences this element, el.resetLogging() — it follows its type / the page again |
Type (per category INIT / DATA / UI / INTERACTION) |
window.components['web-multiselect'].logging — enableLogging, disableLogging, setLogLevel, setCategoryLevel(cat, level | null), resetLogging; the same functions are exported from the package |
| Page | window.components.logging — every component on the page |
| Default | warn |
A page call never overwrites a type level, so the order of calls doesn't matter. Instance
debug / trace lines print through console.log. See examples-logging.html.
The package ships editor metadata so you get autocomplete and hover docs for the
element's attributes, events, and all --ms-* CSS custom properties. All of it is
generated from the component's source on every build, so it never drifts.
-
JetBrains (WebStorm / IntelliJ) — works automatically. The IDE discovers
web-types.jsonvia theweb-typesfield inpackage.json; no setup needed. -
VS Code — the data files ship but VS Code doesn't auto-discover them from a dependency, so point your workspace at them once in
.vscode/settings.json:{ "html.customData": [ "./node_modules/@keenmate/web-multiselect/vscode.html-custom-data.json" ], "css.customData": [ "./node_modules/@keenmate/web-multiselect/vscode.css-custom-data.json" ] }html.customDatapowers tag/attribute completion on<web-multiselect>;css.customDatapowers completion for the--ms-*theming variables. Reload the window after adding them.
These inputs are inserted as raw HTML — intentionally not XSS-safe, so you control the markup. Sanitize any untrusted text before passing it in:
| Input | Output used in |
|---|---|
labels['messages.noData'], labels['messages.noResults'], labels['messages.searching'] |
Dropdown empty / searching text (innerHTML) |
labels['labels.addNew'], labels['messages.addNewPending'] |
"Add new" prompt (innerHTML; the typed {ctx.value} is escaped) |
labels['labels.selectedCount'], labels['labels.moreCount'] |
Counter badge text (innerHTML) |
renderOptionContentCallback, renderGroupLabelContentCallback, renderBadgeContentCallback, renderBadgeCallback, renderSelectedItemContentCallback (string return) |
Option rows, group headers, badges, selected panels (innerHTML) |
Display value (displayValueMember / getDisplayValueCallback) |
Option title and badge text (innerHTML; search highlighting marks text runs only) |
getBadgeDisplayCallback |
Badge text (innerHTML) |
Full title (fullTitleMember / getFullTitleCallback) |
Badge text when isBadgeFullTitleShown (innerHTML) |
Subtitle (subtitleMember / getSubtitleCallback) |
Option subtitle (innerHTML) |
Icon (iconMember / getIconCallback), action-button icon |
Option / action-button icon when it starts with < (innerHTML); a built-in name (check) is a --base-icon-check mask, then renderIconCallback / the page-wide hook (their markup is innerHTML), class names (fa-solid fa-flag) an icon-font <i>, anything else text |
All other labels (ARIA labels, tooltips, placeholders, popover title, action-button texts) are
plain text, as are showMessage() strings and renderSelectedContentCallback (the closed input's value).
Option values and tree paths are escaped (they only ever land in attributes); the display value,
full title, subtitle and icon are HTML — sanitize untrusted data first.
Modern evergreen browsers — the standalone colour fallbacks use CSS relative-colour syntax (oklch(from …)), the same floor as @keenmate/base-css-variables 2.x:
- Chrome / Edge 119+
- Firefox 128+
- Safari 18+
No polyfills are shipped. SSR-safe: the module imports without crashing in Node, but renders only after hydration in the browser.
# Install dependencies
npm install
# Start dev server (HMR)
npm run dev
# Build for production
npm run build
# Create package tarball
npm run package
# Run tests
npm run test:unit # Vitest (happy-dom) — fast logic checks
npm run test:e2e # Playwright (browser) — interaction/visual
npm test # bothFollows the BlissFramework four-layer web-component layout:
| Layer | File | Role |
|---|---|---|
| Element | src/web-component.ts |
MultiSelectElement — custom-element I/O wrapper, driven by the INPUTS table (attributes, properties, callbacks) and the events table |
| Logic | src/multiselect.ts |
MultiSelectEngine<T> — internal engine (search, selection, keyboard, rendering); not exported — the element is the API |
| Service | src/virtual-scroll.ts, src/tree/ |
VirtualScroll; the ltree option model and checkbox cascade for tree mode |
| Side | src/types.ts, src/option-formats.ts, src/converters.ts, src/logger.ts, src/index.ts |
types, data-options parsers, component-local converters, logging shim, package entry |
Positioning (dropdown, popovers, tooltips), attribute parsing and reflection, and the logging engine come from @keenmate/web-components-core.
Two deviations from the canonical shape, both intentional:
MultiSelectElement extends BlissElement, notHTMLElementdirectly. Core'sBlissElementresolves toHTMLElementin the browser and to a stub class under SSR (typeof HTMLElement === 'undefined'), so importing the module in Node doesn't throw. A literalgrep "extends HTMLElement"structure check will not match here by design.src/vite-env.d.tsis a standard Vite ambient-types file, not part of the four-layer model.
MIT — see LICENSE.
Follows the BlissFramework component guidelines for structure, theming, color-scheme, and accessibility. Per-check verifications run via /validate-web-component.
Created by Keenmate as part of the Pure Admin design system.