A way to drag outside to iframe
See original GitHub issueIs your feature request related to a problem? Please describe. React limits that drag-and-drop within a single HTML document. Somehow we need drag something outside to iframe inside.
Describe the solution you’d like
I find that dnd HTML5backend just trigger drag callbacks in window. So if we can make the components inside iframe trigger those callback.And React.createPortal
make components inside iframe have same DndProvider with outside.It works, luckily. But i worry about may some problem i didn’t notice.And the code is not so convenient with HTML5Backend.
import React, {
useRef,
useEffect,
useContext,
forwardRef,
} from 'react';
import classnames from 'classnames';
import { DndContext } from 'react-dnd';
// Frame base on createPortal inside iframe dom.
import Frame from 'react-frame-component';
const events = [
['dragstart', 'handleTopDragStart', false],
['dragstart', 'handleTopDragStartCapture', true],
['dragend', 'handleTopDragEndCapture', true],
['dragenter', 'handleTopDragEnter', false],
['dragenter', 'handleTopDragEnterCapture', true],
['dragleave', 'handleTopDragLeaveCapture', true],
['dragover', 'handleTopDragOver', false],
['dragover', 'handleTopDragOverCapture', true],
['drop', 'handleTopDrop', false],
['drop', 'handleTopDropCapture', true],
];
export const DndFrame = forwardRef((props = {}, ref) => {
const container = useRef(null);
const dndValue = useContext(DndContext) || {};
const { dragDropManager: { backend = {} } = {} } = dndValue;
const { children, className, containerProps = {}, ...others } = props;
const cls = classnames({
'dnd-frame': true,
[className]: !!className,
});
useEffect(() => {
const { current } = container;
if (!current) {
return;
}
// this make callback run in outside window
events.forEach((eventArgs = []) => {
const [name, callbackName, capture = false] = eventArgs;
const callback = backend[callbackName] && backend[callbackName].bind(backend);
current.addEventListener(name, (...args) => {
callback && callback(...args);
}, capture);
});
}, [container.current]);
return (
<Frame className={cls} ref={ref} {...others}>
<div className="dnd-frame-container" ref={container} {...containerProps}>
{ children }
</div>
</Frame>
);
});
Describe alternatives you’ve considered May you can export some options with HTML5Backend.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How to move / drag element from outside to iframe
One possible solution would be to try extending the Selenium ActionChains API and implement new method(s) that would allow you to start the...
Read more >jQuery : How to move / drag element from outside to iframe
jQuery : How to move / drag element from outside to iframe [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] jQuery ...
Read more >Drag'n'Drop with mouse events - The Modern JavaScript Tutorial
Then on mousemove move it by changing left/top with position:absolute . On mouseup – perform all actions related to finishing the drag'n'drop.
Read more >Using the HTML5 Drag and Drop API - web.dev
It's worth noting that in most browsers, text selections, images, and links are draggable by default. For example, if you drag a link...
Read more >Drag Between Two Iframes - CodePen
<iframe class="dragFrame dragDrop" srcdoc='</html><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found an easier solution to simplify this code, but I am not sure if this one is a better solution. Hope to help you to fix this issue.
For future visitors, there’s a simple solution: https://react-dnd.github.io/react-dnd/examples/dustbin/iframe