/** * Tabs component. * * @augments IvComponent */ export class Tabs extends IvComponent { /** @type {Readonly} */ static defaults: Readonly; /** * Returns the tabs instance attached to `el`, if any. * * @param {Element} el Host element. * @returns {Tabs|undefined} The instance or `undefined`. */ static get(el: Element): Tabs | undefined; /** * Returns the existing instance or creates one. * * @param {Element} el Host element. * @param {Partial} [options] Options passed in JavaScript. * @returns {Tabs} The instance. */ static getOrCreate(el: Element, options?: Partial): Tabs; /** * Instantiates every `[data-iv-component="tabs"]` inside `root`. * * @param {ParentNode} [root] Subtree to scan. * @returns {Tabs[]} Newly created instances. */ static initAll(root?: ParentNode): Tabs[]; /** * @param {Element} el The `.iv-tabs` container. * @param {Partial} [options] Options passed in JavaScript. */ constructor(el: Element, options?: Partial); /** @type {Map>} Attributes to restore. */ _saved: Map>; /** @type {Element[]} Headings this instance made screen-reader only. */ _srOnly: Element[]; /** @type {TabPair[]} Tab/panel pairs, in document order. */ _pairs: TabPair[]; /** @type {HTMLElement|null} Currently selected tab. */ _active: HTMLElement | null; /** @type {Element|null} The `.iv-tabs__list` of this instance. */ _list: Element | null; /** * Resolved options. * * @returns {Readonly} The options. */ get options(): Readonly; /** * The currently selected tab. * * @returns {HTMLElement|null} The active tab, or `null` when there is none. */ get activeTab(): HTMLElement | null; /** * The panel of the currently selected tab. * * @returns {HTMLElement|null} The active panel, or `null`. */ get activePanel(): HTMLElement | null; /** * Tells whether a descendant belongs to this instance and not to nested tabs. * * @param {Element} el Candidate descendant. * @returns {boolean} `true` when the closest `.iv-tabs` is this element. */ _owns(el: Element): boolean; /** * Resolves the panel a tab points at through its `href` hash. * * @param {Element} tab Tab element. * @returns {Element|null} The panel, or `null` when it does not exist. */ _panelFor(tab: Element): Element | null; /** * Remembers the current value of an attribute, once per element. * * @param {Element} el Element to remember. * @param {string} name Attribute name. * @returns {void} */ _remember(el: Element, name: string): void; /** * 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; /** * Removes a managed attribute, remembering its previous value. * * @param {Element} el Target element. * @param {string} name Attribute name. * @returns {void} */ _unset(el: Element, name: string): void; /** * Returns the pair a tab belongs to. * * @param {Element} tab Tab element. * @returns {TabPair|null} The pair, or `null`. */ _pairOf(tab: Element): TabPair | null; /** * Resolves a tab from an id (of the tab or of its panel) or an element. * * @param {string|Element} target Tab id, panel id, tab element or panel element. * @returns {HTMLElement|null} The matching tab. */ _resolve(target: string | Element): HTMLElement | null; /** * Applies the selected state to a tab and its panel. * * @param {HTMLElement} active Tab to select. * @returns {void} */ _activate(active: HTMLElement): void; /** * Handles clicks on a tab: the anchor never navigates while JavaScript runs. * * @param {Event} event Click event. * @returns {void} */ _onClick(event: Event): void; /** * Roving focus and activation. * * @param {Event} event Keydown event. * @returns {void} */ _onKeydown(event: Event): void; /** * Selects a tab. Emits the cancelable `iv:change` first. * * @param {string|Element} target Tab id, panel id, tab element or panel element. * @returns {void} */ select(target: string | Element): void; /** * Selects the next tab, wrapping around. * * @returns {void} */ next(): void; /** * Selects the previous tab, wrapping around. * * @returns {void} */ prev(): void; /** * Selects the tab `delta` positions away, wrapping around. * * @param {number} delta Offset, `1` or `-1`. * @returns {void} */ _step(delta: number): void; } export type TabsOptions = { /** * Whether moving focus also selects. */ activation: "automatic" | "manual"; /** * Arrow keys and `aria-orientation`. */ orientation: "horizontal" | "vertical"; }; export type TabPair = { /** * The tab control. */ tab: HTMLElement; /** * The panel it controls. */ panel: HTMLElement; }; import { IvComponent } from "../core/component.js";