Why is this onClick handler not called? (Playground code)

https://playground.solidjs.com/anonymous/b2bfddd1-102a-4f7a-a6e3-5d22846695e4 In the following playground code, when putting the focus on the text field, then clicking on the text (exactly in that order), the onClick on the text is not called (no "HELLO!" print). I have no idea why the onClick callback is ignored. (but I know it's because of the error message that appears, but don't understand why the addition of the error message stops the onClick handler to be executed)
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
30 Replies
Tommypop
Tommypop2y ago
I can't reproduce on the playground
Tommypop
Tommypop2y ago
Tommypop
Tommypop2y ago
Is this still an issue?
Mathieu
MathieuOP2y ago
yes Click on the text field first (nothing else), then on the text with background there is no HELLO! log can you reproduce it now @tommypop ?
Tommypop
Tommypop2y ago
yes Sorry I misunderstood your original post
Otonashi
Otonashi2y ago
the error isn't related, the playground doesn't load one of the dependencies correctly so it happens
Mathieu
MathieuOP2y ago
@otonashi9 I have this problem in my project I eliminated a lot of code to showcase
Otonashi
Otonashi2y ago
afaict this is just because the blur happens first then the click so if the div moves out of the way then the click won't happen if you click near the bottom of the div it logs
Mathieu
MathieuOP2y ago
@otonashi9 in the real project, the element below is a custon dropdown component. The dropdown is not showing the dropdown menu when clicked for this specific case. what do you think about that?
Otonashi
Otonashi2y ago
doesn't seem related to this reproduction to me
Mathieu
MathieuOP2y ago
it's the same thing. Say the focus is on the text field, then clicks the dropdown, but the error message appears, and the onClick handler of the dropdown is not executed.
Otonashi
Otonashi2y ago
the problem is just that the error message appears before the click happens that's it you can see this if you hold down the mouse button
Mathieu
MathieuOP2y ago
showcasing how this is a problem in my project
Mathieu
MathieuOP2y ago
@otonashi9 How can I solve this problem you think?
Otonashi
Otonashi2y ago
i'm not really the best person to ask this but imo the layout shouldn't shift due to the error message if it has to shift then i'm not sure, maybe use onMouseDown instead of onClick
Mathieu
MathieuOP2y ago
ty I'll be back with additional research
Tommypop
Tommypop2y ago
I presume these are the errors you're talking about
Mathieu
MathieuOP2y ago
no
Tommypop
Tommypop2y ago
Oh?
Mathieu
MathieuOP2y ago
there are no errors the problem is about the behavior of onBlur/onClick/layout shifting, etc
Tommypop
Tommypop2y ago
Oh, ok, my bad I misunderstood (again)
Mathieu
MathieuOP2y ago
Hey np! Thanks for looking<3 @otonashi9 I was pretty optimistic when adding a setTimeout to the onBlur callback handler of the text field. It works but only if I add like 100. To my surprise it doesn't work with 0 or even 10 (on my machine). https://playground.solidjs.com/anonymous/5eb7b744-4efc-445e-af40-0cd2969564a3 Would you understand why a setTimeout to 10 isn't even sufficient for the onClick and other stuff to happen first? (try at least twice)
Otonashi
Otonashi2y ago
because usually the time between mousedown and mouseup is longer than 10ms this should work regardless of the amount of time the mouse is held down imo so a timeout isn't the best solution
Mathieu
MathieuOP2y ago
@otonashi9 I just want to give you an update, about my research and how I decided to solve that problem. - It is not generally recommended to replace onClick handlers by onMouseDown, because that leads to a behavior that is different from the html elements. Take a button, if you click on it, but realize it is a mistake, but you still have the mouse down, you can move away with your cursor and release the mouse. It won't trigger the action. By replacing onclick by onmousedown, we are breaking this expected behavior. - HOWEVER, I noticed that is not the case for select dropdown triggers. If you click on a classic html select input, the menu shows in any case (probably because this can't lead to any mutation in any case just yet). So in the end I replaced the onClick by onMouseDown as you suggested. This led to a whole other series of problems, which I had to fix one by one. Thank you very much to explain the problem (onClick doesnt trigger if mouse has moved away before releasing) and putting me on the right track with onMouseDown. Ty as always<3
Otonashi
Otonashi2y ago
- HOWEVER, I noticed that is not the case for select dropdown triggers. If you click on a classic html select input, the menu shows in any case (probably because this can't lead to any mutation in any case just yet).
this is probably because for the native select element you can hold down the cursor then move to the option you want before releasing the cursor
Mathieu
MathieuOP2y ago
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select I can't produce this on Windows Which OS are you using, and did you try it?
Otonashi
Otonashi2y ago
windows firefox
Mathieu
MathieuOP2y ago
WOW indeed on FF this works, but not on my Chrome
Otonashi
Otonashi2y ago
interesting
Mathieu
MathieuOP2y ago
@otonashi9 by the way, the select elements and their behavior is way nicer on iOS/Mac. I had a Mac for few months and noticed a better experience on Mac.
Want results from more Discord servers?
Add your server