UNPKG

@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-migration

Version:

An optional Pragmatic drag and drop package that enables rapid migration from react-beautiful-dnd to Pragmatic drag and drop

67 lines (61 loc) 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isEventInInteractiveElement; exports.interactiveTagNames = void 0; exports.isAnInteractiveElement = isAnInteractiveElement; /** * This file is ported almost exactly from `react-beautiful-dnd`. * * In `react-beautiful-dnd` it is relevant to all drags, * but in the migration layer it is only relevant to keyboard drags. * * This is because now the browser is responsible for determining when a * pointer drag can occur. */ var interactiveTagNames = exports.interactiveTagNames = { input: true, button: true, textarea: true, select: true, option: true, optgroup: true, video: true, audio: true }; function isAnInteractiveElement(parent, current) { if (current == null) { return false; } // Most interactive elements cannot have children. However, some can such as 'button'. // See 'Permitted content' on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button // Rather than having two different functions we can consolidate our checks into this single // function to keep things simple. // There is no harm checking if the parent has an interactive tag name even if it cannot have // any children. We need to perform this loop anyway to check for the contenteditable attribute var hasAnInteractiveTag = Boolean(interactiveTagNames[current.tagName.toLowerCase()]); if (hasAnInteractiveTag) { return true; } // contenteditable="true" or contenteditable="" are valid ways // of creating a contenteditable container // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable var attribute = current.getAttribute('contenteditable'); if (attribute === 'true' || attribute === '') { return true; } // nothing more can be done and no results found if (current === parent) { return false; } // recursion to check parent return isAnInteractiveElement(parent, current.parentElement); } function isEventInInteractiveElement(draggable, event) { var target = event.target; if (!(target instanceof HTMLElement)) { return false; } return isAnInteractiveElement(draggable, target); }