diff --git a/web/src/elements/Interface/Interface.ts b/web/src/elements/Interface/Interface.ts index 8da9454603..8bedbe16e7 100644 --- a/web/src/elements/Interface/Interface.ts +++ b/web/src/elements/Interface/Interface.ts @@ -1,4 +1,5 @@ import { UIConfig, uiConfig } from "@goauthentik/common/ui/config"; +import { ModalOrchestrationController } from "@goauthentik/elements/controllers/ModalOrchestrationController.js"; import { ensureCSSStyleSheet } from "@goauthentik/elements/utils/ensureCSSStyleSheet"; import { state } from "lit/decorators.js"; @@ -22,6 +23,7 @@ export type AkInterface = HTMLElement & { const brandContext = Symbol("brandContext"); const configContext = Symbol("configContext"); +const modalController = Symbol("modalController"); export class Interface extends AKElement implements AkInterface { @state() @@ -31,6 +33,8 @@ export class Interface extends AKElement implements AkInterface { [configContext]!: ConfigContextController; + [modalController]!: ModalOrchestrationController; + @state() config?: Config; @@ -42,6 +46,7 @@ export class Interface extends AKElement implements AkInterface { document.adoptedStyleSheets = [...document.adoptedStyleSheets, ensureCSSStyleSheet(PFBase)]; this[brandContext] = new BrandContextController(this); this[configContext] = new ConfigContextController(this); + this[modalController] = new ModalOrchestrationController(this); this.dataset.akInterfaceRoot = "true"; } diff --git a/web/src/elements/buttons/ModalButton.ts b/web/src/elements/buttons/ModalButton.ts index 5e43b5a455..1fb4a059af 100644 --- a/web/src/elements/buttons/ModalButton.ts +++ b/web/src/elements/buttons/ModalButton.ts @@ -1,5 +1,9 @@ import { PFSize } from "@goauthentik/common/enums.js"; import { AKElement } from "@goauthentik/elements/Base"; +import { + ModalHideEvent, + ModalShowEvent, +} from "@goauthentik/elements/controllers/ModalOrchestrationController.js"; import { CSSResult, TemplateResult, css, html, nothing } from "lit"; import { customElement, property } from "lit/decorators.js"; @@ -65,22 +69,9 @@ export class ModalButton extends AKElement { ]; } - firstUpdated(): void { - if (this.handlerBound) return; - window.addEventListener("keyup", this.keyUpHandler); - this.handlerBound = true; - } - - keyUpHandler = (e: KeyboardEvent): void => { - if (e.code === "Escape") { - this.resetForms(); - this.open = false; - } - }; - - disconnectedCallback(): void { - super.disconnectedCallback(); - window.removeEventListener("keyup", this.keyUpHandler); + closeModal() { + this.resetForms(); + this.open = false; } resetForms(): void { @@ -93,6 +84,7 @@ export class ModalButton extends AKElement { onClick(): void { this.open = true; + this.dispatchEvent(new ModalShowEvent(this)); this.querySelectorAll("*").forEach((child) => { if ("requestUpdate" in child) { (child as AKElement).requestUpdate(); @@ -119,8 +111,7 @@ export class ModalButton extends AKElement { >