Fork me on GitHub
#reagent
<
2019-09-16
>
Alexander Knemeyer11:09:21

Hi folks. I'm struggling to get :on-load working with svg in reagent. For example, [:svg {:on-mouse-down #(println "mouse down") :on-load #(println "loaded")}] prints "mouse down" when I click it but "loaded" never appears. For context (ie in case there's a better way, or I've found a bug) I'm trying to implement the draggable svg components in this tutorial http://www.petercollingridge.co.uk/tutorials/svg/interactive/dragging/ except in cljs. Any ideas of what I'm doing wrong?

dominicm11:09:15

I don't see a use of a load event in that tutorial. Are you certain that svg has a load event?

Alexander Knemeyer12:09:58

One of the code blocks is

<svg xmlns=""
     viewBox="0 0 30 20"
     onload="makeDraggable(evt)">
I've tried variations like onload, on-load, onLoad etc in case reagent/hiccup was doing something in between, but haven't had success so far

jahson12:09:31

A fast googling shows that there were problems with onLoad for svg in react.

juhoteperi12:09:36

React doesn't necessarily support all dom events

juhoteperi12:09:10

Anyway, it is probably good idea to lookup similar example for React and adapt that to Reagent. The example manipulates DOM directly which is not good fit for React.

Alexander Knemeyer12:09:46

Yeah, I think we found the same threads re react. It was from 2017 or so, so I thought I'd check just in case. Thanks, will look up a react example instead. I appreciate the help!