-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Blur event prevents option_click #7
Comments
Hi @goblinJoel and thanks for the bug report. Just checking: you are using the latest version right? (0.3.1) I tried to reproduce the bug in the showcase app but without success. If I click on an option in the dropdown, I see that the Do you think you could create a repository that reproduces the bug you're seeing in your app? That would be really helpful!
This is necessary to avoid sending change events triggered by typing in the text input to the parent liveview. If you remove |
Ok I think I managed to reproduce it on an app I'm developing that uses live_select. Whether the option click works or not seems to depend on what element lies behind the dropdown. The first impression is that it doesn't work if there's another input element behind the dropdown, but I will have to confirm this, after which I will try to fix it. |
Thanks for the reply! Glad you were able to reproduce it. I am indeed using it as a library. For what it's worth, I've been working on MacOS Chrome, in case browser version affects when or in what order events trigger. If I recall correctly, I also noticed that the html phx blur attribute appeared on the element in the dom before the change did -- not sure if that matters. Tomorrow, I could try the same app out in other Mac browsers. Edit: If you find a workaround regarding what elements can/can't be behind the dropdown, that may be useful even if you don't find a quick fix. Edit2: I just remembered something else related to using it as a library: I had some trouble getting it to work as a library, so at some point troubleshooting, I copied the non-minified JS hook code from the repo and used that for the hook rather than importing. (I forget which issue this fixed -- don't have the code in front of me today -- but the blur/change conflict remained.) |
In addition to my edits on my comment yesterday, I tried a couple of things today:
Here's a gist with the relevant files/snippets for my test page: https://gist.github.com/goblinJoel/fa97c3b51f761a7d597e0f2f8ba6c3b4 . I am using |
I fixed it on master. I tested it on my app and it works. Can you please test it on yours against master? Please do not copy and paste the hooks from the JS source.
The fix for the issue consists in triggering Since one can't trigger a Let me know if it works, then I'll release a new version. |
@maxmarcon Yes, this works! I switched my dependency to the git link, main branch, rebuilt, and was able to get it to work. Thank you so much! (It turns out the reason I couldn't get it to import previously and had to copy-paste was because I am not very good at JS and was doing it wrong! Had the same problem this time, but eventually figured out why |
That's great! I'll release a new version right away. Thanks again for reporting this bug and for the quick turnaround. fixed by: c4618ba |
Version 0.3.2 released 👯♀️ |
Thanks for such a quick update! |
I'm having trouble getting selections to work, and I've traced it to the blur event:
For me, when I click on the option, the
blur
event fires, but theoption_click
and whatever is set on the form'sphx-change
never do. If I remove the:hide_dropdown
assign, theoption_click
fires, and the form's change event happens.I'm not entirely sure why it's blurring when I click an option, but it happens even if I use a live select with a minimal layout template and remove some other libraries from our app.js, so I don't think it's our own JS interfering.
I think this is probably a race condition where, if blur is processed before option click, the liveview updates with the hidden dropdown and drops the click event. Perhaps something could be done with send_update_after/4?
(Side note: I'm not sure the component template's
phx_change: "change"
on the text input itself goes anywhere.)I'm thinking about what to do for a workaround in the meantime. This library seems very helpful to make a liveview-friendly select2 equivalent!
The text was updated successfully, but these errors were encountered: