question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE] Support dragging one element to move another ( drag handles )

See original GitHub issue

Is your feature request related to a problem? Please describe. Hello, I’m wondering if there is a supported way to implement drag handles ( a draggable section of an element, or dragging a child to move the parent ) at the moment. I’ve had some luck with /dev/examples/dragExternalValues but the need for _props and lack of documentation isn’t ideal.

Describe the solution you’d like Ideally, a dragHandle prop that accepts a ref with the element we want to use as a handle.

<Container drag dragHandle={dragHandle}>
  <Handle ref={dragHandle} />
  ...
</Parent>

Dragging the handle element would move the container element, dragging inside the container but outside the handle would not register as a drag. Essentially the top bar of a macos window would be a dragHandle to the main window.

Describe alternatives you’ve considered The only current alternative seems to be the _dragX, _dragY, and __dragTransitionControls props. These work well but are not documented as far as I can tell and don’t feel as clean as the rest of the library.

Thanks again for the library. It’s fantastic.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:7

github_iconTop GitHub Comments

4reactions
mattgperrycommented, Jan 29, 2020

@alacroix You can probably add a mousedown/pointerdown event to the element itself (via a ref) and calling event.preventDefault. But yeah we can take this a step further and look into adding a prop or something that suppresses this.

Approach 1

<motion.div drag="x" dragListener={false} dragControls={dragControls} />

Approach 2

function onMouseDown(event) {
  dragControls.start(event, { axis: "x" })
}

return <motion.div dragControls={dragControls} />
2reactions
mattgperrycommented, Jan 29, 2020

Yeah because drag might only optionally be on the component, and it’s where we define axis, we’d have to define it somewhere else. But everything else would be on the component.

However I’m thinking approach 1 would probably be better. Keeps the number of permutations saner.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the HTML5 Drag and Drop API - web.dev
The HTML5 Drag and Drop API means that we can make almost any element on our page draggable. In this post we'll explain...
Read more >
HTML Drag and Drop API - MDN Web Docs
The user may select draggable elements with a mouse, drag those elements to a droppable element, and drop them by releasing the mouse...
Read more >
Draggable Elements That Push Others Out Of Way - CSS-Tricks
E.g. click on element, hold down mouse button, drag mouse cursor, element drags with the mouse, release mouse button to release element. Or...
Read more >
Drag'n'Drop with mouse events - The Modern JavaScript Tutorial
Use event delegation to track drag start: a single event handler on document for mousedown . If elements are dragged to top/bottom window...
Read more >
Accessible Drag and Drop with Multiple Items - SitePoint
Provide a mechanism for the user to select which elements they want to drag, and the recommended keystroke is Space . When an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found