html-combobox-element 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +139 -24
  2. package/dist/cjs/combobox/Combobox.markup.d.ts +22 -1
  3. package/dist/cjs/combobox/Combobox.markup.js +156 -35
  4. package/dist/cjs/combobox/HTML.combobox.element.d.ts +32 -5
  5. package/dist/cjs/combobox/HTML.combobox.element.js +431 -98
  6. package/dist/cjs/combobox/HTML.combobox.option.element.d.ts +25 -4
  7. package/dist/cjs/combobox/HTML.combobox.option.element.js +104 -73
  8. package/dist/cjs/combobox/HTML.combobox.options.collection.d.ts +37 -0
  9. package/dist/cjs/combobox/HTML.combobox.options.collection.js +176 -0
  10. package/dist/cjs/combobox/HTML.combobox.tag.element.d.ts +7 -1
  11. package/dist/cjs/combobox/HTML.combobox.tag.element.js +36 -12
  12. package/dist/cjs/combobox/index.d.ts +1 -0
  13. package/dist/cjs/combobox/index.js +1 -0
  14. package/dist/cjs/playwright.d.ts +48 -0
  15. package/dist/cjs/playwright.js +127 -0
  16. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  17. package/dist/esm/combobox/Combobox.markup.js +156 -35
  18. package/dist/esm/combobox/HTML.combobox.element.js +431 -98
  19. package/dist/esm/combobox/HTML.combobox.option.element.js +104 -73
  20. package/dist/esm/combobox/HTML.combobox.options.collection.js +170 -0
  21. package/dist/esm/combobox/HTML.combobox.tag.element.js +36 -12
  22. package/dist/esm/combobox/index.js +1 -0
  23. package/dist/esm/playwright.js +123 -0
  24. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  25. package/dist/types/combobox/Combobox.markup.d.ts +22 -1
  26. package/dist/types/combobox/HTML.combobox.element.d.ts +32 -5
  27. package/dist/types/combobox/HTML.combobox.option.element.d.ts +25 -4
  28. package/dist/types/combobox/HTML.combobox.options.collection.d.ts +37 -0
  29. package/dist/types/combobox/HTML.combobox.tag.element.d.ts +7 -1
  30. package/dist/types/combobox/index.d.ts +1 -0
  31. package/dist/types/playwright.d.ts +48 -0
  32. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  33. package/package.json +18 -5
@@ -1,7 +1,9 @@
1
1
  import { HTMLComboboxOptionElement } from './HTML.combobox.option.element.js';
