Skip to content
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

Dragging over an iframe stops dragging when moving the mouse too fast #582

Closed
simlmx opened this issue Jul 6, 2021 · 2 comments
Closed

Comments

@simlmx
Copy link

simlmx commented Jul 6, 2021

I found a solution which I'm sharing here.

I had something that looked like

...
return (
  <>
    <iframe></iframe>
    <Draggable>
      <div style={{position: 'absolute'}}></div>
    </Draggable>
  </>
)

i.e. a draggable <div> on top of an <iframe>. When dragging too fast I would lose the drag.

My solution (inspired from this other post) was this:

...
const [isDragging, setIsDragging] = useState(false);

return (
  <>
    {isDragging && (
      <div style={{position: 'absolute', left: 0, right: 0, bottom: 0, top: 0, zIndex: 9999}}</div>
    )}
    <iframe></iframe>
    <Draggable
      onStart={() => setIsDragging(true)}
      onStop={() => setIsDragging(false)}
    >
      <div style={{position: 'absolute'}}></div>
    </Draggable>
  </>
)

This makes sure that when we are dragging, we are dragging on top of a big <div> instead of the <iframe>.

EDIT See @landish's solution below for something even simpler.

@liorocks
Copy link

Amazing solution 👍

I had the same problem, thanks for sharing, it really helped!

I noticed that react-draggable library adds .react-draggable-transparent-selection class to body tag while an element is being dragged.

So here is an alternative solution, which is more like CSS approach and does not requires managing isDragging state.

.react-draggable-transparent-selection .draggable-iframe-cover {
    display: block;
    z-index: 999999;
}

.draggable-iframe-cover {
    position: absolute;
    display: none;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}
<div style={{ position: 'relative' }}>
    <div className="draggable-iframe-cover" />
    <iframe ... />
</div>

@simlmx
Copy link
Author

simlmx commented Oct 28, 2022

@landish Nice! I switched to your simpler and cleaner solution! 👌

maltoze referenced this issue in maltoze/link-popper Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants