Skip to content

Commit

Permalink
[Canvas] Fix incompatible ie11 method (#50007) (#50480)
Browse files Browse the repository at this point in the history
* Fix incompatible ie11 method

* Comment about origin of polyfill
  • Loading branch information
Corey Robertson authored Nov 13, 2019
1 parent 384b037 commit c8d8047
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ const configuration = {
tooltipZ: 1100,
};

// Polyfill for browsers (IE11) that don't have element.closest
// From: https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
function closest(s) {
let el = this;
const matchFn = el.matches ? 'matches' : 'msMatchesSelector';

do {
if (el[matchFn](s)) {
return el;
}
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
}

const componentLayoutState = ({
aeroStore,
setAeroStore,
Expand Down Expand Up @@ -193,8 +208,15 @@ export const InteractivePage = compose(
})),
withProps((...props) => ({
...props,
canDragElement: element =>
!element.closest('.embeddable') || element.closest('.embPanel__header'),
canDragElement: element => {
const hasClosest = typeof element.closest === 'function';

if (hasClosest) {
return !element.closest('.embeddable') || element.closest('.embPanel__header');
} else {
return !closest.call(element, '.embeddable') || closest.call(element, '.embPanel__header');
}
},
})),
withHandlers(eventHandlers), // Captures user intent, needs to have reconciled state
() => InteractiveComponent
Expand Down

0 comments on commit c8d8047

Please sign in to comment.