You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can override the activator function of the sensors you're using to achieve this. If you return false in the activator handler, the sensor will not be activated.
Reacted by Duncan Tang, Pavel Gurianov, Emerson Harris, Nidal Ghonaim, Hakan Bilgin, Hio Pham, Avram Walden, Piotr Janik, nguyenvanvi1, Nguyễn Hoàng Anh and 15 more
Reacted by Vlad Luca, Валера, YvarWesselink, Lulabee, Hakan Bilgin, Thomas Buckley-Houston, Armando Cierra Morán, Khang Nguyen, chuquangtu-04 and Doug Stewart
Reacted by Joshua Dance, Thomas Buckley-Houston, Armando Cierra Morán, hheman, Đào Văn Huỳnh, chuquangtu-04 and Doug Stewart
Reacted by Julian Singheiser, chuquangtu-04 and Doug Stewart
Thanks a lot!!!! Best solution. It would be better if we can achieve this by a prop config like "disableDragInteractiveElements" array
By the way, I post the Typescript version if anyone need it
importtype{PointerEvent}from"react";import{PointerSensor}from"@dnd-kit/core";/** * An extended "PointerSensor" that prevent some * interactive html element(button, input, textarea, select, option...) from dragging */exportclassSmartPointerSensorextendsPointerSensor{staticactivators=[{eventName: "onPointerDown"asany,handler: ({nativeEvent: event}: PointerEvent)=>{if(!event.isPrimary||event.button!==0||isInteractiveElement(event.targetasElement)){returnfalse;}returntrue;},},];}functionisInteractiveElement(element: Element|null){constinteractiveElements=["button","input","textarea","select","option",];if(element?.tagName&&interactiveElements.includes(element.tagName.toLowerCase())){returntrue;}returnfalse;}
Reacted by Duncan Tang, wibed, Nachliel Pokroy, YvarWesselink, Tamás Sallai, Minh Quân Lê, Quan Nguyen, jf, Akshat Malviya, oppenheims and 18 more
Reacted by Sushant Rajbanshi, Trung Quân, Minh Quân, Icaruk, Tao Chu, 巧克力冰激凌, Hakan Bilgin, Trà My, oppenheims, HelKyle and 12 more
Reacted by Alex Tompkins, codsane, ArisaOkuyama, bp41, Quang Hoang, Milo Hill, Arkellys, Simão Garcia, Robin Hède, Sebastian Graz and 66 more
Reacted by Alex Tompkins, Zakariae Filali, Quang Hoang, Sebastian Graz, Nacho Capodanno, DARIUS, Emanuel Quimper, Jefry Dewangga, Jonathan Greene, Minh Quân Lê and 15 more
when i use CustomMouseSensor, i got this error, how can i use CustomMouseSensor? TypeError: Class constructor MouseSensor cannot be invoked without 'new'
import{MouseSensorasLibMouseSensor,TouchSensorasLibTouchSensor}from'@dnd-kit/core';import{MouseEvent,TouchEvent}from'react';// Block DnD event propagation if element have "data-no-dnd" attributeconsthandler=({nativeEvent: event}: MouseEvent|TouchEvent)=>{letcur=event.targetasHTMLElement;while(cur){if(cur.dataset&&cur.dataset.noDnd){returnfalse;}cur=cur.parentElementasHTMLElement;}returntrue;};exportclassMouseSensorextendsLibMouseSensor{staticactivators=[{eventName: 'onMouseDown', handler }]astypeofLibMouseSensor['activators'];}exportclassTouchSensorextendsLibTouchSensor{staticactivators=[{eventName: 'onTouchStart', handler }]astypeofLibTouchSensor['activators'];}
Reacted by Hio Pham, ynguyen, Yadong (Adam) Zhang, Thomas Buckley-Houston, Dallin Wallace, Thomas Gwasira, Hồ Xuân Tý, Taiyib Ashraf, Rizwan Liaqat, jackjie330 and 25 more
Reacted by Hio Pham, ynguyen, TRINHDINHDAI2306, Thomas Gwasira, Hồ Xuân Tý, TNVan296, An, Nguyễn Nhật Quang, Van Dung Ha, Kiều Huynh and 4 more
Reacted by Trung Quân, izaass, Tan Phat Pham, Hoang Trong, Nguyen Dinh Cuong, Doan Anh Kiet, Khoi Do, Jacob Jaffe, Trà My, Nguyễn Đình Dương and 28 more
Reacted by Trung Quân, Hoang Trong, Nguyen Dinh Cuong, Nguyễn Văn Ni, Doan Anh Kiet, Khoi Do, Jacob Jaffe, Andy Fleming, Trà My, ormorm0.0 and 37 more
Reacted by Trung Quân, Nguyễn Vũ Anh Duy, Hoang Trong, Nguyen Dinh Cuong, Doan Anh Kiet, Khoi Do, Jacob Jaffe, Trà My, ormorm0.0, Nguyễn Đình Dương and 27 more
Reacted by Hio Pham, ynguyen, Thomas Buckley-Houston, Thomas Gwasira, Hồ Xuân Tý, TNVan296, Nguyễn Nhật Quang, Van Dung Ha, Kiều Huynh, Kiều Thái and 4 more
Hello everyone, I tried this approach but for some reason my didnt work.
I have a very similar approach with this sandbox. https://codesandbox.io/p/sandbox/dnd-kit-form-builder-fii0zh?file=%2Fsrc%2Fstyles.css
I want to make it draggable only from the dots and being able to expand my component,click on the fields etc.
I added the sensors the data-no-dnd="true" to my parent but nothing..
Reacted by Nyanpasu, mayar-aljabasene, ChTiSh and AnnaArbery
Hello everyone, I tried this approach but for some reason my didnt work. I have a very similar approach with this sandbox. https://codesandbox.io/p/sandbox/dnd-kit-form-builder-fii0zh?file=%2Fsrc%2Fstyles.css I want to make it draggable only from the dots and being able to expand my component,click on the fields etc. I added the sensors the data-no-dnd="true" to my parent but nothing..
I'm experiencing the same problem.
I think it'll work if I don't spread the listeners of useSortable to children, but I don't know how to stop it.
This seems very fundamental, I think the proposed solution should either be added to the docs or built into the library behind a prop like "allowEventPropagation" that does it behind the scenes.
Reacted by Edgar Rodriguez, Herman, HelKyle, Kevin Crossgrove, wervin, Corina Udrescu, Kevin9703, Lionel Marbot, Kyle Gosen, Padmanabham and 16 more
@DjVreditel your solution worked beautifully, thank you. Post this as when I saw the recent comments regarding solutions not working I lost some faith wondering if some recent updates caused changes, but I shouldn't.
If you get "TypeError: Class constructor MouseSensor cannot be invoked without 'new'", patching the activators (since it's a static prop, can be done once) should work. Also canStartDrag can be anything you want.
More beautiful solution in my opinion, if you get "TypeError: Class constructor MouseSensor cannot be invoked without 'new'" with previous solutions:
importtype{MouseEvent,TouchEvent}from'react';import{MouseSensor,TouchSensor}from'@dnd-kit/core';constIGNORE_TAGS=['BUTTON'];// Block Dnd, if IGNORE_TAGS includes elements tag or element has data-no-dnd attributeconstcustomHandleEvent=(element: HTMLElement|null)=>{letcur=element;while(cur){if(IGNORE_TAGS.includes(cur.tagName)||cur.dataset.noDnd){returnfalse;}cur=cur.parentElement;}returntrue;};MouseSensor.activators=[{eventName: 'onMouseDown',handler: ({nativeEvent: event}: MouseEvent)=>customHandleEvent(event.targetasHTMLElement),},];TouchSensor.activators=[{eventName: 'onTouchStart',handler: ({nativeEvent: event}: TouchEvent)=>customHandleEvent(event.targetasHTMLElement),},];
Reacted by Dima, eogrsanchez3, Roger, Henrique Gonçalves and Younus Rahman
Reacted by Dima and Younus Rahman
Reacted by Dima, eogrsanchez3, Roger, Tomàs Forné Cappeau and Younus Rahman
In case anyone else stumbles on this issue like I did...
I was having issues with this solution #477 (comment) not working very well when rendering a shadcn/ui Sheet (or Popover/Dialog etc.) within the draggable element. Clicking anywhere within the Sheet would bubble the event up to the draggable element and start dragging the element.
Stopping propagation of pointerdown and keydown events would prevent the Sheet from closing, so that had me stuck without any way to fix this using the custom sensor solution.
I was able to solve this without adding a visual drag handle by using a trick like this:
<divclassName="relative">{/* this should be the first child, so the siblings can be clickable */}<buttonclassName="absolute inset-0"{...attributes}{...listeners}ref={setActivatorNodeRef}/>{/* ... rest of the interactable UI ... */}<button>look ma, no dragging</button></div>
Essentially you can have the handle positioned in a way so it fills the parent element by giving it an absolute position. If you can't make it the first child of the parent, then you could probably get away with messing with z-index on the children elements so the interactable elements (buttons, inputs, etc.) can be clicked without dragging.
The pointerdown and keydown events in the Sheet won't propagate to the <button> and start dragging because it's not an ancestor of the <Sheet> component.
You also don't need to create custom sensors and set data attributes on interactable elements.
Activity
clauderic commentedon Oct 19, 2021
You can override the activator function of the sensors you're using to achieve this. If you return
falsein the activator handler, the sensor will not be activated.Something like:
AsasinCree commentedon Oct 22, 2021
Thanks a lot!!!! Best solution. It would be better if we can achieve this by a prop config like "disableDragInteractiveElements" array
By the way, I post the Typescript version if anyone need it
HelKyle commentedon Dec 3, 2021
For someone who may have the same issue. Just add
data-no-dnd="true"to the parent node and all the descendant nodes will not handle the dnd events.add component reorder-ability using drag and drop (dnd-kit) (#6)
JANEKKO commentedon Aug 16, 2023
when i use CustomMouseSensor, i got this error, how can i use CustomMouseSensor?
TypeError: Class constructor MouseSensor cannot be invoked without 'new'here's my code:
const sensors = useSensors( useSensor(CustomMouseSensor, { activationConstraint: { distance: 5, }, }))DjVreditel commentedon Sep 11, 2023
Thanks!
This is improved TypeScript example:
JANEKKO commentedon Sep 11, 2023
RafaelCENG commentedon Jan 24, 2024
Hello everyone, I tried this approach but for some reason my didnt work.

I have a very similar approach with this sandbox.
https://codesandbox.io/p/sandbox/dnd-kit-form-builder-fii0zh?file=%2Fsrc%2Fstyles.css
I want to make it draggable only from the dots and being able to expand my component,click on the fields etc.
I added the sensors the data-no-dnd="true" to my parent but nothing..
JANEKKO commentedon Jan 24, 2024
JANEKKO commentedon Feb 27, 2024
HyungwonJang0327 commentedon May 13, 2024
I'm experiencing the same problem.
I think it'll work if I don't spread the listeners of useSortable to children, but I don't know how to stop it.
JANEKKO commentedon May 13, 2024
tom-leamon commentedon May 22, 2024
This seems very fundamental, I think the proposed solution should either be added to the docs or built into the library behind a prop like "allowEventPropagation" that does it behind the scenes.
paddu1246 commentedon Jun 13, 2024
Hi All,
in Dnd kit library input tag onchage event not fired, I was tried above approach , I didn't get any luck. could please help me out this problem.
Thank you in advance
JANEKKO commentedon Jun 13, 2024
ChTiSh commentedon Jul 10, 2024
@DjVreditel your solution worked beautifully, thank you. Post this as when I saw the recent comments regarding solutions not working I lost some faith wondering if some recent updates caused changes, but I shouldn't.
JANEKKO commentedon Jul 10, 2024
mikalai-sauchanka commentedon Oct 9, 2024
If you get "TypeError: Class constructor MouseSensor cannot be invoked without 'new'", patching the activators (since it's a static prop, can be done once) should work. Also canStartDrag can be anything you want.
JANEKKO commentedon Oct 9, 2024
1used23 commentedon Nov 2, 2024
More beautiful solution in my opinion, if you get
"TypeError: Class constructor MouseSensor cannot be invoked without 'new'"with previous solutions:JANEKKO commentedon Nov 2, 2024
Merge pull request #33 from ThanhDanhhh/custom_libs
Merge pull request #33 from ThanhDanhhh/custom_libs
benjamin-andersen commentedon Oct 5, 2025
In case anyone else stumbles on this issue like I did...
I was having issues with this solution #477 (comment) not working very well when rendering a shadcn/ui Sheet (or Popover/Dialog etc.) within the draggable element. Clicking anywhere within the Sheet would bubble the event up to the draggable element and start dragging the element.
Stopping propagation of
pointerdownandkeydownevents would prevent the Sheet from closing, so that had me stuck without any way to fix this using the custom sensor solution.I was able to solve this without adding a visual drag handle by using a trick like this:
Essentially you can have the handle positioned in a way so it fills the parent element by giving it an absolute position. If you can't make it the first child of the parent, then you could probably get away with messing with z-index on the children elements so the interactable elements (buttons, inputs, etc.) can be clicked without dragging.
The
pointerdownandkeydownevents in the Sheet won't propagate to the<button>and start dragging because it's not an ancestor of the<Sheet>component.You also don't need to create custom sensors and set data attributes on interactable elements.
JANEKKO commentedon Oct 5, 2025
Fix: prevent drag activation on interactive elements