最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React-beautiful-dnd: How to drag one element from a different DragDropContext to another DragDropContext - Stack Ov

programmeradmin1浏览0评论

I want to move one element from a different DragDropContext to another:

I have a: // sidebar.js

<DragDropContext onDragEnd={() => console.log('sidebar end drag')}>

    <Droppable droppableId="sidebar">
       {provided => 
        <Draggable 
           ref={provided.innerRef} 
           {...provided.draggableProps} 
           {...other props}
         >
           I can be dragged
         </Draggable>
       }
    </Droppable>

</DragDropContext >

// footerDroppable.js


    <Droppable droppableId="footerDrop">
       {provided => 
        <Draggable 
           ref={provided.innerRef} 
           {...provided.draggableProps} 
           {...other props}
         >
           I'm a footer drag
         </Draggable>
       }
    </Droppable>

</DragDropContext >

// the structure

<div>
  <Sidebar> // first drag context
  <div>
    <footer>
       <other elements />
       <FooterDroppable /> // second drag context
    <footer>
  <div/>

can I move the draggable elemtn from the footer to the sidebar / vice versa?

Sure I can just move the DragDropContext on the parent of both ponents (which I know how to do) but ARE THERE OTHER WAY aside from having a one parent DragDropContext??

P.S. the code above are not the exact structure/code but more like a prototype so you can visualize since I'm working on a bigger app.

I want to move one element from a different DragDropContext to another:

I have a: // sidebar.js

<DragDropContext onDragEnd={() => console.log('sidebar end drag')}>

    <Droppable droppableId="sidebar">
       {provided => 
        <Draggable 
           ref={provided.innerRef} 
           {...provided.draggableProps} 
           {...other props}
         >
           I can be dragged
         </Draggable>
       }
    </Droppable>

</DragDropContext >

// footerDroppable.js


    <Droppable droppableId="footerDrop">
       {provided => 
        <Draggable 
           ref={provided.innerRef} 
           {...provided.draggableProps} 
           {...other props}
         >
           I'm a footer drag
         </Draggable>
       }
    </Droppable>

</DragDropContext >

// the structure

<div>
  <Sidebar> // first drag context
  <div>
    <footer>
       <other elements />
       <FooterDroppable /> // second drag context
    <footer>
  <div/>

can I move the draggable elemtn from the footer to the sidebar / vice versa?

Sure I can just move the DragDropContext on the parent of both ponents (which I know how to do) but ARE THERE OTHER WAY aside from having a one parent DragDropContext??

P.S. the code above are not the exact structure/code but more like a prototype so you can visualize since I'm working on a bigger app.

Share Improve this question asked Nov 27, 2019 at 13:58 I am LI am L 4,6626 gold badges37 silver badges54 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

As you stated, you can have a single DragDropContext to handle d'n'd between multiple Droppable.

And there's no other way to do it (right now) with react-beautiful-dnd.

Try this option out https://react-beautiful-dndlify.app/?path=/story/multiple-horizontal-lists--stress-test from beautiful-dnd

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论