Sharing How to Block drag animation of a parent element from a child element drag event. #2565
mitchell-up
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Before discussing my idea, please share your idea, if you hava a more methods or approach. Also I'll really appreciate if you could review the codes.
Problem
We often encounter situations where we need to make draggable UI which contains other draggable elements.
The problem is that if you drag a child element, drag animations will occur at both a child itself and its parent because of
event propagation.So we can come up with a simple solution using
event.stopPropagation()like below.But it didn't work.
Solution
So I'm gonna approach that
dragprop state in parent container can be changed by drag event on a child element in the parent.Example below is making a draggable container for Modal.
1. Manage drag state using ContextAPI.
Pass
dragState,setDragStateintoBottomDragContextso that inner component can change the state.2. Inner component changes that drag state.
Now we can change the parent
dragstate usinguseContexton any component. But I suggest to make wrapping component changingdragstate.Use Case
Beta Was this translation helpful? Give feedback.
All reactions