Added cleanup concept to the template

This commit is contained in:
barsdeveloper
2022-04-14 22:17:38 +02:00
parent 9b0f344dcc
commit d6aa7b22d2
19 changed files with 136 additions and 69 deletions

View File

@@ -6,6 +6,7 @@ import PinTemplate from "./PinTemplate"
/**
* @typedef {import("../element/PinElement").default} PinElement
*/
export default class StringPinTemplate extends PinTemplate {
hasInput() {
@@ -28,4 +29,30 @@ export default class StringPinTemplate extends PinTemplate {
</div>
`
}
/**
* @param {PinElement} pin
*/
setup(pin) {
super.setup(pin)
const input = pin.querySelector(".ueb-pin-input-content")
this.onFocusHandler = () => {
pin.blueprint.dispatchEditTextEvent(true)
}
this.onFocusOutHandler = () => {
pin.blueprint.dispatchEditTextEvent(false)
document.getSelection().removeAllRanges() // Deselect text inside the input
}
input.addEventListener("onfocus", this.onFocusHandler)
input.addEventListener("onfocusout", this.onFocusOutHandler)
}
/**
* @param {PinElement} pin
*/
cleanup(pin) {
super.cleanup(pin)
pin.blueprint.removeEventListener("onfocus", this.onFocusHandler)
pin.blueprint.removeEventListener("onfocusout", this.onFocusOutHandler)
}
}