Skip to content

Commit 0ff7668

Browse files
committed
Add class option to dropdown form selects
Until now it was not possible to add a class to the ``<select>`` field. This fixes the behaviour of the ``form_select type: :dropdown`` to be more similar to other components.
1 parent ae06d97 commit 0ff7668

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

app/concepts/matestack/ui/core/form/select/select.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
%select{"#{model_binding}" => input_key,
88
id: component_id,
99
ref: "select.#{attr_key}",
10+
class: options[:class],
1011
"@change": "inputChanged(\"#{attr_key}\")",
1112
"init-value": init_value,
1213
"value-type": options_type}

spec/usage/components/form_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,37 @@ def form_config
879879

880880
it "can have a placeholder"
881881

882+
it "can have a class" do
883+
class ExamplePage < Matestack::Ui::Page
884+
def response
885+
components {
886+
form form_config, :include do
887+
form_select id: "my-array-test-dropdown", key: :array_input, type: :dropdown, options: ["Array Option 1","Array Option 2"], class: "form-control"
888+
form_select id: "my-hash-test-dropdown", key: :hash_input, type: :dropdown, options: { "1": "Hash Option 1", "2": "Hash Option 2" }, class: "form-control"
889+
form_submit do
890+
button text: "Submit me!"
891+
end
892+
end
893+
}
894+
end
895+
896+
def form_config
897+
return {
898+
for: :my_object,
899+
method: :post,
900+
path: :success_form_test_path,
901+
params: {
902+
id: 42
903+
}
904+
}
905+
end
906+
end
907+
908+
visit "/example"
909+
910+
expect(page).to have_css("#my-array-test-dropdown.form-control")
911+
expect(page).to have_css("#my-hash-test-dropdown.form-control")
912+
end
882913
end
883914

884915
describe "Checkbox" do

0 commit comments

Comments
 (0)