/** * What the container needs to know about one tab to choose a selection and to * move focus. */ export interface TabState { /** The value that identifies the tab in its group. */ value: string | undefined; /** Whether the tab is unavailable. */ disabled: boolean; } /** A key press that moves focus to another tab. */ export interface TabFocusAction { /** The kind of action. */ type: 'focus'; /** The index of the tab that takes focus. */ index: number; } /** A key press that selects the focused tab. */ export interface TabActivateAction { /** The kind of action. */ type: 'activate'; } /** * What a key press inside the tab list does. The list uses manual * activation, so moving focus never selects. */ export type TabKeyAction = TabFocusAction | TabActivateAction; /** * Returns the direct `nv-tabitem` children of a container, in source order. * * Scoped to direct children so a tab group nested inside a panel that sits in * the same container does not take part in the outer one's selection. * @param {HTMLElement} container - The `nv-tabs` element. * @returns {HTMLNvTabitemElement[]} The container's own tabs. */ export declare function getTabItems(container: HTMLElement): HTMLNvTabitemElement[]; /** * Reads the state of a tab from its element. * * The property wins whenever it is set, and the attribute is the fallback. A * tab that has not upgraded yet only has its attributes. A tab that has * upgraded can carry a stale attribute: `disabled` reflects only at the next * render, so enabling a tab and selecting it in one step sees `false` on the * property and the old attribute together. * @param {HTMLNvTabitemElement} item - The tab element. * @returns {TabState} The value and the disabled state of the tab. */ export declare function readTabState(item: HTMLNvTabitemElement): TabState; /** * Returns the index of the first tab that is available. * @param {TabState[]} tabs - The tabs in source order. * @returns {number} The index, or -1 when every tab is disabled. */ export declare function firstEnabledIndex(tabs: TabState[]): number; /** * Returns the index of the last tab that is available. * @param {TabState[]} tabs - The tabs in source order. * @returns {number} The index, or -1 when every tab is disabled. */ export declare function lastEnabledIndex(tabs: TabState[]): number; /** * Returns the next available tab in one direction, wrapping at the ends. * * Disabled tabs are skipped, as the scoping document asks. Wrapping follows * the WAI-ARIA tabs pattern: Right on the last tab goes to the first. * @param {TabState[]} tabs - The tabs in source order. * @param {number} from - The index to start from. It is not a candidate itself. * @param {number} direction - 1 for forward, -1 for backward. * @returns {number} The index, or -1 when no other tab is available. */ export declare function stepEnabledIndex(tabs: TabState[], from: number, direction: 1 | -1): number; /** * Finds the tab that takes over from a selection that was just lost. * * It looks in the order the tabs had before the change, not in the new one: * several tabs can leave in one batch, so a position in the old list says * nothing about the new list. The next surviving neighbour wins, then the * previous one, which keeps the selection near where the user was. Tabs that * were added in the same batch are not neighbours and are not considered. * @param {T[]} previous - The tabs in their order before the change. * @param {number} lostIndex - The position of the lost selection in `previous`. * @param {(item: T) => boolean} isAvailable - Whether a tab is still there and * enabled. * @returns {T | undefined} The tab that takes over, if any. */ export declare function findReplacement(previous: T[], lostIndex: number, isAvailable: (item: T) => boolean): T | undefined; /** * Chooses which tab is selected. * * An available tab whose value matches wins. Otherwise the preferred tab wins * when it is available; the group passes the tab that takes over from a lost * selection. Otherwise the first available tab wins. * @param {TabState[]} tabs - The tabs in source order. * @param {string | undefined} value - The value the container holds. * @param {number} [preferredIndex] - The tab to select when no tab matches * `value`. Leave it out when there is no preference. * @returns {number} The index of the selected tab, or -1 when no tab is * available. */ export declare function resolveSelectedIndex(tabs: TabState[], value: string | undefined, preferredIndex?: number): number; /** * Says what a key press does on the focused tab. * * Left and Right swap in a right-to-left layout, because "next" is then to the * left. Home and End go to the first and the last available tab. Enter and * Space select the focused tab. * * A navigation key is always taken, even when no other tab can take focus: * focus then stays where it is. A key the group let through would scroll a * horizontally scrollable page or ancestor instead. * @param {string} key - The `KeyboardEvent.key` value. * @param {TabState[]} tabs - The tabs in source order. * @param {number} index - The index of the focused tab. * @param {boolean} [rtl] - Whether the tab list is laid out right to left. * @returns {TabKeyAction | null} What to do, or null when the key does nothing * here. */ export declare function getTabKeyAction(key: string, tabs: TabState[], index: number, rtl?: boolean): TabKeyAction | null;