Fix: IE11 SVG elements have neither classList nor parentElement... (#26035)

This commit is contained in:
Robert Monfera 2018-11-21 19:21:51 +01:00 committed by GitHub
parent c8647f109b
commit b3ef0c4eaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,10 +6,11 @@
import { withHandlers } from 'recompose';
const ancestorElement = (element, className) => {
const ancestorElement = element => {
if (!element) return element;
do if (element.classList.contains(className)) return element;
while ((element = element.parentElement));
// IE11 has no classList on SVG elements, but we're not interested in SVG elements
do if (element.classList && element.classList.contains('canvasPage')) return element;
while ((element = element.parentElement || element.parentNode)); // no IE11 SVG parentElement
};
const localMousePosition = (box, clientX, clientY) => {
@ -27,7 +28,7 @@ const resetHandler = () => {
const setupHandler = (commit, target) => {
// Ancestor has to be identified on setup, rather than 1st interaction, otherwise events may be triggered on
// DOM elements that had been removed: kibana-canvas github issue #1093
const canvasPage = ancestorElement(target, 'canvasPage');
const canvasPage = ancestorElement(target);
if (!canvasPage) return;
const canvasOrigin = canvasPage.getBoundingClientRect();
window.onmousemove = ({ clientX, clientY, altKey, metaKey, shiftKey }) => {
@ -63,7 +64,7 @@ const handleMouseDown = (commit, e, isEditable) => {
resetHandler();
return; // left-click and edit mode only
}
const ancestor = ancestorElement(target, 'canvasPage');
const ancestor = ancestorElement(target);
if (!ancestor) return;
const { x, y } = localMousePosition(ancestor, clientX, clientY);
setupHandler(commit, ancestor);