Open cpbotha opened 3 years ago
I see this is quite an old comment, but the issue appears to still persist. I have onClick event on Plotly React Plot that jumps to top of page despite returning false or preventing default. Any known workarounds for this?
I'm currently using a
plotly_click
custom handler (via react-plotly onClick prop) on a treemap, where I would like to cancel the default zoom-in / zoom-out behaviour if the user is pressing control.For
plotly_legendclick
for example, the convention is to returnfalse
from the custom handler, which will stop default event processing. See https://community.plotly.com/t/disable-legend-click-functionality-hiding-traces/1345/4 for @alexcjohnson 's reply in this regard.However, for the
plotly_click
event I've traced the code into this little section in plotlyjsattachFxHandlers.onClick()
:So the event for
plotly_treemapclick
in this case will honour the convention as can be seen from theclickVal = ...
, but the standardplotly_click
handler is invoked by theFx.click()
invocation, which ignores the handler return values.Unfortunately, the call chain from
Fx.click()
is quite deep:onClick() -> click() -> emitClick() -> plotObj.emit() -> emit() -> emitOne() -> customHandler
. To bring back the return value is going to be quite the adventure. Also, at some spots along the chain, return values are used for a different purpose.Alternatively, the code in the uppermost
onClick()
could for example checkevent.defaultPrevented
-- this is not quite the Plotly convention, but then again that convention is not very well documented at all, and this would be far more straight-forward to implement rather than bringing back the custom handler return value. Furthermore, many javascript programmers know to look for preventDefault.In addition, this fix would immediately also work from React.
What do people think about this?