aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-10-27 23:15:01 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-10-27 23:15:01 +0800
commited1a8d2e4eb77c2e33d5d44118f13331dac43899 (patch)
tree51cd563aae61fcb07a7c0cd03a8565d01fb4461a
parent9d4a26f5223f5b31d4a8c11de15f5942bbd6ccb2 (diff)
feat: add id option for Menu-item
-rw-r--r--src/MenuItem.mjs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs
index 1035cd1..1d864fd 100644
--- a/src/MenuItem.mjs
+++ b/src/MenuItem.mjs
@@ -28,10 +28,11 @@ export class Item extends window.HTMLDivElement {
28 * @param {string} [options.style] - The CSS style string 28 * @param {string} [options.style] - The CSS style string
29 * @param {string[]} [options.className] - Additional CSS classes 29 * @param {string[]} [options.className] - Additional CSS classes
30 */ 30 */
31 constructor ({ text, innerHTML, title, onclick, style, className }) { 31 constructor ({ id, text, innerHTML, title, onclick, style, className }) {
32 super() 32 super()
33 this.innerHTML = innerHTML ?? text 33 if (id) this.id = id
34 if (title) this.title = title 34 if (title) this.title = title
35 this.innerHTML = innerHTML ?? text
35 this.onclick = onclick 36 this.onclick = onclick
36 this.style.cssText = style 37 this.style.cssText = style
37 this.classList.add('menu-item') 38 this.classList.add('menu-item')
@@ -62,8 +63,9 @@ export class Folder extends window.HTMLDivElement {
62 * @param {string} [options.innerHTML] - The HTML content of the folder 63 * @param {string} [options.innerHTML] - The HTML content of the folder
63 * @param {Item[]} options.items - The submenu items 64 * @param {Item[]} options.items - The submenu items
64 */ 65 */
65 constructor ({ text, innerHTML, items, style }) { 66 constructor ({ id, text, innerHTML, items, style }) {
66 super() 67 super()
68 if (id) this.id = id
67 this.innerHTML = innerHTML ?? text 69 this.innerHTML = innerHTML ?? text
68 this.classList.add('folder', 'menu-item') 70 this.classList.add('folder', 'menu-item')
69 this.items = items 71 this.items = items