html-combobox-element 0.0.5 → 0.0.7
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.
- package/README.md +162 -46
- package/dist/cjs/combobox/Combobox.markup.d.ts +22 -1
- package/dist/cjs/combobox/Combobox.markup.js +156 -35
- package/dist/cjs/combobox/HTML.combobox.element.d.ts +32 -5
- package/dist/cjs/combobox/HTML.combobox.element.js +431 -98
- package/dist/cjs/combobox/HTML.combobox.option.element.d.ts +25 -4
- package/dist/cjs/combobox/HTML.combobox.option.element.js +104 -73
- package/dist/cjs/combobox/HTML.combobox.options.collection.d.ts +37 -0
- package/dist/cjs/combobox/HTML.combobox.options.collection.js +176 -0
- package/dist/cjs/combobox/HTML.combobox.tag.element.d.ts +7 -1
- package/dist/cjs/combobox/HTML.combobox.tag.element.js +36 -12
- package/dist/cjs/combobox/index.d.ts +1 -0
- package/dist/cjs/combobox/index.js +1 -0
- package/dist/cjs/index.d.ts +66 -22
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/playwright.d.ts +48 -0
- package/dist/cjs/playwright.js +127 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/combobox/Combobox.markup.js +156 -35
- package/dist/esm/combobox/HTML.combobox.element.js +431 -98
- package/dist/esm/combobox/HTML.combobox.option.element.js +104 -73
- package/dist/esm/combobox/HTML.combobox.options.collection.js +170 -0
- package/dist/esm/combobox/HTML.combobox.tag.element.js +36 -12
- package/dist/esm/combobox/index.js +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/playwright.js +123 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/combobox/Combobox.markup.d.ts +22 -1
- package/dist/types/combobox/HTML.combobox.element.d.ts +32 -5
- package/dist/types/combobox/HTML.combobox.option.element.d.ts +25 -4
- package/dist/types/combobox/HTML.combobox.options.collection.d.ts +37 -0
- package/dist/types/combobox/HTML.combobox.tag.element.d.ts +7 -1
- package/dist/types/combobox/index.d.ts +1 -0
- package/dist/types/index.d.ts +66 -22
- package/dist/types/playwright.d.ts +48 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +49 -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
10
|
-
static onNavigate(event: KeyboardEvent): void;
|
|
27
|
+
constructor();
|
|
11
28
|
connectedCallback(): void;
|
|
12
|
-
|
|
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
|
|
17
|
+
static onControlKeyDown(event: KeyboardEvent): void;
|
|
12
18
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
import { HTMLComboboxElement as ComboboxElementClass } from './combobox/HTML.combobox.element.js';
|
|
2
|
+
import type { HTMLComboboxOptionsCollection } from './combobox/HTML.combobox.options.collection.js';
|
|
1
3
|
export * from './combobox/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* The `<combo-box>` constructor, typed the way lib.dom types built-in elements
|
|
6
|
+
* (`interface HTMLSelectElement` + `declare var HTMLSelectElement: { prototype; new() }`):
|
|
7
|
+
* the same `HTMLComboboxElement` type is what `document.createElement('combo-box')`,
|
|
8
|
+
* `querySelector('combo-box')`, `event.target`, refs and `instanceof HTMLComboboxElement` give.
|
|
9
|
+
*
|
|
10
|
+
* Runtime-wise this is the very same class object that `export *` exported before.
|
|
11
|
+
*/
|
|
12
|
+
export declare const HTMLComboboxElement: Omit<typeof ComboboxElementClass, 'prototype'> & {
|
|
13
|
+
prototype: HTMLComboboxElement;
|
|
14
|
+
new (): HTMLComboboxElement;
|
|
15
|
+
};
|
|
2
16
|
interface HTMLComboboxTagElement extends HTMLElement {
|
|
3
17
|
}
|
|
4
18
|
interface HTMLComboboxOptionElement extends HTMLOptionElement {
|
|
5
19
|
value: string;
|
|
6
20
|
label: string;
|
|
7
21
|
}
|
|
8
|
-
interface HTMLComboboxElement extends HTMLSelectElement {
|
|
22
|
+
export interface HTMLComboboxElement extends HTMLSelectElement {
|
|
9
23
|
/** List of selected options value attribute */
|
|
10
24
|
valueAsArray: string[];
|
|
25
|
+
/** Whether the value differs from when the picker opened (read it in a `close` listener). */
|
|
26
|
+
readonly changed: boolean;
|
|
27
|
+
/** A live `HTMLOptionsCollection`-compatible collection (not `instanceof HTMLOptionsCollection`). */
|
|
28
|
+
readonly options: HTMLOptionsCollection & HTMLComboboxOptionsCollection;
|
|
11
29
|
multiple: boolean;
|
|
12
30
|
/** The value of internal input
|
|
13
31
|
*
|
|
@@ -45,11 +63,11 @@ interface HTMLComboboxElement extends HTMLSelectElement {
|
|
|
45
63
|
* */
|
|
46
64
|
filterable: boolean;
|
|
47
65
|
selectedOptions: HTMLCollectionOf<HTMLComboboxOptionElement>;
|
|
48
|
-
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLComboboxElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
49
66
|
addEventListener<K extends keyof ComboboxEventMap>(type: K, listener: (this: HTMLComboboxElement, ev: ComboboxEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
67
|
+
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLComboboxElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
50
68
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
51
|
-
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLComboboxElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
52
69
|
removeEventListener<K extends keyof ComboboxEventMap>(type: K, listener: (this: HTMLComboboxElement, ev: ComboboxEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
70
|
+
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLComboboxElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
53
71
|
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
54
72
|
}
|
|
55
73
|
interface ComboboxEventMap extends HTMLElementEventMap {
|
|
@@ -62,6 +80,12 @@ interface ComboboxEventMap extends HTMLElementEventMap {
|
|
|
62
80
|
"invalid": ComboboxEvent;
|
|
63
81
|
"selectionchange": ComboboxEvent;
|
|
64
82
|
"selectstart": ComboboxEvent;
|
|
83
|
+
/** The picker closed (read `event.target.changed`) */
|
|
84
|
+
"close": ComboboxEvent;
|
|
85
|
+
/** Enter was pressed in the search field */
|
|
86
|
+
"search": ComboboxEvent;
|
|
87
|
+
/** The owner form was reset */
|
|
88
|
+
"reset": ComboboxEvent;
|
|
65
89
|
}
|
|
66
90
|
/** Own attributes/properties of `<combo-box>`, shared by every JSX integration below. */
|
|
67
91
|
export interface ComboboxJsxAttributes {
|
|
@@ -109,6 +133,10 @@ export interface ComboboxJsxAttributes {
|
|
|
109
133
|
/** A Boolean attribute indicating that at least one option must be selected. */
|
|
110
134
|
required?: boolean;
|
|
111
135
|
disabled?: boolean;
|
|
136
|
+
/** The name the value is submitted under (`<combo-box>` is form-associated). */
|
|
137
|
+
name?: string;
|
|
138
|
+
/** The id of the `<form>` this combobox belongs to, when it isn't inside it. */
|
|
139
|
+
form?: string;
|
|
112
140
|
}
|
|
113
141
|
export interface ComboboxOptionJsxAttributes {
|
|
114
142
|
value: string;
|
|
@@ -173,29 +201,45 @@ declare global {
|
|
|
173
201
|
}
|
|
174
202
|
}
|
|
175
203
|
declare module 'react' {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
204
|
+
/** A React event whose `target` is the element (events from the shadow DOM are retargeted to it). */
|
|
205
|
+
type ComboboxSyntheticEvent<T, E extends globalThis.Event = globalThis.Event> = import('react').SyntheticEvent<T, E> & {
|
|
206
|
+
target: EventTarget & T;
|
|
207
|
+
};
|
|
208
|
+
type ComboboxBaseHTMLAttributes<T> = import('react').HTMLAttributes<T>;
|
|
209
|
+
type ComboboxBaseHostAttributes<T> = Omit<import('react').HTMLAttributes<T>, 'onInput'>;
|
|
210
|
+
interface ComboboxHTMLAttributes<T> extends ComboboxBaseHostAttributes<T>, ComboboxJsxAttributes {
|
|
211
|
+
class?: string | undefined;
|
|
212
|
+
/** The user changed the selection (`event.target.value` is the new value). */
|
|
213
|
+
onChange?: import('react').EventHandler<ComboboxSyntheticEvent<T>> | undefined;
|
|
214
|
+
/** The user typed in the search field (`event.target.query`); `nativeEvent` is its InputEvent. */
|
|
215
|
+
onInput?: import('react').EventHandler<ComboboxSyntheticEvent<T, globalThis.InputEvent>> | undefined;
|
|
216
|
+
onInvalid?: import('react').EventHandler<ComboboxSyntheticEvent<T>> | undefined;
|
|
217
|
+
/** Native listener: the picker closed (`event.target.changed`). Lowercase - `onClose` never fires. */
|
|
218
|
+
onclose?: ((event: ComboboxEvent) => void) | undefined;
|
|
219
|
+
/** Native listener: Enter in the search field. Lowercase - `onSearch` never fires. */
|
|
220
|
+
onsearch?: ((event: ComboboxEvent) => void) | undefined;
|
|
182
221
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
namespace JSX {
|
|
186
|
-
interface IntrinsicElements {
|
|
187
|
-
'combo-box': ComboboxElementAttributes;
|
|
188
|
-
'box-option': ComboboxOptionElementAttributes;
|
|
189
|
-
'box-tag': ComboboxTagElementAttributes;
|
|
190
|
-
}
|
|
222
|
+
interface ComboboxOptionHTMLAttributes<T> extends ComboboxBaseHTMLAttributes<T>, ComboboxOptionJsxAttributes {
|
|
223
|
+
class?: string | undefined;
|
|
191
224
|
}
|
|
192
|
-
|
|
193
|
-
|
|
225
|
+
interface ComboboxTagHTMLAttributes<T> extends ComboboxBaseHTMLAttributes<T> {
|
|
226
|
+
class?: string | undefined;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* @types/react 18 builds React.JSX.IntrinsicElements on top of the global JSX namespace, so
|
|
230
|
+
* its entries must stay assignable to the framework-agnostic global ones (catch-all `on*`,
|
|
231
|
+
* native event types): with React 18 types the global entries are kept as they are.
|
|
232
|
+
* @types/react 19 has no global JSX namespace: React.JSX gets React-typed props.
|
|
233
|
+
* (React 18 types declare the HTML elements in the global namespace, React 19 types don't.)
|
|
234
|
+
*/
|
|
235
|
+
type ComboboxIntrinsicElement<Global, Typed> = globalThis.JSX.IntrinsicElements extends {
|
|
236
|
+
div: unknown;
|
|
237
|
+
} ? Global : Typed;
|
|
194
238
|
namespace JSX {
|
|
195
239
|
interface IntrinsicElements {
|
|
196
|
-
'combo-box': ComboboxElementAttributes
|
|
197
|
-
'box-option': ComboboxOptionElementAttributes
|
|
198
|
-
'box-tag': ComboboxTagElementAttributes
|
|
240
|
+
'combo-box': ComboboxIntrinsicElement<ComboboxElementAttributes, import('react').ClassAttributes<HTMLComboboxElement> & ComboboxHTMLAttributes<HTMLComboboxElement>>;
|
|
241
|
+
'box-option': ComboboxIntrinsicElement<ComboboxOptionElementAttributes, import('react').ClassAttributes<HTMLComboboxOptionElement> & ComboboxOptionHTMLAttributes<HTMLComboboxOptionElement>>;
|
|
242
|
+
'box-tag': ComboboxIntrinsicElement<ComboboxTagElementAttributes, import('react').ClassAttributes<HTMLComboboxTagElement> & ComboboxTagHTMLAttributes<HTMLComboboxTagElement>>;
|
|
199
243
|
}
|
|
200
244
|
}
|
|
201
245
|
}
|
|
@@ -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,28 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-combobox-element",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "The combo-box web-component & customizable select polyfill",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/nihil-pro/html-combobox-element.git"
|
|
9
|
+
},
|
|
6
10
|
"scripts": {
|
|
7
11
|
"prepare": "husky",
|
|
8
12
|
"clean": "rm -rf dist",
|
|
9
13
|
"build:combobox": "tsc -b configs/tsconfig.cjs.json configs/tsconfig.esm.json configs/tsconfig.types.json",
|
|
10
14
|
"build": "npm-run-all clean build:combobox",
|
|
11
15
|
"postbuild": "node scripts/fix-dual-package.mjs",
|
|
12
|
-
"check-types": "tsc --noEmit"
|
|
16
|
+
"check-types": "tsc --noEmit",
|
|
17
|
+
"test": "playwright test",
|
|
18
|
+
"test:ui": "playwright test --ui",
|
|
19
|
+
"test:types": "playwright test -c playwright.types.config.ts"
|
|
13
20
|
},
|
|
14
21
|
"keywords": [
|
|
15
|
-
"web-components",
|
|
16
|
-
"custom elements",
|
|
17
22
|
"combo-box",
|
|
18
|
-
"combobox"
|
|
23
|
+
"combobox",
|
|
24
|
+
"dropdown",
|
|
25
|
+
"select"
|
|
19
26
|
],
|
|
20
27
|
"author": "Roman Konstantin",
|
|
21
28
|
"license": "MIT",
|
|
22
29
|
"devDependencies": {
|
|
23
30
|
"@espcom/eslint-config": "latest",
|
|
31
|
+
"@playwright/test": "^1.65.0",
|
|
24
32
|
"@types/node": "22.8.6",
|
|
25
33
|
"@types/react": "^19.2.14",
|
|
34
|
+
"@types/react-dom": "^19.2.3",
|
|
26
35
|
"c8": "10.1.2",
|
|
27
36
|
"esbuild": "0.25.5",
|
|
28
37
|
"husky": "9.1.5",
|
|
@@ -30,12 +39,37 @@
|
|
|
30
39
|
"npm-run-all": "^4.1.5",
|
|
31
40
|
"preact": "^10.28.4",
|
|
32
41
|
"react": "^19.2.4",
|
|
42
|
+
"react-dom": "^19.2.4",
|
|
33
43
|
"solid-js": "^1.9.11",
|
|
34
44
|
"tsx": "^4.19.2",
|
|
35
45
|
"typescript": "5.9.3",
|
|
36
46
|
"vue": "^3.5.28",
|
|
37
47
|
"xml-splitter": "1.2.1"
|
|
38
48
|
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@types/react": "*",
|
|
51
|
+
"react": "*",
|
|
52
|
+
"preact": "*",
|
|
53
|
+
"solid-js": "*",
|
|
54
|
+
"vue": "*"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"@types/react": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"react": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"preact": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"solid-js": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"vue": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
72
|
+
},
|
|
39
73
|
"sideEffect": false,
|
|
40
74
|
"files": [
|
|
41
75
|
"dist",
|
|
@@ -54,6 +88,16 @@
|
|
|
54
88
|
"types": "./dist/cjs/index.d.ts",
|
|
55
89
|
"default": "./dist/cjs/index.js"
|
|
56
90
|
}
|
|
91
|
+
},
|
|
92
|
+
"./playwright": {
|
|
93
|
+
"import": {
|
|
94
|
+
"types": "./dist/types/playwright.d.ts",
|
|
95
|
+
"default": "./dist/esm/playwright.js"
|
|
96
|
+
},
|
|
97
|
+
"require": {
|
|
98
|
+
"types": "./dist/cjs/playwright.d.ts",
|
|
99
|
+
"default": "./dist/cjs/playwright.js"
|
|
100
|
+
}
|
|
57
101
|
}
|
|
58
102
|
}
|
|
59
103
|
}
|