This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/elements/buttons/Dropdown.ts

36 lines
1 KiB
TypeScript
Raw Normal View History

import { LitElement, TemplateResult, html } from "lit";
import { customElement } from "lit/decorators.js";
import { EVENT_REFRESH } from "../../constants";
2020-12-05 21:08:42 +00:00
@customElement("ak-dropdown")
export class DropdownButton extends LitElement {
menu: HTMLElement | null;
constructor() {
2020-11-21 19:48:49 +00:00
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>`;
}
}