diff --git a/lib/simple_form/components/labels.rb b/lib/simple_form/components/labels.rb index a4df781a..138a06bb 100644 --- a/lib/simple_form/components/labels.rb +++ b/lib/simple_form/components/labels.rb @@ -42,7 +42,7 @@ module SimpleForm def label_html_options label_html_classes = SimpleForm.additional_classes_for(:label) { - [input_type, required_class, SimpleForm.label_class].compact + [input_type, required_class, disabled_class, SimpleForm.label_class].compact } label_options = html_options_for(:label, label_html_classes) diff --git a/test/form_builder/label_test.rb b/test/form_builder/label_test.rb index 503bc8da..ae343647 100644 --- a/test/form_builder/label_test.rb +++ b/test/form_builder/label_test.rb @@ -29,6 +29,16 @@ class LabelTest < ActionView::TestCase assert_select 'label.string.required[for=validating_user_name]', /Name/ end + test 'builder adds a disabled class to label if the attribute is disabled' do + with_label_for @validating_user, :name, disabled: true + assert_select 'label.string.disabled[for=validating_user_name]', /Name/ + end + + test 'builder does not add a disabled class to label if the attribute is not disabled' do + with_label_for @validating_user, :name, disabled: false + assert_no_select 'label.string.disabled[for=validating_user_name]', /Name/ + end + test 'builder escapes label text' do with_label_for @user, :name, label: '', required: false assert_no_select 'label.string script'