Skip to content

Commit ec4c623

Browse files
authored
BETTER COMBOBOX (#306)
1 parent 8beff01 commit ec4c623

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/ruby_ui/combobox/combobox.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module RubyUI
44
class Combobox < Base
5-
def initialize(term: "items", **)
5+
def initialize(term: nil, **)
66
@term = term
77
super(**)
88
end
@@ -18,7 +18,8 @@ def default_attrs
1818
role: "combobox",
1919
data: {
2020
controller: "ruby-ui--combobox",
21-
ruby_ui__combobox_term_value: @term.to_s
21+
ruby_ui__combobox_term_value: @term,
22+
action: "turbo:morph@window->ruby-ui--combobox#updateTriggerContent"
2223
}
2324
}
2425
end

lib/ruby_ui/combobox/combobox_controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ export default class extends Controller {
5353
updateTriggerContent() {
5454
const checkedInputs = this.inputTargets.filter(input => input.checked)
5555

56-
if (checkedInputs.length == 0) {
56+
if (checkedInputs.length === 0) {
5757
this.triggerContentTarget.innerText = this.triggerTarget.dataset.placeholder
58-
} else if (checkedInputs.length === 1) {
59-
this.triggerContentTarget.innerText = this.inputContent(checkedInputs[0])
60-
} else {
58+
} else if (this.termValue && checkedInputs.length > 1) {
6159
this.triggerContentTarget.innerText = `${checkedInputs.length} ${this.termValue}`
60+
} else {
61+
this.triggerContentTarget.innerText = checkedInputs.map((input) => this.inputContent(input)).join(", ")
6262
}
6363
}
6464

0 commit comments

Comments
 (0)