Skip to content

Commit

Permalink
Filter before selecting a clicked option (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefarias authored Mar 7, 2024
1 parent b5dbe6f commit cd04750
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion app/presenters/hotwire_combobox/listbox/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/system/hotwire_combobox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd04750

Please sign in to comment.