|
10 | 10 |
|
11 | 11 | import { getPhrase } from "WoltLabSuite/Core/Language"; |
12 | 12 | import { searchAcp, type AcpSearchResultGroup } from "WoltLabSuite/Core/Api/Acp/Search"; |
| 13 | +import UiDropdownSimple from "WoltLabSuite/Core/Ui/Dropdown/Simple"; |
13 | 14 |
|
14 | 15 | const DELAY = 250; |
15 | 16 | const TRIGGER_LENGTH = 3; |
@@ -252,35 +253,45 @@ function onBlur(event: FocusEvent): void { |
252 | 253 | } |
253 | 254 |
|
254 | 255 | 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) { |
257 | 262 | return; |
258 | 263 | } |
259 | 264 |
|
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 | + } |
263 | 271 |
|
264 | | - const label = document.querySelector<HTMLElement>(".pageHeaderSearchType > .button > .pageHeaderSearchTypeLabel"); |
265 | | - if (label !== null) { |
266 | | - label.textContent = link.textContent; |
267 | | - } |
| 272 | + event.preventDefault(); |
268 | 273 |
|
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); |
281 | 292 | } |
282 | 293 | } |
283 | | - }); |
| 294 | + } |
284 | 295 | }); |
285 | 296 | } |
286 | 297 |
|
|
0 commit comments