MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / NavMenu

Class NavMenu

packages/playground/src/components/NavMenu.ts:72–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72export class NavMenu implements Mountable {
73 readonly root: HTMLElement;
74 private trigger: HTMLButtonElement;
75 private popover: HTMLElement;
76 private popper: PopperInstance | null = null;
77 private isOpen = false;
78
79 private outsideClick = (e: MouseEvent) => {
80 if (!this.root.contains(e.target as Node) && !this.popover.contains(e.target as Node)) {
81 this.close();
82 }
83 };
84 private onKey = (e: KeyboardEvent) => {
85 if (e.key === 'Escape' && this.isOpen) {
86 e.preventDefault();
87 this.close();
88 this.trigger.focus();
89 }
90 };
91
92 constructor(options: NavMenuOptions = {}) {
93 this.root = parseHtml(html`
94 <div class="at-nav-menu">
95 <button type="button" class="at-nav-menu-trigger" aria-haspopup="true" aria-expanded="false" aria-label="Open playground menu"></button>
96 </div>
97 `);
98 this.trigger = this.root.querySelector<HTMLButtonElement>('.at-nav-menu-trigger')!;
99 this.trigger.appendChild(renderIcon(Icons.Menu));
100
101 this.popover = parseHtml(html`<nav class="at-nav-menu-popover" role="menu"></nav>`);
102
103 const items = options.items ?? DEMOS;
104 const includeIndex = options.includeIndex ?? true;
105 const here = window.location.pathname;
106
107 if (includeIndex) {
108 const indexLink = parseHtml(
109 html`<a class="at-nav-menu-item" href="/" role="menuitem">Labs index</a>`
110 );
111 if (here === '/' || here === '/index.html') {
112 indexLink.classList.add('active');
113 }
114 this.popover.appendChild(indexLink);
115 this.popover.appendChild(parseHtml(html`<div class="at-nav-menu-divider"></div>`));
116 }
117
118 for (const item of items) {
119 const link = parseHtml(
120 html`<a class="at-nav-menu-item" href="${item.href}" role="menuitem">${item.title}</a>`
121 );
122 if (here === item.href || here === `${item.href}index.html`) {
123 link.classList.add('active');
124 }
125 this.popover.appendChild(link);
126 }
127
128 this.trigger.addEventListener('click', e => {
129 e.stopPropagation();

Callers

nothing calls this directly

Calls 2

closeMethod · 0.95
preventDefaultMethod · 0.65

Tested by

no test coverage detected