Skip to content

Commit e9ec428

Browse files
pierry01claude
andauthored
feat(combobox): reuse CheckboxGroup for required ComboboxCheckbox (#479)
* feat(combobox): reuse CheckboxGroup for required ComboboxCheckbox Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore(mcp): rebuild registry.json for ComboboxCheckbox CheckboxGroup wiring Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 505dc60 commit e9ec428

4 files changed

Lines changed: 61 additions & 2 deletions

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)

mcp/data/registry.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@
935935
},
936936
{
937937
"path": "combobox_checkbox.rb",
938-
"content": "# frozen_string_literal: true\n\nmodule RubyUI\n class ComboboxCheckbox < Base\n def view_template\n input(type: \"checkbox\", **attrs)\n end\n\n private\n\n def default_attrs\n {\n class: [\n \"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background accent-primary\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n \"checked:bg-primary checked:text-primary-foreground\",\n \"aria-disabled:cursor-not-allowed aria-disabled:opacity-50 aria-disabled:pointer-events-none\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2\"\n ],\n data: {\n ruby_ui__combobox_target: \"input\",\n action: \"ruby-ui--combobox#inputChanged\"\n }\n }\n end\n end\nend\n"
938+
"content": "# frozen_string_literal: true\n\nmodule RubyUI\n class ComboboxCheckbox < Base\n def view_template\n input(type: \"checkbox\", **attrs)\n end\n\n private\n\n def default_attrs\n {\n class: [\n \"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background accent-primary\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n \"checked:bg-primary checked:text-primary-foreground\",\n \"aria-disabled:cursor-not-allowed aria-disabled:opacity-50 aria-disabled:pointer-events-none\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2\"\n ],\n data: {\n ruby_ui__combobox_target: \"input\",\n ruby_ui__checkbox_group_target: \"checkbox\",\n ruby_ui__form_field_target: \"input\",\n action: %w[\n ruby-ui--combobox#inputChanged\n change->ruby-ui--checkbox-group#onChange\n change->ruby-ui--form-field#onInput\n invalid->ruby-ui--form-field#onInvalid\n ]\n }\n }\n end\n end\nend\n"
939939
},
940940
{
941941
"path": "combobox_clear_button.rb",

0 commit comments

Comments
 (0)