Simulation DragAndDrop not working with dispatchEvent

0 Answers 41 Views
Drag and Drop
Mikalai
Top achievements
Rank 1
Mikalai asked on 18 Jan 2024, 05:24 PM | edited on 18 Jan 2024, 05:25 PM

I have function for simulating DragAndDrop, if i use that i see hint but if i change position and drop it's not working.
is this even possible? I use DragTarget and DropTarget Directives

function simulateDragAndDrop(element, destination) {
  const mouseDownEvent = new MouseEvent('mousedown', { bubbles: true, cancelable: true })
  const mouseUpEvent = new MouseEvent('mouseup', { bubbles: true, cancelable: true })
  const mouseMoveEvent = new MouseEvent('mousemove', {
    bubbles: true,
    cancelable: true,
    clientX: destination.offsetLeft,
    clientY: destination.offsetTop + destination.offsetHeight,
  })

  element.dispatchEvent(mouseDownEvent)
  document.dispatchEvent(mouseMoveEvent)
  const hint = document.querySelector('.drag-hint')
  hint.style.left = `${destination.offsetLeft}px`
  hint.style.top = `${destination.offsetTop + destination.offsetHeight}px`
  document.dispatchEvent(mouseUpEvent)
}


No answers yet. Maybe you can help?

Tags
Drag and Drop
Asked by
Mikalai
Top achievements
Rank 1
Share this question
or