Skip to content

Commit 202b9c7

Browse files
committed
Fix provider selection in acp search dropdown
1 parent 96a13cd commit 202b9c7

2 files changed

Lines changed: 63 additions & 44 deletions

File tree

  • ts/WoltLabSuite/Core/Acp/Ui
  • wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui

ts/WoltLabSuite/Core/Acp/Ui/Search.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import { getPhrase } from "WoltLabSuite/Core/Language";
1212
import { searchAcp, type AcpSearchResultGroup } from "WoltLabSuite/Core/Api/Acp/Search";
13+
import UiDropdownSimple from "WoltLabSuite/Core/Ui/Dropdown/Simple";
1314

1415
const DELAY = 250;
1516
const TRIGGER_LENGTH = 3;
@@ -252,35 +253,45 @@ function onBlur(event: FocusEvent): void {
252253
}
253254

254255
function initProviderSelection(): void {
255-
const dropdown = document.getElementById("pageHeaderSearchType");
256-
if (dropdown === null) {
256+
// `UiDropdownSimple` reparents the dropdown menu to a global container
257+
// during its lazy initialization, so the menu items are no longer
258+
// descendants of `#pageHeaderSearchType` at this point. Look it up
259+
// through the dropdown registry instead.
260+
const menu = UiDropdownSimple.getDropdownMenu("pageHeaderSearchType");
261+
if (menu === undefined) {
257262
return;
258263
}
259264

260-
dropdown.querySelectorAll<HTMLAnchorElement>("a[data-provider-name]").forEach((link) => {
261-
link.addEventListener("click", (event) => {
262-
event.preventDefault();
265+
menu.addEventListener("click", (event) => {
266+
const target = event.target as HTMLElement | null;
267+
const link = target?.closest<HTMLAnchorElement>("a[data-provider-name]") ?? null;
268+
if (link === null) {
269+
return;
270+
}
263271

264-
const label = document.querySelector<HTMLElement>(".pageHeaderSearchType > .button > .pageHeaderSearchTypeLabel");
265-
if (label !== null) {
266-
label.textContent = link.textContent;
267-
}
272+
event.preventDefault();
268273

269-
const oldProvider = providerName;
270-
const newProvider = link.dataset.providerName === "everywhere" ? "" : link.dataset.providerName!;
271-
providerName = newProvider;
272-
273-
if (oldProvider !== newProvider) {
274-
const input = getSearchInput();
275-
if (input !== null) {
276-
const query = input.value.trim();
277-
if (query.length >= TRIGGER_LENGTH) {
278-
lastQuery = query;
279-
void performSearch(query);
280-
}
274+
const label = document.querySelector<HTMLElement>(
275+
".pageHeaderSearchType > .button > .pageHeaderSearchTypeLabel",
276+
);
277+
if (label !== null) {
278+
label.textContent = link.textContent;
279+
}
280+
281+
const oldProvider = providerName;
282+
const newProvider = link.dataset.providerName === "everywhere" ? "" : link.dataset.providerName!;
283+
providerName = newProvider;
284+
285+
if (oldProvider !== newProvider) {
286+
const input = getSearchInput();
287+
if (input !== null) {
288+
const query = input.value.trim();
289+
if (query.length >= TRIGGER_LENGTH) {
290+
lastQuery = query;
291+
void performSearch(query);
281292
}
282293
}
283-
});
294+
}
284295
});
285296
}
286297

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

Lines changed: 30 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)