diff --git a/app/assets/javascripts/hw_combobox/models/combobox/selection.js b/app/assets/javascripts/hw_combobox/models/combobox/selection.js index 9880f50..287d872 100644 --- a/app/assets/javascripts/hw_combobox/models/combobox/selection.js +++ b/app/assets/javascripts/hw_combobox/models/combobox/selection.js @@ -2,9 +2,9 @@ import Combobox from "hw_combobox/models/combobox/base" import { wrapAroundAccess } from "hw_combobox/helpers" Combobox.Selection = Base => class extends Base { - selectOption(event) { - this._select(event.currentTarget) + selectOptionOnClick(event) { this.filter(event) + this._select(event.currentTarget) this.close() } diff --git a/app/presenters/hotwire_combobox/listbox/option.rb b/app/presenters/hotwire_combobox/listbox/option.rb index 8092176..76cb44c 100644 --- a/app/presenters/hotwire_combobox/listbox/option.rb +++ b/app/presenters/hotwire_combobox/listbox/option.rb @@ -37,7 +37,7 @@ def id def data { - action: "click->hw-combobox#selectOption", + action: "click->hw-combobox#selectOptionOnClick", filterable_as: filterable_as, autocompletable_as: autocompletable_as, value: value diff --git a/test/system/hotwire_combobox_test.rb b/test/system/hotwire_combobox_test.rb index 6ba870d..680df88 100644 --- a/test/system/hotwire_combobox_test.rb +++ b/test/system/hotwire_combobox_test.rb @@ -246,6 +246,12 @@ class HotwireComboboxTest < ApplicationSystemTestCase delete_from_combobox "#state-field", "Florida", original: "Florida" assert_options_with count: State.count + + type_in_combobox "#state-field", :down, :down, :down + assert_selected_option_with text: "Michigan" + click_on_option "Florida" + assert_closed_combobox + assert_combobox_display_and_value "#state-field", "Florida", "FL" end test "combobox with prefilled value" do