Sign up (with export icon)

utils/dom/findclosestscrollableancestor

Api-module iconmodule

Functions

  • Chevron-right icon

    findClosestScrollableAncestor( domElement ) → HTMLElement | null

    Returns the closest scrollable ancestor of a DOM element.

    The search crosses shadow DOM boundaries, continuing from the host element of a shadow root instead of stopping at it. Without that, an element rendered inside a shadow tree would report no scrollable ancestor at all, even when one exists further up in the surrounding document, because the walk goes over parentElement, which is null for a direct child of a shadow root. Works for both open and closed shadow roots.

    Parameters

    domElement: HTMLElement

    DOM element.

    Returns

    HTMLElement | null

    First ancestor of domElement that is scrollable or null if such ancestor doesn't exist.