Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const isOverflowing = element => {
const doc = ownerDocument(element);
const win = ownerWindow(doc);
const isBody = element && element.tagName.toLowerCase() === 'body';
/* istanbul ignore next */
if (!isWindow(doc) && !isBody) {
return element.scrollHeight > element.clientHeight;
}
const style = win.getComputedStyle(doc.body);
const marginLeft = parseInt(style.getPropertyValue('margin-left'), 10);
const marginRight = parseInt(style.getPropertyValue('margin-right'), 10);
return marginLeft + doc.body.clientWidth + marginRight < win.innerWidth;
};
const elemRect = {
width: element.clientWidth,
height: element.clientHeight
};
// Get the transform origin point on the element itself
const transformOrigin = this.getTransformOrigin(elemRect, contentAnchorOffset);
// Calculate element positioning
let top = anchorOffset.top - transformOrigin.vertical;
let left = anchorOffset.left - transformOrigin.horizontal;
const bottom = top + elemRect.height;
const right = left + elemRect.width;
// Use the parent window of the anchorEl if provided
const containerWindow = ownerWindow(getAnchorEl(anchorEl));
// Window thresholds taking required margin into account
const heightThreshold = containerWindow.innerHeight - marginThreshold;
const widthThreshold = containerWindow.innerWidth - marginThreshold;
// Check if the vertical axis needs shifting
if (top < marginThreshold) {
const diff = top - marginThreshold;
top -= diff;
transformOrigin.vertical += diff;
} else if (bottom > heightThreshold) {
const diff = bottom - heightThreshold;
top -= diff;
transformOrigin.vertical += diff;
}
function getTranslateValue(props, node) {
const { direction } = props;
const rect = node.getBoundingClientRect();
let transform;
if (node.fakeTransform) {
transform = node.fakeTransform;
} else {
const computedStyle = ownerWindow(node).getComputedStyle(node);
transform = computedStyle.getPropertyValue('-webkit-transform') || computedStyle.getPropertyValue('transform');
}
let offsetX = 0;
let offsetY = 0;
if (transform && transform !== 'none' && typeof transform === 'string') {
const transformValues = transform.split('(')[1].split(')')[0].split(',');
offsetX = parseInt(transformValues[4], 10);
offsetY = parseInt(transformValues[5], 10);
}
if (direction === 'left') {
return `translateX(100vw) translateX(-${rect.left - offsetX}px)`;
} else if (direction === 'right') {
return `translateX(-${rect.left + rect.width + GUTTER - offsetX}px)`;
function ownerWindow(componentOrElement) {
let doc = ownerDocument(componentOrElement);
return getOwnerWindow(doc);
}
export default function (componentOrElement) {
return ownerWindow(ReactDOM.findDOMNode(componentOrElement));
}
componentDidMount() {
this.button = findDOMNode(this);
listenForFocusKeys(ownerWindow(this.button));
}