josefarias / hotwire_combobox

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

Add `onchange` event when selecting on click in empty `ListBox` #166

Closed RickHPotter closed 3 months ago

RickHPotter commented 3 months ago

The onchange event was not being triggered when selecting from ListBox without having typed anything in the .hw-combobox__input.

I tried to see if the navigate/ClickOnTheOutside stimulus actions were doing something SelectOnClick wasn't, but soon I realised that the onchange event was being triggered only due to its nature.

josefarias commented 3 months ago

Hey @RickHPotter thanks for the PR,

I think this is what you're looking for: https://github.com/josefarias/hotwire_combobox/issues/137#issuecomment-2035555941

The combobox isn't actually changing in this scenario. So I don't love the idea of having it emit a change event. However, we are emitting our own custom events from the canonical component element to support the kind of interaction you're describing.

Closing for now. But let me know if the above doesn't work for you and we can discuss alternatives, including the one proposed here.

RickHPotter commented 3 months ago

Thanks for your thorough answer. That works really well with what I plan to do in my app.

I guess I should have read more thouroughly the issues before trying to "fix" something, lol.