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
Jens Langhammer 42a9979d91 web/elements: close dropdown when refresh event is dispatched
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
2021-12-06 11:18:22 +01:00

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>`;
}
}