Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to dragStart(e) a component that is different from e.target? #1032

Closed
zsoerenm opened this issue Oct 16, 2023 · 4 comments · Fixed by #1050
Closed

Is there a way to dragStart(e) a component that is different from e.target? #1032

zsoerenm opened this issue Oct 16, 2023 · 4 comments · Fixed by #1050
Labels
question Further information is requested

Comments

@zsoerenm
Copy link
Contributor

Description

I have a toolbar from where I want to drag in new components. On some issues it is recommended to use dragStart(e) for newly created components, where e is the mousedown event.
However, in my case the component that I want to drag hasn't been created yet, when the user clicks the mouse.
I have to create the component on the fly, when the mouse button is down. Hence, the target of the mousedown event e won't be the target that I'd like to be dragged.
How would I do something like this?

@daybrush daybrush added the question Further information is requested label Oct 29, 2023
@daybrush
Copy link
Owner

@zsoerenm

You can use .dragStart method

onMousedown={e => {
    e.preventDefault();
    moveable.waitToChangeTarget().then(() => {
         moveable.dragStart(e);
   });
}}

https://daybrush.com/moveable/storybook/?path=/story/combination-with-other-components--components-selecto

@zsoerenm
Copy link
Contributor Author

zsoerenm commented Oct 31, 2023

Thanks,
but the problem is that e.target is not the element that I want to drag.
The element that I'd like to drag is created on the mouse down. Therefore, the e.target is different.

@daybrush
Copy link
Owner

@zsoerenm

Setting the target to the created element and doing .dragStart will not be a problem.

@zsoerenm
Copy link
Contributor Author

Okay, does that mean moveable.target and e.target don't have to be the same?
I thought it wasn't possible because e.target is accessed in Gesto here:
https://github.com/daybrush/gesto/blob/bae238937462160a2c9aedab36ce9e4b7132da3a/src/Gesto.ts#L307

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants