Comments (6)
There’s a partial workaround for the inability to capture events with mousedown.preventDefault: listen to top
rather than window
. But it only works if the top frame has the same domain as the frame, which makes the workaround much less useful.
from d3-drag.
If we mousedown.preventDefault:
- We may want to call element.focus on an ancestor. However, that appears to only work on HTML elements with a
tabIndex
attribute or SVGa
elements. Alternatively we could call element.blur on the document.activeElement. - We may want to listen to
top
rather thanwindow
. However, this would require catching the security error and a fallback towindow
, so dragging will still break if the mouse leaves the iframe and the top window is not on the same domain. - We may or may not want to suppress all clicks, or just clicks on moved drags.
If we don’t mousedown.preventDefault:
- We need to preventDefault on dragstart and selectstart and set-moz-user-select: none.
- We may or may not want to suppress all clicks, or just clicks on moved drags.
If we touchstart.preventDefault:
- We may want to generate a synthetic click, or just on a moved drag. This is a bit tricky. We can’t use element.click because it’s unsupported on SVG elements, and we probably want the click event to have the correct coordinates.
If we don’t touchstart.preventDefault:
- Some drag operations may trigger a pinch-zoom. It’s unclear when or why, as in most cases touchmove.preventDefault seems to be sufficient to prevent it.
from d3-drag.
👍
In contrast to D3 3.x, it is not necessary to fork the implementation.
Given this, I agree that it's best to have the most standards compliant and forward looking behavior be the default for D3 4.0.
from d3-drag.
Thanks for replying. I think I’m leaning towards keeping things mostly the same with D3 3.x (although D3 4.0 will be more easily customizable, should you want different behavior) for now.
When the Chrome bug is fixed, I might switch to mousedown.preventDefault, but then I’d need to figure out how to focus.
When Pointer Events are supported, we could use those instead of touch events, and then we should be able to pointerdown.preventDefault to prevent pinch-and-zoom without suppressing click.
But it’s all a big if, since the nature of the preventDefault API is that it doesn’t let you explicitly specify what you intend to prevent.
from d3-drag.
Pointer events have landed in Chrome in the meantime: https://caniuse.com/#feat=pointer
from d3-drag.
The selectstart
event landed in Firefox: https://caniuse.com/#feat=selection-api
from d3-drag.
Related Issues (20)
- Possible typo in README HOT 2
- What are the perposes of functions yesdrag and nodrag?
- Drag event on Chrome 72 HOT 3
- d3 mouseup event not firing HOT 1
- Drag Event Issue on Windows Chrome 74, related to solution for #47 HOT 1
- The default filter should return false if event.ctrlKey. HOT 5
- drag start event is don't send when Ctrl-key is press HOT 1
- drag.on("init") ? HOT 7
- Click event not firing if drag enables with simulation HOT 1
- Non-cancelable event HOT 3
- remove drag.container? HOT 1
- Use native events (*element*.dispatchEvent) instead of d3-dispatch? HOT 1
- remove dragEvent.on?
- d3.event is not available in version 6.1.1 HOT 1
- DragEvent missing event.currentTarget for arrow function node selection HOT 1
- Make event listeners non-passive. HOT 2
- d3.drag() causes error in testing mousedown event via jsdom HOT 4
- d3.pointer() could use event.touches[0] HOT 2
- Add event.currentTarget
- Support d3.drag in testing environments
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-drag.