From 5800671213e887aec7b5e841c0a32c81b9a02f9e Mon Sep 17 00:00:00 2001 From: Tamara Steinwender <tamara.steinwender@tugraz.at> Date: Thu, 27 Jan 2022 13:56:53 +0100 Subject: [PATCH] Add sanity checks --- packages/app-shell/src/color-mode.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/app-shell/src/color-mode.js b/packages/app-shell/src/color-mode.js index 78af1fef..4da8b40b 100644 --- a/packages/app-shell/src/color-mode.js +++ b/packages/app-shell/src/color-mode.js @@ -81,6 +81,9 @@ export class ColorMode extends ScopedElementsMixin(DBPLitElement) { toggleModeMenu() { const button = this.shadowRoot.querySelector(".mode-button"); + if(!button) { + return; + } if (button.classList.contains("active")) button.classList.remove("active"); else @@ -116,10 +119,15 @@ export class ColorMode extends ScopedElementsMixin(DBPLitElement) { loadTheme(themeName) { const button = this.shadowRoot.querySelector(".button-" + themeName); const otherButtons = this.shadowRoot.querySelectorAll(".button-theme"); + const body = this.shadowRoot.host.getRootNode({composed: true}).body; + + if (button === null || otherButtons.length === 0 || body === null ) { + return; + } + otherButtons.forEach(button => button.classList.remove("active")); button.classList.add("active"); - const body = this.shadowRoot.host.getRootNode({composed: true}).body; if (!body.classList.contains(themeName)) { this.themes.forEach(theme => { -- GitLab