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.

Draggable elements can be dragged outside the body

See original GitHub issue

Hi there,

I was looking at the codebase to cover the enhancement request regarding the possibility to set the parent as CSS selector (see open issues) and half way through the implementation I had an idea which permits to solve the following issue:

Currently the resizable/draggable element could be dragged off the document, meaning the user could eventually lose control or visibility of elements unless the developer set parent to true:

out-of-body

I’ve a non-disruptive code change which I could push to achieve this:

constrained-to-body Note: within Storybook the white stage is the body

Would you mind think about it and let me know if you’d like to have this feature please? I could push this merge request into your package.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

4reactions
dvagocommented, May 11, 2020

Here you go, https://gist.github.com/dvago/02aeab97cb0094ba1fc2219963333066

Basically, the getParentSize function returns either the width and the height of the parent If the parent flag is set to true, or the body width and height rather than null values.

Said so, the script has a few areas where it check for the parent flag in order to calculate boundary limits but because of the changes above there is no need of these checks as you want to have boundary limits anyway.

I wouldn’t personally rely on this package to be honest with you, but I guess as workable script it’s fine.

The main reason of the above sentence is because there is a system of $emitters on native listeners without any debounce mechanism making the whole package quite expensive, especially if you end up having multiple draggable/resizable elements.

1reaction
dvagocommented, Jul 19, 2020

Indeed, so you answered yourself 😉 … Also keep in mind that emitters are an extra layer on top of existing native listeners and you don’t really need to bloat your script with them. (In fact, emitters are also bad practice in the new Vue version as far as I know)

Furthermore, emitting “dragging” could be easily avoided with some state e.g. “isDragging” => true/false which permits the user to use the state just if really needed or most likely just rely on hooks like “onDragStart”/“onDragEnd”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

draggable - HTML: HyperText Markup Language | MDN
The draggable global attribute is an enumerated attribute that indicates whether the element can be dragged, either with native browser ...
Read more >
Disable Draggable Element Outside The Body - Stack Overflow
When I dragging a element. it goes outside of the body. How can I disable or make draggable inside the body. <div id="drag"...
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 and Drop | Angular Material
You can now add the cdkDrag directive to elements to make them draggable. When outside of a cdkDropList element, draggable elements can be...
Read more >
Element Dragging | jsPlumb Documentation
You must set position:absolute on elements that you intend to be draggable. The reasoning for this is that all libraries implement dragging by...
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