From bf9a89caba1de38a4923be37f0183ca954ea5c73 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Fri, 15 Aug 2025 11:12:52 -0700 Subject: [PATCH] fix modal click --- src/client/TerritoryPatternsModal.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/client/TerritoryPatternsModal.ts b/src/client/TerritoryPatternsModal.ts index 0d57be4c5..245f4fb2a 100644 --- a/src/client/TerritoryPatternsModal.ts +++ b/src/client/TerritoryPatternsModal.ts @@ -44,9 +44,10 @@ export class TerritoryPatternsModal extends LitElement { super.connectedCallback(); window.addEventListener("keydown", this.handleKeyDown); this.updateComplete.then(() => { - this.updatePreview(); + this.open().then(() => { + this.updatePreview(); + }); }); - this.open(); } disconnectedCallback() { @@ -231,11 +232,21 @@ export class TerritoryPatternsModal extends LitElement { `; } - public open() { + public async open() { this.isActive = true; - this.modalEl?.open(); - window.addEventListener("keydown", this.handleKeyDown); this.requestUpdate(); + + // Wait for the DOM to be updated and the o-modal element to be available + await this.updateComplete; + + // Now modalEl should be available + if (this.modalEl) { + this.modalEl.open(); + } else { + console.warn("modalEl is still null after updateComplete"); + } + + window.addEventListener("keydown", this.handleKeyDown); } public close() {