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

Please pass the sourceEvent to onMoveStart, onMove and onMoveEnd #1676

Closed
Jinhai opened this issue Nov 16, 2021 · 5 comments · Fixed by #1555
Closed

Please pass the sourceEvent to onMoveStart, onMove and onMoveEnd #1676

Jinhai opened this issue Nov 16, 2021 · 5 comments · Fixed by #1555

Comments

@Jinhai
Copy link

Jinhai commented Nov 16, 2021

d3-drag stops the even propagation at https://github.com/d3/d3-drag/blob/main/src/drag.js#L58
This makes client code cannot get on mousedown event.
One possible fix is to pass the sourceEvent to onMoveStart, onMove and onMoveEnd, same as other handlers.

@Jinhai Jinhai changed the title pass the sourceEvent to onMoveStart, onMove and onMoveEnd Please pass the sourceEvent to onMoveStart, onMove and onMoveEnd Nov 16, 2021
@moklick
Copy link
Member

moklick commented Nov 17, 2021

Hey @Jinhai could you explain what you want to achieve?

@Jinhai
Copy link
Author

Jinhai commented Nov 17, 2021

Hi @moklick, thanks for checking.
Commonly used libraries, like antd provides Popover and Dropdown UI components, they rely on mousedown event to auto close the Popover / Dropdown.
With react-flow, because d3-drag stops the event propagation, when clicking on react-flow pane, those UI components can not work properly.
I see the need of d3-drag to stop propagation to make sure gesture are not interrupted. But if the sourceEvent is passed to react-flow handlers, in this case onMoveStart, onMove and onMoveEnd, same as other handlers. Client code will have a chance to know there is a mousedown in react-flow pane, so client code can do necessary operation when needed. In above antd Popover / Dropdown case, client code can sent out a event to trigger the close properly. There are other cases too.

@BrianHung
Copy link

Encountered same problem integrating https://headlessui.dev/react/dialog with react flow. The dialog uses an event listener on window to listen for click outside events to close any currently open dialog. Right now opening a dialog then clicking on the canvas does not work since canvas intercepts and stops propagation of the event. As a result, the dialog will stay open.

A fix on the dialog library side would be to set capturing=true for the event listener, but I’ve looked at various other dialog libraries such as radix and they also run into the same problem.

@moklick

@moklick
Copy link
Member

moklick commented Feb 22, 2022

We updated the handlers for v10 and pass the source event:

export type OnMove = (event: MouseEvent | TouchEvent, viewport: Viewport) => void;
export type OnMoveStart = OnMove;
export type OnMoveEnd = OnMove;

@Jinhai
Copy link
Author

Jinhai commented Feb 28, 2022

We updated the handlers for v10 and pass the source event:

export type OnMove = (event: MouseEvent | TouchEvent, viewport: Viewport) => void;
export type OnMoveStart = OnMove;
export type OnMoveEnd = OnMove;

Awesome. Thank you!

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

Successfully merging a pull request may close this issue.

3 participants