42a9979d91
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
36 lines
1 KiB
TypeScript
36 lines
1 KiB
TypeScript
import { LitElement, TemplateResult, html } from "lit";
|
|
import { customElement } from "lit/decorators.js";
|
|
|
|
import { EVENT_REFRESH } from "../../constants";
|
|
|
|
@customElement("ak-dropdown")
|
|
export class DropdownButton extends LitElement {
|
|
menu: HTMLElement | null;
|
|
|
|
constructor() {
|
|
super();
|
|
this.menu = this.querySelector<HTMLElement>(".pf-c-dropdown__menu");
|
|
this.querySelectorAll("button.pf-c-dropdown__toggle").forEach((btn) => {
|
|
btn.addEventListener("click", () => {
|
|
if (!this.menu) return;
|
|
this.menu.hidden = !this.menu.hidden;
|
|
});
|
|
});
|
|
window.addEventListener(EVENT_REFRESH, this.clickHandler);
|
|
}
|
|
|
|
clickHandler = (): void => {
|
|
if (!this.menu) return;
|
|
this.menu.hidden = true;
|
|
};
|
|
|
|
disconnectedCallback(): void {
|
|
super.disconnectedCallback();
|
|
window.removeEventListener(EVENT_REFRESH, this.clickHandler);
|
|
}
|
|
|
|
render(): TemplateResult {
|
|
return html`<slot></slot>`;
|
|
}
|
|
}
|