Last active
October 17, 2024 09:58
-
-
Save blinkinglight/5475b79aa454719f0cd8b36baf3984a7 to your computer and use it in GitHub Desktop.
Revisions
-
blinkinglight revised this gist
Oct 17, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ <my-custom-element data-bind-value="$test" data-on-change="$test=event.detail"></my-custom-element> -
blinkinglight created this gist
Oct 17, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ 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);