Fork me on GitHub
#reagent
<
2018-12-05
>
manu14:12:48

hi! what do you suggest to write unit text? I used also re-frame.. thx 🙂

mikethompson20:12:36

@manu perhaps have a look at re-frame-test ?

escherize20:12:56

Or you can get by with clojure.test

escherize20:12:12

Do you want to test how your app is hooked together, or the functions that drive effects?

urzds22:12:51

Hi! I am trying to open a new window at some URL with following code:

[:a {:href url
     :target "_blank"
     :rel "noopener noreferrer"
     :onclick #(do
                 (js/window.open url "_blank" "noopener")
                 false)}
 url]
However, the URL opens in a new tab instead. If I write :on-click instead of :onclick, it opens two tabs. What am I doing wrong?

urzds22:12:35

In the Firefox JavaScript console, the the generated code, when I click on the grey "event" box, looks exactly like this: https://stackoverflow.com/a/15766254/7177944

urzds22:12:58

Or rather: I already tried variants that looked exactly like that.

urzds23:12:57

It seems that :on-click is the correct variant, but my false is being ignored.

justinlee23:12:58

@urzds I don’t really understand the wizardry of why that stackoverflow answer works, but I wonder if the weirdness is that they are providing text rather than a function

urzds23:12:46

I also found this, but it also behaves in the same way: https://groups.google.com/forum/#!topic/clojurescript/xlsD4iYiYvk

urzds23:12:23

I now have:

:on-click (fn [e]
                                                     (.stopPropagation e)
                                                     (js/window.open url "_blank")
                                                     false)

justinlee23:12:37

does the stopPropagation stop the 2 tabs at least?

urzds23:12:35

It appears that I can make it open 1 tab and 1 window by adding the third argument to window.open: "noopener".

urzds23:12:36

What I just noticed is that in Firefox, I see two event handlers registered: click = function emptyFunction() {} and onClick = ... with my own code.

justinlee23:12:11

step1 is to make it work in a javascript console

urzds23:12:12

The former seems to come from React, according to the source location.

justinlee23:12:13

this window.open("print.html", "newwindow", "width=300,height=250") works for me in chrome

urzds23:12:26

On the console, yes.

urzds23:12:40

And if I change the :a to a :div, it works, too. So it really appears to be that the click event is not being ignored...

justinlee23:12:26

i was just going to ask that. somewhere in the back of my mind i recall that you have to do something else to make a tags behave

justinlee23:12:01

oh you need a (.preventDefault e)

urzds23:12:23

You're a genius. 😄 Where did you find that answer?

justinlee23:12:30

I don’t think you even need the .stopPropagation

urzds23:12:38

(Works now. Thanks a lot!)

justinlee23:12:43

propagation usually only matters with form submission

justinlee23:12:02

the issue is that a has a default behavior on click and div does not

justinlee23:12:14

you have to affirmatively tell the browser not to do anything

urzds23:12:24

First comment here confirms it: https://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false#1357151 (more details: http://blog.niftysnippets.org/2011/11/story-on-return-false.html) tl;dr: If using Reagent (which via React probably uses the "DOM2 event handlers") only preventDefault prevents the default action from happening. return false only worked with DOM0 event handlers, i.e. code in string literals as HTML elements or attached to the .onclick JS property of the element.

justinlee23:12:07

right and i think react 16 changed that too?

justinlee23:12:52

actually it was react 12

justinlee23:12:55

well i’m not sure when it flipped over, but at any rate, you cannot do the return-false-to-prevent-default in any recent react https://reactjs.org/docs/handling-events.html

urzds23:12:02

@lee.justin.m Thanks for the links to the docs!