Skip to content

Commit

Permalink
Mark combobox as queried when selecting on small screens (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefarias authored Jul 30, 2024
1 parent 4bfb641 commit 7f205da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Combobox.Filtering = Base => class extends Base {
}

_markQueried() {
this._actingCombobox.toggleAttribute("data-queried", this._isQueried)
this._forAllComboboxes(el => el.toggleAttribute("data-queried", this._isQueried))
}

get _isQueried() {
Expand Down
22 changes: 22 additions & 0 deletions test/system/hotwire_combobox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,28 @@ class HotwireComboboxTest < ApplicationSystemTestCase
assert_combobox_display_and_value "#state-field", "Alabama", "AL"
end

test "selecting an option marks combobox as queried" do
visit async_path

assert_no_selector ".hw-combobox__input[data-queried]"
open_combobox "#movie-field"
click_on_option "Aladdin"
assert_closed_combobox
assert_combobox_display_and_value "#movie-field", "Aladdin", movies(:aladdin).id
assert_selector ".hw-combobox__input[data-queried]"

on_small_screen do
visit async_path

assert_no_selector ".hw-combobox__input[data-queried]"
open_combobox "#movie-field"
click_on_option "Aladdin"
assert_closed_combobox
assert_combobox_display_and_value "#movie-field", "Aladdin", movies(:aladdin).id
assert_selector ".hw-combobox__input[data-queried]"
end
end

test "combobox with prefilled value and working clear widget" do
visit prefilled_path

Expand Down

0 comments on commit 7f205da

Please sign in to comment.