Skip to content

Commit 8d56238

Browse files
pierry01claude
andcommitted
feat(combobox): reuse CheckboxGroup for required ComboboxCheckbox
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c7fcc90 commit 8d56238

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

docs/app/views/docs/combobox.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,49 @@ def view_template
123123
RUBY
124124
end
125125

126+
render Docs::VisualCodeExample.new(title: "Required Checkbox", context: self) do
127+
<<~RUBY
128+
form(class: "flex flex-col gap-2 w-96") do
129+
FormField do
130+
FormFieldLabel { "Pick at least one" }
131+
132+
Combobox term: "things" do
133+
ComboboxTrigger placeholder: "Pick value"
134+
135+
ComboboxPopover do
136+
ComboboxSearchInput(placeholder: "Pick value or type anything")
137+
138+
ComboboxList do
139+
ComboboxEmptyState { "No result" }
140+
141+
CheckboxGroup(data_required: true) do
142+
ComboboxItem do
143+
ComboboxCheckbox(name: "food[]", value: "apple", data: {value_missing: "Pick at least one option"})
144+
span { "Apple" }
145+
end
146+
147+
ComboboxItem do
148+
ComboboxCheckbox(name: "food[]", value: "banana", data: {value_missing: "Pick at least one option"})
149+
span { "Banana" }
150+
end
151+
152+
ComboboxItem do
153+
ComboboxCheckbox(name: "food[]", value: "carrot", data: {value_missing: "Pick at least one option"})
154+
span { "Carrot" }
155+
end
156+
end
157+
end
158+
end
159+
end
160+
161+
FormFieldError()
162+
end
163+
164+
Button(type: "submit") { "Submit" }
165+
end
166+
RUBY
167+
end
168+
126169
render Docs::VisualCodeExample.new(title: "Disabled", context: self) do
127170
<<~RUBY
128171
div(class: "w-96") do

gem/lib/ruby_ui/combobox/combobox_checkbox.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ def default_attrs
1919
],
2020
data: {
2121
ruby_ui__combobox_target: "input",
22-
action: "ruby-ui--combobox#inputChanged"
22+
ruby_ui__checkbox_group_target: "checkbox",
23+
ruby_ui__form_field_target: "input",
24+
action: %w[
25+
ruby-ui--combobox#inputChanged
26+
change->ruby-ui--checkbox-group#onChange
27+
change->ruby-ui--form-field#onInput
28+
invalid->ruby-ui--form-field#onInvalid
29+
]
2330
}
2431
}
2532
end

gem/test/ruby_ui/combobox_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ def test_combobox_checkbox_renders_styled_input
9292
assert_match(/checked:bg-primary/, output)
9393
end
9494

95+
def test_combobox_checkbox_wires_checkbox_group_and_form_field
96+
output = phlex { RubyUI.ComboboxCheckbox(name: "x", value: "1") }
97+
assert_match(/data-ruby-ui--checkbox-group-target="checkbox"/, output)
98+
assert_match(/data-ruby-ui--form-field-target="input"/, output)
99+
assert_match(/change->ruby-ui--checkbox-group#onChange/, output)
100+
assert_match(/change->ruby-ui--form-field#onInput/, output)
101+
assert_match(/invalid->ruby-ui--form-field#onInvalid/, output)
102+
end
103+
95104
def test_combobox_item_indicator_renders_check_svg
96105
output = phlex { RubyUI.ComboboxItemIndicator() }
97106
assert_match(/peer-checked:opacity-100/, output)

0 commit comments

Comments
 (0)