Skip to content

Commit

Permalink
fix: use parentNode's ownerDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Oct 10, 2020
1 parent ea753de commit 2e803ef
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/createTippy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export default function createTippy(
let listeners: ListenerObject[] = [];
let debouncedOnMouseMove = debounce(onMouseMove, props.interactiveDebounce);
let currentTarget: Element;
const doc = getOwnerDocument(props.triggerTarget || reference);

// ===========================================================================
// 🔑 Public members
Expand Down Expand Up @@ -159,7 +158,7 @@ export default function createTippy(
instance.props.interactive &&
instance.props.trigger.indexOf('mouseenter') >= 0
) {
doc.addEventListener('mousemove', debouncedOnMouseMove);
getDocument().addEventListener('mousemove', debouncedOnMouseMove);
debouncedOnMouseMove(event);
}
});
Expand Down Expand Up @@ -187,6 +186,11 @@ export default function createTippy(
return currentTarget || reference;
}

function getDocument(): Document {
const parent = getCurrentTarget().parentNode as Element;
return parent ? getOwnerDocument(parent) : document;
}

function getDefaultTemplateChildren(): PopperChildren {
return getChildren(popper);
}
Expand Down Expand Up @@ -282,7 +286,7 @@ export default function createTippy(
}

function cleanupInteractiveMouseListeners(): void {
doc.removeEventListener('mousemove', debouncedOnMouseMove);
getDocument().removeEventListener('mousemove', debouncedOnMouseMove);
mouseMoveListeners = mouseMoveListeners.filter(
(listener) => listener !== debouncedOnMouseMove
);
Expand Down Expand Up @@ -350,13 +354,15 @@ export default function createTippy(
}

function addDocumentPress(): void {
const doc = getDocument();
doc.addEventListener('mousedown', onDocumentPress, true);
doc.addEventListener('touchend', onDocumentPress, TOUCH_OPTIONS);
doc.addEventListener('touchstart', onTouchStart, TOUCH_OPTIONS);
doc.addEventListener('touchmove', onTouchMove, TOUCH_OPTIONS);
}

function removeDocumentPress(): void {
const doc = getDocument();
doc.removeEventListener('mousedown', onDocumentPress, true);
doc.removeEventListener('touchend', onDocumentPress, TOUCH_OPTIONS);
doc.removeEventListener('touchstart', onTouchStart, TOUCH_OPTIONS);
Expand Down Expand Up @@ -1065,7 +1071,7 @@ export default function createTippy(
);
}

doc.addEventListener('mousemove', debouncedOnMouseMove);
getDocument().addEventListener('mousemove', debouncedOnMouseMove);
pushIfUnique(mouseMoveListeners, debouncedOnMouseMove);
debouncedOnMouseMove(event);
}
Expand Down

0 comments on commit 2e803ef

Please sign in to comment.