Coder Social home page Coder Social logo

Comments (6)

mbostock avatar mbostock commented on April 28, 2024

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.

mbostock avatar mbostock commented on April 28, 2024

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 SVG a elements. Alternatively we could call element.blur on the document.activeElement.
  • We may want to listen to top rather than window. However, this would require catching the security error and a fallback to window, 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.

jfirebaugh avatar jfirebaugh commented on April 28, 2024

👍

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.

mbostock avatar mbostock commented on April 28, 2024

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.

Herst avatar Herst commented on April 28, 2024

Pointer events have landed in Chrome in the meantime: https://caniuse.com/#feat=pointer

from d3-drag.

Herst avatar Herst commented on April 28, 2024

The selectstart event landed in Firefox: https://caniuse.com/#feat=selection-api

from d3-drag.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.