d3 / d3-selection

Transform the DOM by selecting elements and joining to data.

Home Page:https://d3js.org/d3-selection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Double click bug on foreignObject

shayantabrizi opened this issue · comments

I encounter a problem in double clicking foreignObjects. In this code, when we double click in the circle , in the console both 'click' and 'dblclick' logs appear. But when we double click the foreign object (H), only the 'click' log appears. If we comment either line 35 or line 40, dblclick also works for the foreign object.

This sounds like a browser quirk and not a D3 bug.

I have tried it on Firefox, Chrome, and Edge. All of them had the same problem. You mean that d3 works correctly and all of them work incorrectly?

D3 doesn’t intercept event listeners or define its own event lifecycle or anything like that, so if an event listener is behaving weirdly when you use D3 to register an event listener, it’ll behave weirdly in the same way as if you use the web standard API directly (e.g., element.addEventListener). Hence this is either a browser bug or the expected behavior of web standards, but unlikely to be an issue with D3 because of how D3 works.

You can read the source of selection.on here:

https://github.com/d3/d3-selection/blob/master/src/selection/on.js

The problem may be related to how d3 renders the objects, not only how events are handled. If line 40 is commented, it seems to work correctly. There may be a difference in how d3 handles foreignObjects and ordinary objects.