Add more events
This commit is contained in:
parent
1bf89ec64c
commit
edf6d04137
2 changed files with 7 additions and 0 deletions
|
@ -21,3 +21,8 @@
|
||||||
## Attributes
|
## Attributes
|
||||||
|
|
||||||
* `closeSignal`: An AbortSignal that fires when the drop-down closes
|
* `closeSignal`: An AbortSignal that fires when the drop-down closes
|
||||||
|
|
||||||
|
## Events
|
||||||
|
|
||||||
|
* `change`: Fired whenever the value changes, even if via JavaScript
|
||||||
|
* `input`: Fired when the value is changed by selecting an option (after `change`)
|
||||||
|
|
|
@ -203,6 +203,7 @@ export class BetterSelect extends HTMLElement {
|
||||||
this.addEventListener("keypress", event => {
|
this.addEventListener("keypress", event => {
|
||||||
if (event.key == "Enter") {
|
if (event.key == "Enter") {
|
||||||
this.selectDefault()
|
this.selectDefault()
|
||||||
|
this.dispatchEvent(new InputEvent("input", {bubbles: true}))
|
||||||
}
|
}
|
||||||
}, {signal})
|
}, {signal})
|
||||||
|
|
||||||
|
@ -275,6 +276,7 @@ export class BetterSelect extends HTMLElement {
|
||||||
*/
|
*/
|
||||||
setValue(value, state=value) {
|
setValue(value, state=value) {
|
||||||
this.#value = {value, state}
|
this.#value = {value, state}
|
||||||
|
this.dispatchEvent(new Event("change", {bubbles: true}));
|
||||||
this.#internals.setFormValue(value, state)
|
this.#internals.setFormValue(value, state)
|
||||||
this.text.innerText = state
|
this.text.innerText = state
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue