From: Alexander Ebert Date: Tue, 23 Mar 2021 18:16:23 +0000 (+0100) Subject: Incorrect position of the suggestion drop-down X-Git-Tag: 5.4.0_Alpha_1~134 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9d7cfda776e5c3809babfeb003d1212c29413619;p=GitHub%2FWoltLab%2FWCF.git Incorrect position of the suggestion drop-down Related issue: #4096 --- diff --git a/ts/WoltLabSuite/Core/Ui/Dropdown/Simple.ts b/ts/WoltLabSuite/Core/Ui/Dropdown/Simple.ts index 475f676186..729272902f 100644 --- a/ts/WoltLabSuite/Core/Ui/Dropdown/Simple.ts +++ b/ts/WoltLabSuite/Core/Ui/Dropdown/Simple.ts @@ -566,10 +566,10 @@ const UiDropdownSimple = { /** * Opens the dropdown unless it is already open. */ - open(containerId: string, disableAutoFocus?: boolean): void { + open(containerId: string, disableAutoFocus?: boolean, referenceElement?: HTMLElement): void { const menu = _menus.get(containerId); if (menu !== undefined && !menu.classList.contains("dropdownOpen")) { - UiDropdownSimple.toggleDropdown(containerId, undefined, disableAutoFocus); + UiDropdownSimple.toggleDropdown(containerId, referenceElement, disableAutoFocus); } }, diff --git a/ts/WoltLabSuite/Core/Ui/Search/Input.ts b/ts/WoltLabSuite/Core/Ui/Search/Input.ts index 934ef2fe81..39ffd5fd7c 100644 --- a/ts/WoltLabSuite/Core/Ui/Search/Input.ts +++ b/ts/WoltLabSuite/Core/Ui/Search/Input.ts @@ -288,10 +288,8 @@ class UiSearchInput { if (typeof data.returnValues === "object") { const callbackClick = this.clickSelectItem.bind(this); - let listItem; - Object.keys(data.returnValues).forEach((key) => { - listItem = this.createListItem(data.returnValues[key]); + const listItem = this.createListItem(data.returnValues[key]); listItem.addEventListener("click", callbackClick); this.list!.appendChild(listItem); @@ -312,7 +310,7 @@ class UiSearchInput { if (!this.list.childElementCount && !this.handleEmptyResult()) { UiDropdownSimple.close(this.dropdownContainerId); } else { - UiDropdownSimple.open(this.dropdownContainerId, true); + UiDropdownSimple.open(this.dropdownContainerId, true, this.element); // mark first item as active const firstChild = this.list.childElementCount ? (this.list.children[0] as HTMLLIElement) : undefined; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dropdown/Simple.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dropdown/Simple.js index d1eda1748b..b2c0a48c92 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dropdown/Simple.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dropdown/Simple.js @@ -472,10 +472,10 @@ define(["require", "exports", "tslib", "../../CallbackList", "../../Core", "../. /** * Opens the dropdown unless it is already open. */ - open(containerId, disableAutoFocus) { + open(containerId, disableAutoFocus, referenceElement) { const menu = _menus.get(containerId); if (menu !== undefined && !menu.classList.contains("dropdownOpen")) { - UiDropdownSimple.toggleDropdown(containerId, undefined, disableAutoFocus); + UiDropdownSimple.toggleDropdown(containerId, referenceElement, disableAutoFocus); } }, /** diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Input.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Input.js index e81886d67f..4f69b3391e 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Input.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Input.js @@ -242,9 +242,8 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ut } if (typeof data.returnValues === "object") { const callbackClick = this.clickSelectItem.bind(this); - let listItem; Object.keys(data.returnValues).forEach((key) => { - listItem = this.createListItem(data.returnValues[key]); + const listItem = this.createListItem(data.returnValues[key]); listItem.addEventListener("click", callbackClick); this.list.appendChild(listItem); }); @@ -261,7 +260,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ut Simple_1.default.close(this.dropdownContainerId); } else { - Simple_1.default.open(this.dropdownContainerId, true); + Simple_1.default.open(this.dropdownContainerId, true, this.element); // mark first item as active const firstChild = this.list.childElementCount ? this.list.children[0] : undefined; if (this.autoFocus && firstChild && ~~(firstChild.dataset.objectId || "")) {