npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

html-combobox-element

v0.0.8

Published

The combo-box web-component & customizable select polyfill

Readme

HTMLComboboxElement

A customizable, and fully HTMLSelectElement compatible web component, with both dropdown and combobox functionality. In other words – the <select> and <selectedcontent> polyfill.

Key features

Like a native <select>:

  • It is seamlessly exposed to assistive technology;
  • Fully participate in HTML forms;
  • Is fully controllable by keyboard, including type-ahead;
  • Supports the same CSS pseudo-classes: :disabled, :required, :invalid etc.;
  • Dispatches same events: change, input, reset etc.;
  • Supports single and multiple modes;
  • Supports <optgroup> and has the same markup style.

And – its fully customizable. Itself, its options and chips.

Install

npm install html-combobox-element

Register – once in app entry point

import 'html-combobox-element';

This registers the <combo-box>, <box-option> and <box-tag> custom elements with full TS support.

Usage

<combo-box multiple required>
  <box-option value="apple" selected>
    Apple
  </box-option>
  
  <optgroup label="Group">
    <box-option value="banana" selected>
      Banana
    </box-option>
    <box-option value="cherry">
      Cherry
    </box-option>
  </optgroup>
</combo-box>

Differences from <select>

  • In multiple mode, the combobox.value lists every selected value, where select.value gives only the first;
  • In multiple mode, the selected values are displayed as chips;
  • In singlemode, the <combo-box> without a selected option stays empty, where a <select> selects its first option.

Events – type: when

  • change: The user changed the selection. Once per action, only when the value changed.
  • input: The user typed in the search field. It is the field's own InputEvent.
  • close: The dropdown closed.
  • search: The user pressed Enter in the search field
  • reset: The form was reset

Read from event:

  • event.target.changed: tells whether the value differs from when it opened;
  • event.target.query: tells the search field current text;
  • event.target.value: the combobox selection;
  • event.target.valueAsArray: the combobox selection as an array of strings.

Like native form controls, changes made by script dispatch no change. Framework bindings that assume input means "the value changed" need the change event instead.

Attributes

All <select>'s attributes are supported, and few extra:

  • filterable: Displays search field in picker; options are automatically filtered against input value;
  • searchable: Displays search field in picker; you listen for input events and implement own filter. Usefully for fuzzy search, etc.;
  • placeholder: The combobox own placeholder, shown when there is no selection;
  • query: The search field input value.

Options API

Like select.options, combobox.options is a live collection too, but a fully compatible polyfill – HTMLComboboxOptionsCollection, because HTMLOptionsCollection can't be constructed or subclassed. The only difference between select.options and combobox.options, is that combobox.options will false on instanceof HTMLOptionsCollection check. The <box-option> itself has the same API as native <option>. It exists, because the <option> can't be styled at all.

Accessibility

  • Roles and states are set through ElementInternals, and mirrored as role and ariaattributes, so tools that read the DOM can see it too.
  • The host itself takes focus, so screen readers announce the combobox with its label and value.
  • The arrow keys, Home/End, PageUp/PageDown, Enter, Space, Escape and type-ahead work as in the select-only combobox pattern.
  • Name it with a <label>, aria-label or aria-labelledby.
  • With searchable or filterable attributes, the popup is a dialog holding the search field and the listbox.
  • With clearable and/or multiple attribute, the selected values are a list, each with a "Remove " button. Those texts can be localized:
import { HTMLComboboxElement } from 'html-combobox-element';

HTMLComboboxElement.strings.removeTag = 'Удалить';        // "Удалить Банан"
HTMLComboboxElement.strings.clearAll = 'Очистить выбор';

Example of produced accessibility tree in Chrome

combobox "Fruit"  value="Banana"  expanded=true  hasPopup=listbox  controls=…
  listbox                         (multiselectable with `multiple`)
    option "Apple"   selected=false
    option "Banana"  selected=true
    option "Cherry"  disabled=true

Known Chrome limitation

Chrome does not expose the value of a disabled <combo-box>, because it computes the value of an ARIA combobox only while it is focusable.

