Skip to content

Commit 9be9965

Browse files
committed
applies code review suggestions
1 parent 986cc50 commit 9be9965

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/ruby_ui/combobox/combobox_controller.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class extends Controller {
99

1010
static targets = [
1111
"input",
12-
"toggle",
12+
"toggleAll",
1313
"popover",
1414
"item",
1515
"emptyState",
@@ -34,14 +34,17 @@ export default class extends Controller {
3434
if (e.target.type == "radio") {
3535
this.closePopover()
3636
}
37+
38+
const isToggleAllUnchecked = this.hasToggleAllTarget && !e.target.checked
39+
if (isToggleAllUnchecked) this.toggleAllTarget.checked = false
3740
}
3841

3942
inputContent(input) {
4043
return input.dataset.text || input.parentElement.innerText
4144
}
4245

43-
toggleInputs() {
44-
const isChecked = this.toggleTarget.checked
46+
toggleAllItems() {
47+
const isChecked = this.toggleAllTarget.checked
4548
this.inputTargets.forEach(input => input.checked = isChecked)
4649
this.updateTriggerContent()
4750
}

lib/ruby_ui/combobox/combobox_toggle_all_checkbox.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
module RubyUI
44
class ComboboxToggleAllCheckbox < Base
55
def view_template
6-
render RubyUI::ComboboxCheckbox.new(**attrs)
6+
input(type: "checkbox", **attrs)
77
end
88

99
private
1010

1111
def default_attrs
1212
{
13+
class: [
14+
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background accent-primary",
15+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
16+
"disabled:cursor-not-allowed disabled:opacity-50"
17+
],
1318
data: {
14-
ruby_ui__combobox_target: "toggle",
15-
action: "change->ruby-ui--combobox#toggleInputs"
19+
ruby_ui__combobox_target: "toggleAll",
20+
action: "change->ruby-ui--combobox#toggleAllItems"
1621
}
1722
}
1823
end

0 commit comments

Comments
 (0)