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.

Drag a React Fragment

See original GitHub issue

I know that react-dnd requires an actual DOM node to work on. However I wanted to enable dragging a row in my container component using CSS grid. The CSS grid is arranged in rows and columns (using grid-template-columns). In the CSS grid, “rows” are just a collection of elements, there must be no enclosing <div> tag for example (this will break CSS grid).

My CSS grid container:

<div className="Container__grid">
  {list.map(row => <Row key={row.id} {...row} />)}
</div>

I would like to specify my drag source in Row as for example:

render = ({ connectDragSource }) => connectDragSource(
  <React.Fragment>
    <div>a cell</div
    <div>a cell</div>
  </React.Fragment>
);

But that’s not possible because React fragment is not backed up by any DOM node. Any options how to overcome this limitation?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
darthtrevinocommented, Mar 26, 2019

To follow up on this, you can use connectDragSource on a ref that’s a dom node, and this can be rendered inside of a fragment. In this case, the connected element will be the portion of the DOM that’s draggable.

e.g.

<>
   <div ref={connectDragSource}>...</div>
</>
1reaction
drjkuocommented, Nov 18, 2018

@johnswanson display: contents makes the div not draggable

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fragments - React
A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding...
Read more >
Building Complex Nested Drag and Drop User Interfaces With ...
Drag and drop features offer a straightforward experience that many modern web applications use. In this article, we will be showing you how...
Read more >
Fragment in React.js - Tutorialspoint
React Fragment helps in returning multiple elements. The other alternative is to use a html element like div to wrap them.
Read more >
Is it possible to align react Fragement? - Stack Overflow
Fragments are not rendered in the final HTML so they cannot be selected by CSS. Therefore, you should use something which can be...
Read more >
What is the use of Fragment in React ? - GeeksforGeeks
In ReactJS, we render the JSX from the component with the help of a return statement whether written inside the functional component or ......
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