Drag a React Fragment
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:7
- Comments:9 (3 by maintainers)
Top 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 >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
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.
@johnswanson
display: contents
makes the div not draggable