| 1 |
import getWindowSizes from './getWindowSizes'; |
| 2 |
import getClientRect from './getClientRect'; |
| 3 |
|
| 4 |
/** |
| 5 |
* Get the position of the given element, relative to its offset parent |
| 6 |
* @method |
| 7 |
* @memberof Popper.Utils |
| 8 |
* @param {Element} element |
| 9 |
* @return {Object} position - Coordinates of the element and its `scrollTop` |
| 10 |
*/ |
| 11 |
export default function getOffsetRect(element) { |
| 12 |
let elementRect; |
| 13 |
if (element.nodeName === 'HTML') { |
| 14 |
const { width, height } = getWindowSizes(element.ownerDocument); |
| 15 |
elementRect = { |
| 16 |
width, |
| 17 |
height, |
| 18 |
left: 0, |
| 19 |
top: 0, |
| 20 |
}; |
| 21 |
} else { |
| 22 |
elementRect = { |
| 23 |
width: element.offsetWidth, |
| 24 |
height: element.offsetHeight, |
| 25 |
left: element.offsetLeft, |
| 26 |
top: element.offsetTop, |
| 27 |
}; |
| 28 |
} |
| 29 |
|
| 30 |
// position |
| 31 |
return getClientRect(elementRect); |
| 32 |
} |