Sign up (with export icon)

utils/dom/getpositionedancestor

Api-module iconmodule

Functions

  • Chevron-right icon

    getPositionedAncestor( element? ) → HTMLElement | null

    Returns the element the given one is laid out against while absolutely positioned – the element whose padding box its top and left are relative to. Returns null when there is nothing to compensate for: the element is laid out against the initial containing block, is position: fixed, or is not rendered at all.

    Use it when turning a position measured against the viewport into the top and left to set on an absolutely positioned element, by subtracting the returned element's padding-box offset – the way toAbsoluteRect and getOptimalPosition do.

    The layout-aware counterpart of Element#offsetParent, and what to reach for instead of it: this one follows the flattened tree, the one the browser lays out, so it stays right for slotted content – an editor slotted into a container component – where offsetParent names an element that does not lay that content out. Falls back to offsetParent for slotted content inside a closed root, whose slot the DOM standard does not expose.

    Parameters

    element?: HTMLElement

    The native DOM element to be checked.

    Returns

    HTMLElement | null