josefarias / hotwire_combobox

An accessible autocomplete for Ruby on Rails.
https://hotwirecombobox.com
MIT License
456 stars 30 forks source link

Skip extra item selection events when clicking an option #110

Closed jlw closed 6 months ago

jlw commented 6 months ago

While working on #108, I noticed some odd behavior around item selection that only manifested as a bug with the multiple selection. I simply added some extra conditionals in that PR because I hadn't yet worked out any clean fixes.

The first commit here addresses only the very first odd behavior - when I click on an option in the list, the first item is incorrectly selected before resolving on the actual option I clicked.

I verified this by adding the following:

debugging

which resulted in:

debugging output


The second commit here addresses both of the de-selection and re-selection events, seen here originally in a bit more detail:

reselections

and now has been removed without breaking any system tests (and passing minimal manual testing):

no-more-reselection

josefarias commented 6 months ago

Great catch @jlw thanks! I think this points to a larger problem in the codebase.

The current design couples certain things – like filtering and selection. Conditionals will keep proliferating unless we nip this in the bud.

I'm going to attempt a refactor I've had on the back burner for a while. That should fix this, as well as make our work in https://github.com/josefarias/hotwire_combobox/pull/106 easier. Although it might cause some minor merge conflicts. But we'll figure it out.

Gonna keep this open in case that refactor doesn't pan out. Working on it now.

josefarias commented 6 months ago

@jlw I finished the refactor in https://github.com/josefarias/hotwire_combobox/pull/111. That should've also fixed the issues you're seeing here. Closing for now.

Sorry about the merge conflicts in the other PR. I'll help you get those sorted tomorrow.