From 03331033ea7105f4f7adbae639c22efa98fa8017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 10 Dec 2021 00:12:52 +0100 Subject: Better handling of popup visibility. --- static/components/popup-element.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'static/components/popup-element.ts') diff --git a/static/components/popup-element.ts b/static/components/popup-element.ts index 0a142348..42e8ee7f 100644 --- a/static/components/popup-element.ts +++ b/static/components/popup-element.ts @@ -12,8 +12,6 @@ import { remove_event } from '../server_connect' /* */ class PopupElement extends ComponentVEvent { - isVisible: boolean = false; - constructor(uid?: string) { super(uid); @@ -74,17 +72,27 @@ class PopupElement extends ComponentVEvent { return ['visible']; } + attributeChangedCallback(name: string, oldValue?: string, newValue?: string) { + switch (name) { + case 'visible': + this.onVisibilityChange() + break; + } + } + get visible(): boolean { - return this.isVisible; + return this.hasAttribute('visible'); } set visible(isVisible: boolean) { - this.isVisible = isVisible; - if (this.isVisible) { - this.classList.add('visible'); + if (isVisible) { + this.setAttribute('visible', 'visible'); } else { - this.classList.remove('visible'); + this.removeAttribute('visible'); } + } + + private onVisibilityChange() { /* TODO better way to find root */ let root; -- cgit v1.2.3