2
+ import { HTMLComboboxOptionsCollection } from './HTML.combobox.options.collection.js';
2
3
  export declare class HTMLComboboxElement extends HTMLElement {
3
4
  #private;
4
5
  static OWN_IDL: Set<string>;
6
+ static observedAttributes: string[];
5
7
  static observerOptions: {
6
8
  childList: boolean;
7
9
  };
@@ -9,6 +11,11 @@ export declare class HTMLComboboxElement extends HTMLElement {
9
11
  static formAssociated: boolean;
10
12
  shadowRoot: ShadowRoot;
11
13
  constructor();
14
+ /** Texts used only by assistive technology, override them to localize. */
15
+ static get strings(): {
16
+ clearAll: string;
17
+ removeTag: string;
18
+ };
12
19
  connectedCallback(): void;
13
20
  insertBefore: <T extends Node>(node: T, referenceNode: Node | null) => T;
14
21
  appendChild: <T extends Node>(node: T) => T;
@@ -19,8 +26,9 @@ export declare class HTMLComboboxElement extends HTMLElement {
19
26
  replaceChild: <T extends Node>(newChild: Node, oldChild: T) => T;
20
27
  get changed(): boolean;
21
28
  disconnectedCallback(): void;
29
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
22
30
  formResetCallback(): void;
23
- formDisabledCallback(): void;
31
+ formDisabledCallback(disabled: boolean): void;
24
32
  get valueAsArray(): string[];
25
33
  get query(): string;
26
34
  set query(value: string);
@@ -37,22 +45,41 @@ export declare class HTMLComboboxElement extends HTMLElement {
37
45
  get form(): HTMLFormElement;
38
46
  get labels(): NodeList;
39
47
  get length(): number;
48
+ /** Like `select.length = n`: appends blank options, or removes the last ones */
49
+ set length(value: number);
40
50
  get multiple(): boolean;
41
51
  set multiple(value: boolean);
52
+ /** The options, as a live `HTMLOptionsCollection`-like list (like `select.options`) */
53
+ get options(): HTMLComboboxOptionsCollection;
42
54
  get required(): boolean;
43
55
  set required(value: boolean);
56
+ /** Index of the first selected option, or -1. Setting it selects only that option. */
57
+ get selectedIndex(): number;
58
+ set selectedIndex(value: number);
44
59
  get selectedOptions(): NodeListOf<HTMLComboboxOptionElement>;
45
60
  get type(): "select-multiple" | "select-one";
46
61
  get validationMessage(): string;
47
62
  get validity(): ValidityState;
48
63
  get willValidate(): boolean;
49
- get value(): string;
50
- set value(value: string);
51
- checkValidity(): void;
64
+ get value(): string | null | undefined;
65
+ set value(value: string | null | undefined);
66
+ /** Like `select.add()`: inserts an option or optgroup before `before` (an element or an index), or at the end */
67
+ add(element: HTMLComboboxOptionElement | HTMLOptGroupElement, before?: HTMLElement | number | null): void;
68
+ checkValidity(): boolean;
52
69
  item(index: number): HTMLComboboxOptionElement;
53
- reportValidity(): void;
70
+ /** The first option whose `id` or `name` attribute is `name` */
71
+ namedItem(name: string): HTMLComboboxOptionElement;
72
+ /**
73
+ * Overloaded like `select.remove()`: without an argument removes the combobox itself
74
+ * (`Element.remove()`), with an index removes that option.
75
+ */
76
+ remove(): void;
77
+ remove(index: number): void;
78
+ reportValidity(): boolean;
54
79
  setCustomValidity(message: string): void;
55
80
  showPicker(): void;
81
+ /** Closes the dropdown, if open */
82
+ hidePicker(): void;
56
83
  setAttribute(name: string, value: any): void;
57
84
  removeAttribute(name: string): void;
58
85
  static loadCssFromUrls(urls: string[]): void;
@@ -1,24 +1,45 @@
1
+ /**
2
+ * The `<option>` of `<combo-box>`.
3
+ *
4
+ * The browser only knows what `selected`/`disabled` mean on a native `<option>`, so the role and
5
+ * both states are set through ElementInternals, and mirrored as `role`, `aria-selected` and
6
+ * `aria-disabled` attributes. Internals are invisible from outside the element, so the attributes
7
+ * are what tools reading the DOM (Playwright's getByRole, Testing Library, axe) can see.
8
+ * Both say the same thing; for the browser an attribute takes precedence over internals.
9
+ *
10
+ * Attributes and properties:
11
+ * - Setters (and the setAttribute/removeAttribute overrides that route to them) only normalize
12
+ * the value and write the attribute.
13
+ * - attributeChangedCallback applies the side effects (state, ARIA, notifying the combobox).
14
+ * It's the one hook the browser calls for every way an attribute can change: the setters,
15
+ * the native Element.prototype methods, setAttributeNS/setAttributeNode, DevTools, and other
16
+ * JavaScript worlds (test runners, extensions) that can't see this class at all.
17
+ */
1
18
  export declare class HTMLComboboxOptionElement extends HTMLElement {
2
19
  #private;
3
20
  static OWN_IDL: Set<string>;
21
+ static observedAttributes: string[];
4
22
  static EventInit: {
5
23
  bubbles: boolean;
6
24
  cancelable: boolean;
7
25
  composed: boolean;
8
26
  };
9
- static captureFocus(event: FocusEvent): void;
10
- static onNavigate(event: KeyboardEvent): void;
27
+ constructor();
11
28
  connectedCallback(): void;
12
- disconnectedCallback(): void;
29
+ /** Like <option>: the value attribute, or the text when there is none */
13
30
  get value(): string;
14
31
  set value(value: string);
32
+ /** Like <option>: the label attribute when present, otherwise the text */
15
33
  get label(): string;
16
34
  set label(value: string);
35
+ /** Like <option>: the text content with whitespace stripped and collapsed */
36
+ get text(): string;
37
+ set text(value: string);
17
38
  get selected(): boolean;
18
39
  set selected(value: boolean);
19
40
  get disabled(): boolean;
20
41
  set disabled(value: boolean);
42
+ attributeChangedCallback(name: 'selected' | 'disabled', _oldValue: string | null, newValue: string | null): void;
21
43
  setAttribute(name: string, value: string): void;
22
44
  removeAttribute(name: string): void;
23
- toggleAttribute(name: string, force?: boolean): boolean;
24
45
  }
@@ -0,0 +1,37 @@
1
+ import { HTMLComboboxOptionElement } from './HTML.combobox.option.element.js';
2
+ interface CollectionSource {
3
+ /** The listbox the options live in (inside the combobox shadow root) */
4
+ container: () => HTMLElement;
5
+ /** Live list of the options, in tree order (optgroup children included) */
6
+ options: () => NodeListOf<HTMLComboboxOptionElement>;
7
+ }
8
+ /**
9
+ * The `options` of a `<combo-box>`: an implementation of `HTMLOptionsCollection`, whose constructor
10
+ * is not exposed (it can't be constructed or subclassed). Same behaviour as `select.options`:
11
+ * it is live, supports `options[i]` (also as an assignment target), `length` (also settable),
12
+ * `item()`, `namedItem()`, `add()`, `remove()`, `selectedIndex` and iteration.
13
+ */
14
+ export declare class HTMLComboboxOptionsCollection {
15
+ #private;
16
+ [index: number]: HTMLComboboxOptionElement;
17
+ constructor(source: CollectionSource);
18
+ get [Symbol.toStringTag](): string;
19
+ [Symbol.iterator](): IterableIterator<HTMLComboboxOptionElement>;
20
+ get length(): number;
21
+ /** Like `select.options.length = n`: appends blank options, or removes the last ones. */
22
+ set length(value: number);
23
+ item(index: number): HTMLComboboxOptionElement | null;
24
+ /** The first option whose `id` or `name` attribute is `name` */
25
+ namedItem(name: string): HTMLComboboxOptionElement | null;
26
+ /**
27
+ * Inserts an option (or optgroup) before `before` (an option/optgroup of this list, or an index),
28
+ * or at the end. Throws like `select.options.add()`.
29
+ */
30
+ add(element: HTMLComboboxOptionElement | HTMLOptGroupElement, before?: HTMLElement | number | null): void;
31
+ /** Removes the option at `index` (does nothing when out of range) */
32
+ remove(index: number): void;
33
+ /** Index of the first selected option, or -1. Setting it selects only that option. */
34
+ get selectedIndex(): number;
35
+ set selectedIndex(value: number);
36
+ }
37
+ export {};
@@ -1,12 +1,18 @@
1
+ /**
2
+ * A selected value shown inside `<combo-box>`. The tags are exposed as a list of items,
3
+ * each with a "Remove …" button when the combobox is `clearable` or `multiple`.
4
+ */
1
5
  export declare class HTMLComboboxTagElement extends HTMLElement {
6
+ #private;
2
7
  static EventInit: {
3
8
  bubbles: boolean;
4
9
  cancelable: boolean;
5
10
  composed: boolean;
6
11
  };
12
+ constructor();
7
13
  get value(): string;
8
14
  connectedCallback(): void;
9
15
  disconnectedCallback(): void;
10
16
  static onClearTag(event: Event): void;
11
- static captureFocus(event: Event): void;
17
+ static onControlKeyDown(event: KeyboardEvent): void;
12
18
  }
@@ -1 +1,2 @@
1
1
  export * from './HTML.combobox.element.js';
2
+ export * from './HTML.combobox.options.collection.js';
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Makes Playwright's `selectOption()`, `toHaveValue()` and `toHaveValues()` work on `<combo-box>`
3
+ * as they do on `<select>`.
4
+ *
5
+ * Why it's needed: Playwright runs its page-side code in an isolated JavaScript world. That world
6
+ * shares the DOM with the page, but not the page's JavaScript: the `<combo-box>` class (its
7
+ * `options`, `value`, `multiple`, …) doesn't exist there, so Playwright sees a plain element and
8
+ * refuses it ("Element is not a <select> element").
9
+ *
10
+ * What it does: Playwright's custom selector engines registered with `contentScript: true` are
11
+ * evaluated in that isolated world. This "engine" selects nothing; evaluating it teaches the
12
+ * isolated world the `<select>` API of `<combo-box>`/`<box-option>`, implemented through the DOM
13
+ * only (attributes, shadow root). `<combo-box>` reacts to `selected` attributes changed from any
14
+ * world, so this drives the real component.
15
+ *
16
+ * It never touches the page's own world, so the application under test sees no difference.
17
+ *
18
+ * @example
19
+ * // fixtures.ts
20
+ * import { test as base } from '@playwright/test';
21
+ * import { registerCombobox } from 'html-combobox-element/playwright';
22
+ *
23
+ * export const test = base.extend<{}, { combobox: void }>({
24
+ * combobox: [async ({ playwright }, use) => {
25
+ * await registerCombobox(playwright.selectors);
26
+ * await use();
27
+ * }, { scope: 'worker', auto: true }],
28
+ * });
29
+ *
30
+ * // in a test
31
+ * await page.getByLabel('Fruit').selectOption('banana');
32
+ * await expect(page.getByLabel('Fruit')).toHaveValue('banana');
33
+ */
34
+ /** The part of Playwright's `Selectors` this module uses (no dependency on Playwright) */
35
+ export interface SelectorsLike {
36
+ register(name: string, script: string, options?: {
37
+ contentScript?: boolean;
38
+ }): Promise<void>;
39
+ }
40
+ /** Name under which the engine is registered by default */
41
+ export declare const COMBOBOX_ENGINE_NAME = "combobox-select-api";
42
+ /** Source of the selector engine, for `selectors.register(name, source, { contentScript: true })` */
43
+ export declare const comboboxSelectorEngine: string;
44
+ /**
45
+ * Registers the engine. Call it once per worker, before any page is created
46
+ * (Playwright requires selector engines to be registered before pages exist).
47
+ */
48
+ export declare function registerCombobox(selectors: SelectorsLike, name?: string): Promise<void>;
@@ -1 +1 @@
1
- {"root":["../../src/index.ts","../../src/combobox/boolean.attribute.value.normalizer.ts","../../src/combobox/combobox.markup.ts","../../src/combobox/html.combobox.element.ts","../../src/combobox/html.combobox.option.element.ts","../../src/combobox/html.combobox.tag.element.ts","../../src/combobox/index.ts"],"version":"5.9.3"}
1
+ {"root":["../../src/index.ts","../../src/playwright.ts","../../src/combobox/boolean.attribute.value.normalizer.ts","../../src/combobox/combobox.markup.ts","../../src/combobox/html.combobox.element.ts","../../src/combobox/html.combobox.option.element.ts","../../src/combobox/html.combobox.options.collection.ts","../../src/combobox/html.combobox.tag.element.ts","../../src/combobox/index.ts"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-combobox-element",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "The combo-box web-component & customizable select polyfill",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -9,18 +9,21 @@
9
9
  "build:combobox": "tsc -b configs/tsconfig.cjs.json configs/tsconfig.esm.json configs/tsconfig.types.json",
10
10
  "build": "npm-run-all clean build:combobox",
11
11
  "postbuild": "node scripts/fix-dual-package.mjs",
12
- "check-types": "tsc --noEmit"
12
+ "check-types": "tsc --noEmit",
13
+ "test": "playwright test",
14
+ "test:ui": "playwright test --ui"
13
15
  },
14
16
  "keywords": [
15
- "web-components",
16
- "custom elements",
17
17
  "combo-box",
18
- "combobox"
18
+ "combobox",
19
+ "dropdown",
20
+ "select"
19
21
  ],
20
22
  "author": "Roman Konstantin",
21
23
  "license": "MIT",
22
24
  "devDependencies": {
23
25
  "@espcom/eslint-config": "latest",
26
+ "@playwright/test": "^1.65.0",
24
27
  "@types/node": "22.8.6",
25
28
  "@types/react": "^19.2.14",
26
29
  "c8": "10.1.2",
@@ -54,6 +57,16 @@
54
57
  "types": "./dist/cjs/index.d.ts",
55
58
  "default": "./dist/cjs/index.js"
56
59
  }
60
+ },
61
+ "./playwright": {
62
+ "import": {
63
+ "types": "./dist/types/playwright.d.ts",
64
+ "default": "./dist/esm/playwright.js"
65
+ },
66
+ "require": {
67
+ "types": "./dist/cjs/playwright.d.ts",
68
+ "default": "./dist/cjs/playwright.js"
69
+ }
57
70
  }
58
71
  }
59
72
  }