/** * Dropdown component. * * @augments IvComponent */ export class Dropdown extends IvComponent { /** @type {Readonly} */ static defaults: Readonly; /** * Returns the dropdown instance attached to `el`, if any. * * @param {Element} el Host element. * @returns {Dropdown|undefined} The instance or `undefined`. */ static get(el: Element): Dropdown | undefined; /** * Returns the existing instance or creates one. * * @param {Element} el Host element. * @param {Partial} [options] Options passed in JavaScript. * @returns {Dropdown} The instance. */ static getOrCreate(el: Element, options?: Partial): Dropdown; /** * Instantiates every `[data-iv-component="dropdown"]` inside `root`. * * @param {ParentNode} [root] Subtree to scan. * @returns {Dropdown[]} Newly created instances. */ static initAll(root?: ParentNode): Dropdown[]; /** * @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 {boolean} Last committed state; guards the async `toggle`. */ _open: boolean; /** @type {Map>} Attributes to restore. */ _saved: Map>; /** @type {boolean} Whether this instance added the placement class. */ _addedEndClass: boolean; /** @type {boolean} Whether the current opening came from the keyboard. */ _fromKeyboard: boolean; /** @type {HTMLElement|null} The trigger. */ _summary: HTMLElement | null; /** @type {Element|null} The menu container. */ _menu: Element | null; /** * The host element, typed as a details element. * * @returns {HTMLDetailsElement} The `
` element. */ get details(): HTMLDetailsElement; /** * Resolved options. * * @returns {Readonly} The options. */ get options(): Readonly; /** * Whether the menu is currently open. * * @returns {boolean} `true` when open. */ get isOpen(): boolean; /** * Sets a managed attribute, remembering its previous value. * * @param {Element} el Target element. * @param {string} name Attribute name. * @param {string} value Attribute value. * @returns {void} */ _set(el: Element, name: string, value: string): void; /** * The focusable menu items, in document order. * * @returns {HTMLElement[]} Enabled items. */ _items(): HTMLElement[]; /** * Keeps `aria-expanded` in sync with the state. * * @returns {void} */ _syncExpanded(): void; /** * Moves focus to a menu item. * * @param {number} index Index in the item list; clamped by the caller. * @returns {void} */ _focusItem(index: number): void; /** * Returns focus to the trigger. * * @returns {void} */ _focusSummary(): void; /** * Handles the native `toggle` event, i.e. a state change made by the user. * * @returns {void} */ _onToggle(): void; /** * Closes the menu when a click lands outside the component. * * @param {Event} event Click event. * @returns {void} */ _onDocumentClick(event: Event): void; /** * Closes the menu when an item is activated with the pointer. * * @param {Event} event Click event. * @returns {void} */ _onClick(event: Event): void; /** * Menu button and menu keyboard handling. * * @param {Event} event Keydown event. * @returns {void} */ _onKeydown(event: Event): void; /** * Opens the menu. Emits the cancelable `iv:open` first. * * @returns {void} */ open(): void; /** * Closes the menu. Emits the cancelable `iv:close` first. * * @param {DropdownReason} [reason] Why the menu is closing. * @returns {void} */ close(reason?: DropdownReason): void; /** * Opens the menu when closed, closes it when open. * * @returns {void} */ toggle(): void; } export type DropdownOptions = { /** * Menu alignment; only `bottom-end` adds a class. */ placement: "bottom-start" | "bottom-end"; /** * Close the menu when an item is activated. */ closeOnSelect: boolean; }; export type DropdownReason = "api" | "trigger" | "escape" | "external"; import { IvComponent } from "../core/component.js";