Skip to content

Commit

Permalink
Fix filtering when locking in selection (#98)
Browse files Browse the repository at this point in the history
Closes #94
  • Loading branch information
josefarias authored Mar 12, 2024
1 parent 2821994 commit 8871dd0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Combobox.Filtering = Base => class extends Base {
this._selectNew()
} else if (isDeleteEvent(event)) {
this._deselect()
} else if (event.inputType === "hw:lockInSelection") {
this._select(this._ensurableOption)
} else if (this._isOpen) {
this._select(this._visibleOptionElements[0])
}
Expand Down
3 changes: 3 additions & 0 deletions test/dummy/app/controllers/comboboxes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def custom_events
def custom_attrs
end

def conflicting_order
end

private
delegate :combobox_options, :html_combobox_options, to: "ApplicationController.helpers", private: true

Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/views/comboboxes/conflicting_order.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= combobox_tag :conflict, %w[ A1 A A2 A3 ], id: "conflicting-order" %>
1 change: 1 addition & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
get "include_blank", to: "comboboxes#include_blank"
get "custom_events", to: "comboboxes#custom_events"
get "custom_attrs", to: "comboboxes#custom_attrs"
get "conflicting_order", to: "comboboxes#conflicting_order"

resources :movies, only: %i[ index update ]
get "movies_html", to: "movies#index_html"
Expand Down
10 changes: 9 additions & 1 deletion test/system/hotwire_combobox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,14 @@ class HotwireComboboxTest < ApplicationSystemTestCase
assert_combobox_display_and_value "#movie-field", "A Few Good Men", movies(:a_few_good_men).id
end

test "selection with conflicting order" do
visit conflicting_order_path

open_combobox "#conflicting-order"
click_on_option "A"
assert_combobox_display_and_value "#conflicting-order", "A", "A"
end

private
def open_combobox(selector)
find(selector).click
Expand All @@ -763,7 +771,7 @@ def delete_from_combobox(selector, text, original:)
end

def click_on_option(text)
find("li[role=option]", text: text).click
find("li[role=option]", exact_text: text).click
end

def clear_autocompleted_portion(selector)
Expand Down

0 comments on commit 8871dd0

Please sign in to comment.