Drag an drop works in Chrome but bugs in Firefox
Unanswered
Californian posted this in #help-forum
CalifornianOP
I have a drag and drop functionality in my Next app. It works fine in Chrome but bugs in Firefox. I trigger the functionality in the
Any idea ? Do I need a polyfill or something like that ?
onMouseDown callback of a div, like onMouseDown={(e) => handleDragStart(e, index)} . The handlers look like the following:const handleDragStart = (event: React.MouseEvent<HTMLDivElement>, index: number) => {
...
document.addEventListener('mousemove', (e) =>
handleDragMove(e, index)
);
document.addEventListener('mouseup', () => handleDragEnd(index));
}
};const handleDragMove = async (event: MouseEvent, index: number) => {
event.preventDefault();
...
}const handleDragEnd = (index: number) => {
...
document.removeEventListener('mousemove', (e) =>
handleDragMove(e, index));
document.removeEventListener('mouseup', () => handleDragEnd(index));
};Any idea ? Do I need a polyfill or something like that ?
8 Replies
CalifornianOP
up
Asiatic Lion
Why not using react-dropzone for drag and dropping files?
CalifornianOP
I don't want to drag and drop files. My feature is more something like making changes in the component when dragging internal elements in the component. For example, making transformations in images
In Chrome it works fine but in Firefox the drag is a bit buggy (it kinda works but I have to go like I would drag and then release the mouse button to be able to drag)
Asiatic Lion
I see what you mean, unfortunately I dont see an issue in the code. Cant help further, sorry for that
googled “firefox onmousedown buggy†and the first result for me had the solution https://forum.babylonjs.com/t/firefox-pointerlock-mousemove-mousedown-behavior/960/7
CalifornianOP
Thanks, I will try it out. I wonder if I will have to find a solution for each browser. Would be good to have a polyfill solving these problems for all browsers.