admin管理员组文章数量:1401964
I've been trying to find an answer to this for a while now and the library, while being very nice and well done... lack very much in clear documentation. I'm hoping to partipate in improving it once I get a clear understanding of it.
Here's what I'm trying to acplish.
I have a hierarchy of object that is quite plex and multiple draggable type can be mixed in the same level and some of these can even have childrens that are these same dragable.
That render the "type" property not working for me. I want to bine "IsDropDisabled" with "draggingOverWith" to make it happen instead and manage the plexity there.
Basically, the idea is that when the item I'm currently dragging is passing "over" a potential dropable, I want to check the type against an "allowed" array of type and allow it if the type is right.
For that, I want to access "snapshot.draggingOverWith" from the Droppable but the issue is... that "IsDropDisabled" is above in the code hierarchy so I'm kinda of lost as to how the code in the library actually does that parison.
The idea would be something like that:
<Droppable droppableId={props.verticalgroup.id} isDropDisabled={() => {CompareTypes(snapshot.draggingOverWith, ['Type1', 'Type3'])}>
{(provided, snapshot) => (
<div
{...provided.droppableProps}
ref={provided.innerRef}
className={snapshot.isDraggingOver ? 'changeBackground' : ''}
>
...[Other Code]
</div>
)}
</Droppable>
Thanks for helping.
I've been trying to find an answer to this for a while now and the library, while being very nice and well done... lack very much in clear documentation. I'm hoping to partipate in improving it once I get a clear understanding of it.
Here's what I'm trying to acplish.
I have a hierarchy of object that is quite plex and multiple draggable type can be mixed in the same level and some of these can even have childrens that are these same dragable.
That render the "type" property not working for me. I want to bine "IsDropDisabled" with "draggingOverWith" to make it happen instead and manage the plexity there.
Basically, the idea is that when the item I'm currently dragging is passing "over" a potential dropable, I want to check the type against an "allowed" array of type and allow it if the type is right.
For that, I want to access "snapshot.draggingOverWith" from the Droppable but the issue is... that "IsDropDisabled" is above in the code hierarchy so I'm kinda of lost as to how the code in the library actually does that parison.
The idea would be something like that:
<Droppable droppableId={props.verticalgroup.id} isDropDisabled={() => {CompareTypes(snapshot.draggingOverWith, ['Type1', 'Type3'])}>
{(provided, snapshot) => (
<div
{...provided.droppableProps}
ref={provided.innerRef}
className={snapshot.isDraggingOver ? 'changeBackground' : ''}
>
...[Other Code]
</div>
)}
</Droppable>
Thanks for helping.
Share Improve this question asked May 22, 2021 at 3:38 Johnny PrescottJohnny Prescott 2711 gold badge9 silver badges24 bronze badges1 Answer
Reset to default 5 +50I think you could try to use the onDragStart
method from the DragDropContext
and send required information to Droppable for isDropDisabled
to work conditionally.
Like they do here on their egghead course video.
const [isDropDisabled, setIsDropDisabled] = useState(false);
const onDragStart = (task) => {
setIsDropDisabled(task.something === 'xyz') // <= your condition goes here
}
and
<DragDropContext onDragStart={this.onDragStart} ...>
...
</DragDropContext>
lastly, in your Droppable
use that as value
<Droppable droppableId={props.verticalgroup.id} isDropDisabled={isDropDisabled}>
{(provided, snapshot) => (
<div
{...provided.droppableProps}
ref={provided.innerRef}
className={snapshot.isDraggingOver ? 'changeBackground' : ''}
>
...[Other Code]
</div>
)}
</Droppable>
本文标签: javascriptReactDnD Using IsDropDisabled to disable dropping wrong element typeStack Overflow
版权声明:本文标题:javascript - React-DnD: Using IsDropDisabled to disable dropping wrong element type - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744288370a2598993.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论