Last active
October 17, 2024 09:58
-
-
Save blinkinglight/5475b79aa454719f0cd8b36baf3984a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyCustomElement extends HTMLElement { | |
constructor() { | |
super(); | |
const template = document.createElement('template'); | |
template.id = 'pool-calculator-template'; | |
template.innerHTML = ` | |
<input type="text" id="input"/> | |
`; | |
// this.appendChild(template); | |
this.shadow = this.attachShadow({ mode: 'open' }); | |
this.shadow.appendChild(template.content.cloneNode(true)); | |
this.input = this.shadow.getElementById('input'); | |
this.input.value = this.getAttribute('value'); | |
this.input.onkeyup = () => { | |
this.setAttribute('value', this.input.value); | |
this.dispatchEvent( | |
new CustomEvent('change', { detail: this.input.value }) | |
); | |
}; | |
} | |
static get observedAttributes() { | |
return ['value']; | |
} | |
static get formAssociated() { | |
return true; | |
} | |
attributeChangedCallback(name, oldValue, newValue) { | |
this.input.value = newValue; | |
} | |
// our custom element code | |
} | |
customElements.define('my-custom-element', MyCustomElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<my-custom-element data-bind-value="$test" data-on-change="$test=event.detail"></my-custom-element> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment