UNPKG

@intility/bifrost-react

Version:

React library for Intility's design system, Bifrost.

29 lines (28 loc) 1.34 kB
/** * Check if an element has overflowing scroll content * @param element DOM node * @returns true if the element has any scroll overflow * @example * // find closest parent element that currently has a scrollbar * const scrollContainer = closestElement(isScrollableRightNow, element) */ export declare function isScrollableRightNow(element: HTMLElement): boolean; /** * Check if an element can render a scrollbar * @param element DOM node * @returns true if overflowY is 'auto' or 'scroll' * @example * // find closest parent element that can be scrolled (but may not have a scrollbar currently) * const scrollContainer = closestElement(isEverScrollable, element) */ export declare function isEverScrollable(element: HTMLElement): boolean; /** * Find closest parent element in the DOM tree * @param predicate Function that is called for each parent element until it returns true * @param element Child element (DOM node) to start traversing from * @returns First parent element where predicate returns true, or root node (`document.documentElement`) * @example * // find closest parent `<table>` element * const closestTable = closestElement(el => el.tagName === 'table', element) */ export default function closestElement(predicate: (element: HTMLElement) => boolean, element?: HTMLElement | null): HTMLElement;