From 31841186f0fa1e939fe13fc8a1232f1085164e0b Mon Sep 17 00:00:00 2001 From: Rhodri Davies Date: Mon, 16 Feb 2015 17:49:15 +0000 Subject: [PATCH] Add disabled class to label's additional classes Adds disabled class to the attribute label so that it might also be styled when the input is disabled --- lib/simple_form/components/labels.rb | 2 +- test/form_builder/label_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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'