diff --git a/CHANGELOG.md b/CHANGELOG.md index bea55ae47..5cce4c8ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### enhancements * Add wrapper mapping per form basis [@rcillo](https://github.com/rcillo) and [@bernardoamc](https://github.com/bernardoamc) * New `input_class` global config option to set a class to be generated in all inputs. + * New `input_class` global config option to set a class to be generated in all inputs. * `input_field` supports `html5` component [@nashby](https://github.com/nashby) * Add `include_default_input_wrapper_class` config [@luizcosta](https://github.com/luizcosta) diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index b4fbe8a84..90cbf9bab 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -65,6 +65,10 @@ def initialize(builder, attribute_name, column, input_type, options = {}) @html_classes = SimpleForm.additional_classes_for(:input) { additional_classes } @input_html_classes = @html_classes.dup + if SimpleForm.input_class && !input_html_classes.empty? + input_html_classes << SimpleForm.input_class + end + @input_html_options = html_options_for(:input, input_html_classes).tap do |o| o[:readonly] = true if has_readonly? o[:disabled] = true if has_disabled? @@ -81,7 +85,7 @@ def input_options end def additional_classes - @additional_classes ||= [input_type, required_class, readonly_class, disabled_class, SimpleForm.input_class].compact + @additional_classes ||= [input_type, required_class, readonly_class, disabled_class].compact end def input_class diff --git a/test/inputs/general_test.rb b/test/inputs/general_test.rb index 6513aebef..931cb2a36 100644 --- a/test/inputs/general_test.rb +++ b/test/inputs/general_test.rb @@ -20,10 +20,19 @@ class InputTest < ActionView::TestCase assert_select 'input.string[autofocus]' end - test 'input should accepts input class configuration' do - swap SimpleForm, :input_class => :xlarge do + test 'input accepts input_class configuration' do + swap SimpleForm, input_class: :xlarge do with_input_for @user, :name, :string assert_select 'input.xlarge' + assert_no_select 'div.xlarge' + end + end + + test 'input does not add input_class when configured to not generate additional classes for input' do + swap SimpleForm, input_class: 'xlarge', generate_additional_classes_for: [:wrapper] do + with_input_for @user, :name, :string + assert_select 'input' + assert_no_select '.xlarge' end end