Skip to content

Commit

Permalink
Add disabled class to label's additional classes
Browse files Browse the repository at this point in the history
Adds disabled class to the attribute label so that it might also be
styled when the input is disabled
  • Loading branch information
rhodrid committed Feb 16, 2015
1 parent b2516e7 commit 3184118
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simple_form/components/labels.rb
Expand Up @@ -42,7 +42,7 @@ def label_target

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)
Expand Down
10 changes: 10 additions & 0 deletions test/form_builder/label_test.rb
Expand Up @@ -29,6 +29,16 @@ def with_label_for(object, *args, &block)
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: '<script>alert(1337)</script>', required: false
assert_no_select 'label.string script'
Expand Down

0 comments on commit 3184118

Please sign in to comment.