Add missing input events

This commit is contained in:
Talia 2025-09-18 12:20:46 +02:00
parent 7d6f2591f4
commit aeef67188c
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E
3 changed files with 26 additions and 10 deletions

View file

@ -6,7 +6,7 @@
},
"type": "module",
"license": "MIT",
"version": "3.0.1",
"version": "3.0.2",
"url": "https://darkwiiplayer.github.io/BetterSelect/",
"scripts": {
"definitions": "tsc src/*.js --declaration --allowJs --emitDeclarationOnly"

View file

@ -2,6 +2,7 @@ export class BetterSelect extends HTMLElement {
static formAssociated: boolean;
static observedAttributes: readonly string[];
static styleSheet: CSSStyleSheet;
static searchHideDisabled: boolean;
/** @type {HTMLElement} */
display: HTMLElement;
/** @type {HTMLElement} */
@ -18,6 +19,7 @@ export class BetterSelect extends HTMLElement {
loading: HTMLDialogElement;
options: HTMLCollectionOf<HTMLOptionElement>;
keyboardSearchBuffer: string;
dispatchInputEvent(): void;
/**
* @param {String} key
*/
@ -35,18 +37,19 @@ export class BetterSelect extends HTMLElement {
* @param {string} value
* @param {HTMLElement} item
*/
match(value: string, item: HTMLElement): RegExpMatchArray;
match(value: string, item: HTMLElement): false | RegExpMatchArray;
connectedCallback(): void;
mutationCallback(): void;
/** @param {HTMLElement} option */
setOption(option: HTMLElement): void;
/**
* @param {number} index
* @param {string} value
* @param {string} state
*/
setValue(value: string, state?: string): void;
setValue(index: number, value: string, state?: string): void;
updateClearButton(): void;
set value(value: any);
set value(arg: any);
get value(): any;
get valueText(): any;
setOptions(): void;
@ -61,7 +64,7 @@ export class BetterSelect extends HTMLElement {
/**
* @param {String} name
*/
set name(name: string);
set name(arg: string);
/**
* @return {String}
*/
@ -71,12 +74,14 @@ export class BetterSelect extends HTMLElement {
/**
* @param {Boolean} disabled
*/
set disabled(disabled: boolean);
set disabled(arg: boolean);
get disabled(): boolean;
/**
* @param {ValidityConstraint} _constraint
*/
validityMessage(_constraint: ValidityConstraint): string;
next(): void;
previous(): void;
setValidity(): boolean;
checkValidity(): boolean;
get validity(): ValidityState;
@ -85,7 +90,7 @@ export class BetterSelect extends HTMLElement {
/**
* @param {Boolean} required
*/
set required(required: boolean);
set required(arg: boolean);
get required(): boolean;
reportValidity(): boolean;
requiredChanged(): void;

View file

@ -280,7 +280,7 @@ export class BetterSelect extends HTMLElement {
if (item) {
if (!item.part.contains("disabled")) {
this.setOption(item)
this.dispatchEvent(new InputEvent("input", {bubbles: true}))
this.dispatchInputEvent()
this.close()
}
} else if (!this.#states.has("open")) {
@ -318,12 +318,15 @@ export class BetterSelect extends HTMLElement {
event.stopPropagation()
} else if (key == "Delete") {
this.clear()
this.dispatchInputEvent()
} else if (key == "ArrowDown") {
event.preventDefault()
this.next()
this.dispatchInputEvent()
} else if (key == "ArrowUp") {
event.preventDefault()
this.previous()
this.dispatchInputEvent()
}
}
})
@ -340,6 +343,10 @@ export class BetterSelect extends HTMLElement {
this.setValidity()
}
dispatchInputEvent() {
this.dispatchEvent(new InputEvent("input", {bubbles: true}))
}
/**
* @param {String} key
*/
@ -402,7 +409,7 @@ export class BetterSelect extends HTMLElement {
this.addEventListener("keypress", event => {
if (event.key == "Enter") {
this.selectDefault()
this.dispatchEvent(new InputEvent("input", {bubbles: true}))
this.dispatchInputEvent()
}
}, {signal})
@ -482,7 +489,10 @@ export class BetterSelect extends HTMLElement {
* @param {string} state
*/
setValue(index, value, state=value) {
if (value)
this.#index = Number(index)
else
this.#index = undefined
this.#value = {value, state}
this.dispatchEvent(new Event("change", {bubbles: true}));
@ -506,6 +516,7 @@ export class BetterSelect extends HTMLElement {
template.nextElementSibling.addEventListener("click", event => {
event.stopPropagation()
this.clear()
this.dispatchInputEvent()
})
}
}