/** * Modal dialog component. * * @augments IvComponent */ export class Dialog extends IvComponent { /** @type {Readonly} */ static defaults: Readonly; /** * Returns the dialog instance attached to `el`, if any. * * @param {Element} el Host element. * @returns {Dialog|undefined} The instance or `undefined`. */ static get(el: Element): Dialog | undefined; /** * Returns the existing instance or creates one. * * @param {Element} el Host element. * @param {Partial} [options] Options passed in JavaScript. * @returns {Dialog} The instance. */ static getOrCreate(el: Element, options?: Partial): Dialog; /** * Instantiates every `[data-iv-component="dialog"]` inside `root`. * * @param {ParentNode} [root] Subtree to scan. * @returns {Dialog[]} Newly created instances. */ static initAll(root?: ParentNode): Dialog[]; /** * @param {Element} el A `` element. * @param {Partial} [options] Options passed in JavaScript. * @throws {IvError} `invalid-element` when `el` is not a ``. */ constructor(el: Element, options?: Partial); /** @type {Element|null} Element focus returns to on close. */ _trigger: Element | null; /** @type {DialogReason|null} Reason of a close started by this instance. */ _closingReason: DialogReason | null; /** @type {boolean} Whether this instance added a temporary `tabindex`. */ _addedTabindex: boolean; /** @type {boolean} Whether the instance is being destroyed. */ _destroying: boolean; /** @type {EventTarget|null} Where the press behind the current click landed. */ _pressTarget: EventTarget | null; /** * The host element, typed as a dialog. * * @returns {HTMLDialogElement} The `` element. */ get dialog(): HTMLDialogElement; /** * Resolved options. * * @returns {Readonly} The options. */ get options(): Readonly; /** * Whether the dialog is currently open. * * @returns {boolean} `true` when open. */ get isOpen(): boolean; /** * The native `returnValue` of the dialog. * * @returns {string} The return value. */ get returnValue(): string; /** * Opens the dialog as a modal. * * @param {{ trigger?: Element }} [opts] Opening context. * @returns {void} */ open(opts?: { trigger?: Element; }): void; /** * Closes the dialog. * * @param {DialogReason} [reason] Why the dialog is closing. * @param {string} [returnValue] Native return value. * @returns {void} */ close(reason?: DialogReason, returnValue?: string): void; /** * Opens the dialog when closed, closes it when open. * * @returns {void} */ toggle(): void; /** * Moves focus inside the dialog after opening. * * @returns {void} */ _focusInitial(): void; /** * Removes the temporary `tabindex` added on open. * * @returns {void} */ _restoreTabindex(): void; /** * Reacts to the native `close` event, whoever caused it. * * @returns {void} */ _onNativeClose(): void; } export type DialogOptions = { /** * Close when the backdrop is clicked. */ closeOnBackdrop: boolean; /** * Close when Esc is pressed. */ closeOnEscape: boolean; /** * Selector, scoped to the dialog, focused on open. */ initialFocus: string | null; /** * Return focus to the trigger on close. */ returnFocus: boolean; }; export type DialogReason = "api" | "escape" | "backdrop" | "form" | "trigger" | "external"; import { IvComponent } from "../core/component.js";