-
-
Notifications
You must be signed in to change notification settings - Fork 801
[Experimental] Introduce useDragHandle hook
#1740
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
base: experimental
Are you sure you want to change the base?
Conversation
|
@dnd-kit/abstract
@dnd-kit/collision
@dnd-kit/dom
@dnd-kit/geometry
@dnd-kit/helpers
@dnd-kit/react
@dnd-kit/state
commit: |
| useOnElementChange(value, (handle) => { | ||
| if (!draggableInstance) return; | ||
|
|
||
| draggableInstance.handle = handle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line does get flagged by the react compiler lint rule, but I can see this is using a ref inside a custom signals implementation so no idea if that the compiler is even a viable target for the library.
Mutating a value returned from a function whose return value should not be mutated (eslint react-compiler/react-compiler)
| draggableInstance.handle = handle; | ||
| }); | ||
|
|
||
| return handleRef; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type here is RefObject<Element | null>, so you'll probably want to match that to the existing handleRef type of (element: Element | null) => void or at least allow a generic for the element type so it doesn't complain when being applied to something like a <button>
This PR introduces a
useDragHandlehook that allows React consumers to set a drag handle in a different location than whereuseDraggableoruseSortableis used.Resolves #1738
Example usage — two separate components
Below the draggable is declared in a row component, while the dedicated handle lives in a different component.
The key takeaway:
useDragHandledoes not need to live in the same component whereuseDraggable/useSortableis invoked—perfect for table rows, list items with nested actions, or any layout where the “grab-area” is rendered deeper in the tree.