MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getPosition

Function getPosition

packages/react-aria/src/overlays/calculatePosition.ts:778–801  ·  view source on GitHub ↗
(
  node: Element,
  parent: Element,
  ignoreScale: boolean,
  overrideRect?: Offset | null | undefined
)

Source from the content-addressed store, hash-verified

776}
777
778function getPosition(
779 node: Element,
780 parent: Element,
781 ignoreScale: boolean,
782 overrideRect?: Offset | null | undefined
783): Offset {
784 let style = window.getComputedStyle(node);
785 let offset: Offset;
786 if (style.position === 'fixed') {
787 offset = overrideRect || getRect(node, ignoreScale);
788 } else {
789 offset = getOffset(node, ignoreScale, overrideRect);
790 let parentOffset = getOffset(parent, ignoreScale);
791 let parentStyle = window.getComputedStyle(parent);
792 parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;
793 parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;
794 offset.top -= parentOffset.top;
795 offset.left -= parentOffset.left;
796 }
797
798 offset.top -= parseInt(style.marginTop, 10) || 0;
799 offset.left -= parseInt(style.marginLeft, 10) || 0;
800 return offset;
801}
802
803// Returns the containing block of an element, which is the element that
804// this element will be positioned relative to.

Callers 1

calculatePositionFunction · 0.70

Calls 2

getRectFunction · 0.70
getOffsetFunction · 0.70

Tested by

no test coverage detected