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

Fix : React DND broken when used within a NodeViewWrapper #5023

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tej1562
Copy link

@tej1562 tej1562 commented Apr 1, 2024

Drag event doesn't work on components wrapped inside a NodeViewWrapper.

Please describe your changes

Currently, drag events are explicitly prevented on NodeView. This is also applied to NodeView children due to event propagation, thus preventing drag events on the components inside NodeView. This PR adds a check to ensure drag events are only prevented on the NodeView parent.

How did you accomplish your changes

Added event target check to ensure drag prevention on NodeView doesn't propagate to child components.

    if (!isDraggable && isSelectable && isDragEvent && event.target === this.dom) {
      event.preventDefault()
    }

    if (isDraggable && isDragEvent && !isDragging && event.target === this.dom) {
      event.preventDefault()
      return false
    }

How have you tested your changes

Created a NodeView with a react dnd component using NodeViewWrapper. Drag works as expected on the react dnd component.

How can we verify your changes

Create a NodeView with draggable component and check if component can be dragged.

Remarks

[add any additional remarks here]

Checklist

  • The changes are not breaking the editor
  • Added tests where possible
  • Followed the guidelines
  • Fixed linting issues

Related issues

#5018

Copy link

netlify bot commented Apr 1, 2024

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 185c1b4
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/660ab5afa4a13a0009dbeed4
😎 Deploy Preview https://deploy-preview-5023--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tej1562 tej1562 force-pushed the fix/react-dnd-broken-inside-nodeviewrapper branch from c859f2e to 185c1b4 Compare April 1, 2024 13:25
@bdbch
Copy link
Contributor

bdbch commented Apr 6, 2024

Since you check for this.dom - would that break something if I drag a child node of my prosemirror node that is not supposed to be draggable?

@bdbch bdbch closed this Apr 6, 2024
@bdbch bdbch reopened this Apr 6, 2024
@bdbch
Copy link
Contributor

bdbch commented Apr 6, 2024

Sorry, misclicked there!

Oops

@tej1562
Copy link
Author

tej1562 commented Apr 6, 2024

The drag on child node won't affect the drag behaviour of parent node. Here, this.dom refers to dom element representing the parent NodeView and it's drag behaviour only depends on the draggable property. If draggable is set to false on the NodeView, then it remains undraggable but child nodes within NodeView can still be dragged.

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

Successfully merging this pull request may close these issues.

None yet

2 participants