Skip to content

Commit

Permalink
Revert "Reroute listbox streams to dialog if necessary"
Browse files Browse the repository at this point in the history
This reverts commit 36446c0.
  • Loading branch information
josefarias committed Mar 7, 2024
1 parent 36446c0 commit a7e185f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 27 deletions.
10 changes: 0 additions & 10 deletions app/assets/javascripts/hw_combobox/models/combobox/dialog.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import Combobox from "hw_combobox/models/combobox/base"

Combobox.Dialog = Base => class extends Base {
rerouteListboxStreamToDialog({ detail: { newStream } }) {
if (newStream.target == this.listboxTarget.id && this._dialogIsOpen) {
newStream.setAttribute("target", this.dialogListboxTarget.id)
}
}

_connectDialog() {
if (window.visualViewport) {
window.visualViewport.addEventListener("resize", this._resizeDialog)
Expand Down Expand Up @@ -56,8 +50,4 @@ Combobox.Dialog = Base => class extends Base {
get _smallViewport() {
return window.matchMedia(`(max-width: ${this.smallViewportMaxWidthValue})`).matches
}

get _dialogIsOpen() {
return this.dialogTarget.open
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Combobox.Filtering = Base => class extends Base {
this._selectNew()
} else if (isDeleteEvent(event)) {
this._deselect()
} else if (this._isOpen) {
} else {
this._select(this._visibleOptionElements[0])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Combobox.Toggle = Base => class extends Base {
_collapse() {
this._actingCombobox.setAttribute("aria-expanded", false) // needs to happen before resetting acting combobox

if (this._dialogIsOpen) {
if (this.dialogTarget.open) {
this._closeInDialog()
} else {
this._closeInline()
Expand Down
3 changes: 1 addition & 2 deletions app/presenters/hotwire_combobox/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ def input_data
input->hw-combobox#filter
keydown->hw-combobox#navigate
click@window->hw-combobox#closeOnClickOutside
focusin@window->hw-combobox#closeOnFocusOutside
turbo:before-stream-render@document->hw-combobox#rerouteListboxStreamToDialog".squish,
focusin@window->hw-combobox#closeOnFocusOutside".squish,
hw_combobox_target: "combobox",
async_id: canonical_id
end
Expand Down
6 changes: 0 additions & 6 deletions test/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
.container aside.empty {
display: none;
}

@media (max-width: 600px) {
.container aside {
display: none;
}
}
</style>
</head>

Expand Down
14 changes: 7 additions & 7 deletions test/system/hotwire_combobox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,21 +458,21 @@ class HotwireComboboxTest < ApplicationSystemTestCase

test "dialog" do
on_small_screen do
visit async_html_path
visit html_options_path

assert_no_selector "dialog[open]"
open_combobox "#movie-field"
open_combobox "#state-field"
assert_selector "dialog[open]"

within "dialog" do
type_in_combobox "#movie-field-hw-dialog-combobox", "whi"
assert_combobox_display "#movie-field-hw-dialog-combobox", "Whiplash"
assert_selected_option_with text: "Whiplash"
type_in_combobox "#state-field-hw-dialog-combobox", "Flor"
assert_combobox_display "#state-field-hw-dialog-combobox", "Florida"
assert_selected_option_with text: "Florida"
end
assert_combobox_value "#movie-field", movies(:whiplash).id
assert_combobox_value "#state-field", "FL"

click_away
assert_combobox_display_and_value "#movie-field", "Whiplash", movies(:whiplash).id
assert_combobox_display_and_value "#state-field", "Florida", "FL"
assert_no_selector "dialog[open]"
end
end
Expand Down

0 comments on commit a7e185f

Please sign in to comment.