class CustomModal extends HTMLElement { static observedAttributes = ['active']; #templateHtml = `
`; constructor() { super(); this.attachShadow({ mode: 'open' }); const template = document.createElement('template') template.innerHTML = this.#templateHtml; this.shadowRoot.appendChild(template.content.cloneNode(true)); this.overlay = this.shadowRoot.querySelector('div.overlay'); console.log(this.overlay); this.mainWindow = this.shadowRoot.querySelector('main-window'); } connectedCallback() { this.updateStyle(); } attributeChangedCallback() { console.log("attributeChanged"); this.updateStyle(); } updateStyle() { console.log(this.getAttribute('active'), typeof this.getAttribute('active')); this.overlay.style.visibility = this.getAttribute('active') === "true" ? 'visible' : 'hidden'; } } customElements.define('custom-modal', CustomModal);