Skip to content

Respect canDrop option of react-dnd#4555

Merged
zbeyens merged 3 commits into
udecode:mainfrom
DND-IT:respect-can-drop-option
Aug 8, 2025
Merged

Respect canDrop option of react-dnd#4555
zbeyens merged 3 commits into
udecode:mainfrom
DND-IT:respect-can-drop-option

Conversation

@delijah
Copy link
Copy Markdown
Collaborator

@delijah delijah commented Aug 8, 2025

Checklist

  • yarn typecheck
  • yarn lint:fix
  • yarn test
  • yarn brl
  • yarn changeset
  • ui changelog

This PR enables the dnd plugin, to support the react-dnd native canDrop option.

It's already possible to pass a canDrop function to the useDraggable hook like this:

import { useDraggable } from '@platejs/dnd';

const { isAboutToDrag, isDragging } = useDraggable({
    drop: {
        canDrop(item, monitor) {
            // Only allow drop if this drop target is directly hovered.
            if (!monitor.isOver({ shallow: true })) {
                return false;
            }

            return true;
        },
    },
    ...
});

But unfortunately it's not respected by the dnd plugin yet (namely the getDropPath function).

There is also a canDropNode option, but this is only valid for dnd operations on plate nodes (not for file system files for example).

@codesandbox
Copy link
Copy Markdown

codesandbox Bot commented Aug 8, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Aug 8, 2025

🦋 Changeset detected

Latest commit: 1ddc1f2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@platejs/dnd Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 11:36pm

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. plugin:dnd labels Aug 8, 2025
@zbeyens
Copy link
Copy Markdown
Member

zbeyens commented Aug 8, 2025

Thanks! Test is failing

@zbeyens zbeyens merged commit ce67f8b into udecode:main Aug 8, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin:dnd size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants