Shorten the Menu constructor a tiny bit

The fallback path used when the `menuItems` aren't provided/correct can be simplified, since the manual loop isn't necessary.
This commit is contained in:
Jonas Jenwald 2026-08-04 12:41:46 +02:00
parent 4806d8294e
commit 1e2c571075

View File

@ -39,14 +39,9 @@ class Menu {
constructor(menuContainer, triggeringButton, menuItems) {
this.#menu = menuContainer;
this.#triggeringButton = triggeringButton;
if (Array.isArray(menuItems)) {
this.#menuItems = menuItems;
} else {
this.#menuItems = [];
for (const button of this.#menu.querySelectorAll("button")) {
this.#menuItems.push(button);
}
}
this.#menuItems = Array.isArray(menuItems)
? menuItems
: [...this.#menu.querySelectorAll("button")];
this.#setUpMenu();
}