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

useDndMonitor onDragStart not called when there is an activationConstraint and collisionDetection is closestCorners #369

Closed
mkelliher opened this issue Jul 20, 2021 · 1 comment

Comments

@mkelliher
Copy link

Repro

  1. Create a DndContext with:
    • A pointer sensor with an activation constraint: useSensor(PointerSensor, { activationConstraint: { distance: 10 } })
    • collisionDetection={closestCorners}
    • A draggable and a droppable component
  2. Somewhere in a child component within the context, put useDndMonitor({ onDragStart: () => console.log('useDndMonitor: onDragStart') })
  3. Notice that the useDndMonitor: onDragStart is not logged when a drag is started.

I have set up the repro in a CodeSandbox here: https://codesandbox.io/s/dnd-kit-ondragstart-bug-zysht?file=/src/App.js

When you drag the item by its red drag handle, take a look at the console logs. You will see that the DndContext: onDragStart is called, but the useDndMonitor: onDragStart is not.

Workaround

I found that this issue does not occur if the collisionDetection function returns null at the start of the drag. So the workaround is to have collisionDetection always return null until DndContext: onDragStart is called. Then, after that, have the function return its regular results (i.e., closestCorners).

See the above CodeSandbox for an example of the workaround (in App.js use collisionDetection={collisionDetectionWorkaround}).

@clauderic
Copy link
Owner

clauderic commented Jul 22, 2021

This is fixed by this commit, which will be released in the next major version:
05d6a78#diff-c4e29cc1eb5f250d1c1ff78d14b5785fb2a003b7aa2c8821dfecf20bc9d86325R387-R391

You can follow the release PR here #342

If you're eager to jump to the next version before it's released, you can install versions tagged with @next on npm.

See this forked sandbox where the issue is no longer reproducible if you upgrade to the @next version of @dnd-kit/core https://codesandbox.io/s/dnd-kit-ondragstart-bug-forked-utdlw?file=/src/Draggable.js

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

No branches or pull requests

2 participants