Skip to content

Commit

Permalink
Show clear widget on prefilled state
Browse files Browse the repository at this point in the history
  • Loading branch information
jlw committed Mar 14, 2024
1 parent 7208642 commit 6fbd9bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Combobox.Filtering = Base => class extends Base {
this._filterSync(event)
}

this._markQueried()
}

_markQueried() {
this._actingCombobox.toggleAttribute("data-queried", this._isQueried)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Combobox.Selection = Base => class extends Base {
if (this.hasPrefilledDisplayValue) {
this._fullQuery = this.prefilledDisplayValue
}
this._markQueried()
}

_select(option, { forceAutocomplete = false } = {}) {
Expand Down
8 changes: 7 additions & 1 deletion test/system/hotwire_combobox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,20 @@ class HotwireComboboxTest < ApplicationSystemTestCase
assert_combobox_display_and_value "#state-field", "Florida", "FL"
end

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

assert_closed_combobox
assert_combobox_display_and_value "#state-field", "Michigan", "MI"
assert_selector ".hw-combobox__input[data-queried]"

open_combobox "#state-field"
assert_selected_option_with text: "Michigan"

click_away
find(".hw-combobox__handle").click
assert_open_combobox
assert_no_visible_selected_option
end

test "combobox in form with prefilled value" do
Expand Down

0 comments on commit 6fbd9bc

Please sign in to comment.