UNPKG

@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-migration

Version:

An optional Pragmatic drag and drop package that enables rapid migration from react-beautiful-dnd to Pragmatic drag and drop

43 lines (40 loc) 1.17 kB
// eslint-disable-next-line import/no-extraneous-dependencies /** * Returns the closest element with `position: absolute` or `null` if none found. */ function getClosestAbsolutePositionedElement(element) { const { position } = getComputedStyle(element); if (position === 'absolute') { return element; } const { parentElement } = element; if (parentElement instanceof HTMLElement) { return getClosestAbsolutePositionedElement(parentElement); } return null; } /** * Returns the closest element that is offset relative to the scroll container. */ export function getClosestPositionedElement({ element, mode }) { var _getClosestAbsolutePo; /** * We use the element directly for standard lists, * because we assume it is positioned in the flow. */ if (mode === 'standard') { return element; } /** * For virtual lists we use the closest element with `position: absolute`, * as this is how virtualization libraries offset elements. */ return (_getClosestAbsolutePo = getClosestAbsolutePositionedElement(element)) !== null && _getClosestAbsolutePo !== void 0 ? _getClosestAbsolutePo : element; }