Skip the search close handler if it was not open
authorAlexander Ebert <ebert@woltlab.com>
Sat, 18 Jun 2022 13:48:56 +0000 (15:48 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 18 Jun 2022 13:48:56 +0000 (15:48 +0200)
Executing the callback causes some unintentional changes to the page state.

See https://www.woltlab.com/community/thread/295991-dialoge-hintergrund-scrollt/

ts/WoltLabSuite/Core/Ui/Search.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search.js

index 6c6c18952923b5304cca739ffabf9723d18e84bc..0c705bca0d8b16d6cd2119f537730c1e79bebfd9 100644 (file)
@@ -150,6 +150,11 @@ function openSearch(): void {
 }
 
 function closeSearch(): void {
+  const wasOpen = _pageHeader.classList.contains("searchBarOpen") || _pageHeaderSearch.classList.contains("open");
+  if (!wasOpen) {
+    return;
+  }
+
   _pageHeader.classList.remove("searchBarOpen");
   _pageHeaderSearch.classList.remove("open");
   _userPanelSearchButton?.parentElement!.classList.remove("open");
index d05b6d6fa2a81888ac84d377e3275a06856ac67d..bd561ab55afc42e53be82c8cb5c4c9b05402b884 100644 (file)
@@ -126,6 +126,10 @@ define(["require", "exports", "tslib", "../Event/Handler", "./Alignment", "./Clo
         }, 1);
     }
     function closeSearch() {
+        const wasOpen = _pageHeader.classList.contains("searchBarOpen") || _pageHeaderSearch.classList.contains("open");
+        if (!wasOpen) {
+            return;
+        }
         _pageHeader.classList.remove("searchBarOpen");
         _pageHeaderSearch.classList.remove("open");
         _userPanelSearchButton === null || _userPanelSearchButton === void 0 ? void 0 : _userPanelSearchButton.parentElement.classList.remove("open");