@carbon/react
Version:
React components for the Carbon Design System
50 lines (49 loc) • 2.02 kB
TypeScript
/**
* Copyright IBM Corp. 2020, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Checks whether the given node or one of its ancestors matches any of the
* specified floating menu selectors.
*
* @param {Node} node - A DOM node.
* @param {string[]} selectorsFloatingMenus - Additional CSS selectors that
* match floating menus.
* @returns {boolean} Whether the node or one of its ancestors is in a floating
* menu.
*/
export declare const elementOrParentIsFloatingMenu: (node: Node, selectorsFloatingMenus?: string[]) => boolean;
/**
* Ensures the focus is kept within the given container by implementing
* "focus-wrap" behavior.
*/
export declare const wrapFocus: ({ bodyNode, startTrapNode, endTrapNode, currentActiveNode, oldActiveNode, selectorsFloatingMenus, }: {
/** The DOM node of the container. */
bodyNode: HTMLElement | null;
/** The start sentinel node for focus trapping. */
startTrapNode: HTMLElement | null;
/** The end sentinel node for focus trapping. */
endTrapNode: HTMLElement | null;
/** The current active node (i.e., the one with focus). */
currentActiveNode: HTMLElement;
/** The previous active node (i.e., the one that had focus before). */
oldActiveNode: HTMLElement;
/** CSS selectors for floating menus. */
selectorsFloatingMenus?: string[];
}) => void;
/**
* Ensures the focus is kept in the given container, implementing "focus-wrap"
* behavior.
*
* Note: This must be called *before* focus moves using `onKeyDown` or similar.
*/
export declare const wrapFocusWithoutSentinels: ({ containerNode, currentActiveNode, event, }: {
/** The container node within which to keep focus. */
containerNode: HTMLElement;
/** The current active node (i.e., the one with focus). */
currentActiveNode: HTMLElement;
/** The event that triggered this function. */
event: React.KeyboardEvent | KeyboardEvent;
}) => void;