question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] dragAndDrop is not working with react-beautiful-dnd

See original GitHub issue

Context:

  • Playwright Version: 1.18.1
  • Operating System: Mac
  • Node.js version: 14
  • Browser: Desktop Electron App (Electron version 13)
  • Extra: Maybe issue is with this library - react-beautiful-dnd

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and that we can run and debug locally. For example:

  await page.dragAndDrop(`#Test123`, `#test124`)

Describe the bug Element is not dropped at the target location, but I do see some kind of fluctuation at source element. See attached video for reference.

https://www.loom.com/share/fd512a9448774a729cd8a1caeaa4fe01

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
emanuellarinicommented, Jun 2, 2022

For those who might search for this… I have a working solution… keep in mind that you mind need to make adjustments in X and Y coordinates depending on your needs.

const dragAndDrop = (page, subjectSelector, targetSelector) => {
    const subjectElement = await page.waitForSelector(subjectSelector);
    const targetElement = await page.waitForSelector(targetSelector);
    
    const subjectElementBound = await subjectElement.boundingBox();
    const targetElementBound = await targetElement.boundingBox();

    await page.mouse.move(
      subjectElementBound.x,
      subjectElementBound.y,
      { steps: 10 } // this is the most important part!
    );

    await page.dispatchEvent(
      subjectSelector,
      'mousedown',
      {
        button: 0,
        force: true
      }
    );
   
    // the x and y below is up to you to determine, in my case it was a checkers game so I needed to calculate a bit
    // if you are using with lists, you might try and consider the numbers below.. 
   
    const x = targetElementBound.x + targetElementBound.width / 2;
    const y = targetElementBound.y + targetElementBound.height / 2;

    // steps are needed here as well
    await page.mouse.move(x, y, { steps: 10 }); 

    await page.dispatchEvent(targetSelector, 'mouseup', {
      button: 0
    });
}
3reactions
johanlajilicommented, Jun 13, 2022

For those who might search for this… I have a working solution… keep in mind that you mind need to make adjustments in X and Y coordinates depending on your needs.

const dragAndDrop = (page, subjectSelector, targetSelector) => {
    const subjectElement = await page.waitForSelector(subjectSelector);
    const targetElement = await page.waitForSelector(targetSelector);
    
    const subjectElementBound = await subjectElement.boundingBox();
    const targetElementBound = await targetElement.boundingBox();

    await page.mouse.move(
      subjectElementBound.x,
      subjectElementBound.y,
      { steps: 10 } // this is the most important part!
    );

    await page.dispatchEvent(
      subjectSelector,
      'mousedown',
      {
        button: 0,
        force: true
      }
    );
   
    // the x and y below is up to you to determine, in my case it was a checkers game so I needed to calculate a bit
    // if you are using with lists, you might try and consider the numbers below.. 
   
    const x = targetElementBound.x + targetElementBound.width / 2;
    const y = targetElementBound.y + targetElementBound.height / 2;

    // steps are needed here as well
    await page.mouse.move(x, y, { steps: 10 }); 

    await page.dispatchEvent(targetSelector, 'mouseup', {
      button: 0
    });
}

You beauty

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · atlassian/react-beautiful-dnd - GitHub
Beautiful and accessible drag and drop for lists with React - Issues ... Error while testing a component that uses React Beautiful DnD...
Read more >
How to implement drag and drop in React with React DnD
All elements that are draggable and droppable need to be enclosed inside React DnD's context provider, which is used for initializing and also ......
Read more >
reactjs - React props being mutated before setState called ...
A couple things I tried: smacking key everywhere and making them unique, in case this is a DnD problem; making copies of the...
Read more >
Troubleshooting - React DnD - GitHub Pages
This page is dedicated to the problems you might bump into while using React DnD. Could not find the drag and drop manager...
Read more >
react-beautiful-dnd/README.md - UNPKG
**. Within that subset of functionality react-beautiful-dnd offers a powerful, natural and beautiful drag and drop experience. However, it does not provide the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found