Testing with Playwright

Playwright's getByRole() / ariaSnapshot() and Testing Library's *ByRole work:

await page.getByRole('combobox').focus();
await page.getByRole('option', { name: 'Cherry' }).click();
await expect(page.getByRole('option', { selected: true })).toHaveText('Cherry');

Playwright's selectOption(), toHaveValue(), toHaveValues() and getByLabel() work on <combo-box> like on <select> once you register in your fixtures the helper from html-combobox-element/playwright:

// fixtures.ts
import { test as base } from '@playwright/test';
import { registerCombobox } from 'html-combobox-element/playwright';

export const test = base.extend<{}, { combobox: void }>({
  combobox: [async ({ playwright }, use) => {
    await registerCombobox(playwright.selectors);
    await use();
  }, { scope: 'worker', auto: true }],
});
export { expect } from '@playwright/test';
// any.spec.ts
import { test, expect } from './fixtures';

test('pick a fruit', async ({ page }) => {
  await page.getByLabel('Fruit').selectOption('banana'); // by value or label
  await page.getByLabel('Fruits').selectOption(['apple', 'cherry']);
  await expect(page.getByLabel('Fruit')).toHaveValue('banana');
  await expect(page.getByLabel('Fruits')).toHaveValues(['apple', 'cherry']);
});

Why helper is needed

Playwright runs its own page-side code in an isolated JavaScript world, which shares the DOM with your page but not its JavaScript, so the HTMLComboboxElement class doesn't exist there. The helper registers a selector engine with contentScript: true, which is the Playwright's public way to run code in that world. That teaches it the <select> API of <combo-box> through the DOM only. Your page's own JavaScript is not touched.

One difference with screen readers

Playwright names a custom element from <label for> only for native controls, so query getByRole('combobox', { name }) with aria-label or aria-labelledby on the <combo-box>, or without a name.

TypeScript and JSX frameworks

import 'html-combobox-element' also brings the typings for:

  • document.createElement('combo-box');
  • querySelector;
  • addEventListener with a typed event.target.

Event listeners attached through the props

The props are the same everywhere, but which handlers get called, and with what, depends on the framework:

| Handler prop | React 19 | React 18 | Vue/Preact/SolidJS | |--------------|---|---|--------------------| | onInput | SyntheticEvent | SyntheticEvent | DOM event | | onChange | SyntheticEvent | never called | DOM event | | onsearch | DOM event | never called | DOM event | | oninvalid | DOM event | never called | DOM event | | onreset | DOM event | never called | DOM event | | onclose | DOM event | never called | DOM event | | onClose | never called | never called | DOM event | | onSearch | never called | never called | DOM event | | onReset | never called | never called | DOM event | | onInvalid | never called | never called | DOM event |

The combobox.addEventListener(type, cb) works seamlessly in all frameworks.

Boolean props

The multiple, clearable, disabled, ... behave like native ones in every framework, except that the string 'false' is also false, i.e. turns the feature off.

React

Package ships types, for jsx: "react-jsx", "react-jsxdev" and classic "react". Handlers are typed accordingly: onChange, onInput, onFocus, onClick, ... receive a SyntheticEvent: event.target is the <combo-box>, event.nativeEvent is the DOM event.

  • In React 19, events it doesn't know ("close", "search") are attached as native listeners under the exact, case-sensitive name, so use onclose and onsearch.
  • In React 18, listen to change, close and search on the element itself through the ref.
  • In a project written in React, but aliased to Preact at build time – types may confuse. Rely on runtime behaviour, rather than on Typescript errors.

Preact and SolidJS

Nothing to do, everything just work.

Vue

Vue template compiler treats unknown tags as Vue components by default. You must tell it to treat <combo-box>, <box-option> and <box-tag> tags as custom elements.

Monorepos and microservices

The typings are part of a TypeScript program only if the program includes this package. A workspace package that renders <combo-box> but leaves the import to the app shell type-checks inside the app, but not on its own (its CI, editor, project references). Add a type-only import there - it's removed from the JS output, nothing is registered twice:

import type {} from 'html-combobox-element';