-
-
Notifications
You must be signed in to change notification settings - Fork 683
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
Stop propagation of click events on draggable node once activation constraints are met #377
Conversation
…nstraints are met
🦋 Changeset detectedLatest commit: d7d6a4d The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Size Change: +456 B (+1%) Total Size: 61.4 kB
ℹ️ View Unchanged
|
Hi @clauderic, I'm working on application where cards can be sorted. These cards contain checkboxes and buttons. With this change (since Is there a way to these buttons can still work? UpdateFound #476 (comment) The solution/fix seems to be to leverage change the default configuration of sensors with
This works for me. But I'm thinking if there are others struggling with this issue. Then a migration guide in |
Hi @andys8, to avoid the conflicts between click and drag events, you can implement a custom MouseSensor like this. import type { MouseEvent, KeyboardEvent } from 'react'
import {
MouseSensor as LibMouseSensor,
KeyboardSensor as LibKeyboardSensor
} from '@dnd-kit/core'
export class MouseSensor extends LibMouseSensor {
static activators = [
{
eventName: 'onMouseDown' as const,
handler: ({ nativeEvent: event }: MouseEvent) => {
return shouldHandleEvent(event.target as HTMLElement)
}
}
]
}
function shouldHandleEvent(element: HTMLElement | null) {
let cur = element
while (cur) {
if (cur.dataset && cur.dataset.noDnd) {
return false
}
cur = cur.parentElement
}
return true
} add <input data-no-dnd="true" /> |
@HelKyle I prefer this implementation that doesn't relay on |
Fixes #172
This PR adds a
click
event listener to the draggable node to stop propagation of click events once activation constraints are met.If activation constraints are not met,
click
events fire as they should.