Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checkbox label styles #4800

Merged
merged 1 commit into from
Apr 4, 2022
Merged

Fix checkbox label styles #4800

merged 1 commit into from
Apr 4, 2022

Conversation

taitus
Copy link
Member

@taitus taitus commented Mar 31, 2022

References

Reference to Pending notes: https://github.com/orgs/consul/projects/1#card-74165527

Background

Currently we use a display: block style for labels containing check boxes inside them, and so the label has a width of 100%.

Since, on most browsers, clicking on a label has a similar effect as clicking on its associated input, this means that clicking on the blank space on the right of the label text will check/uncheck the checkbox. In usability tests we've seen people accidentally activating and deactivating options without noticing, due to this issue.

Objectives

Check checkbox labels styles in the admin section in order to prevent accidental clicks.

@taitus taitus self-assigned this Mar 31, 2022
@javierm javierm changed the title Admin checkbox label styles Fix admin checkbox label styles Mar 31, 2022
@javierm javierm self-assigned this Apr 1, 2022
Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taitus The display: table solution looks great 👍. The only issue I see is there might be side effects if we apply it everywhere 🤔. I've left an idea about doing it only for checkboxes.

@@ -315,6 +315,16 @@ $table-header: #ecf1f6;
.proposal-new {
padding-top: 0;
}

form {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just realized this also happens in public sections such as "My account". Maybe we can use a more generic solution, and apply it just to check boxes 🤔.

diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss
index d26617846..b4eecfd5f 100644
--- a/app/assets/stylesheets/layout.scss
+++ b/app/assets/stylesheets/layout.scss
@@ -1063,6 +1063,10 @@ form {
     line-height: $line-height;
   }
 
+  .checkbox-label {
+    display: table;
+  }
+
   fieldset legend {
     font-weight: bold;
   }
diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb
index 5eb292079..9d2453458 100644
--- a/lib/consul_form_builder.rb
+++ b/lib/consul_form_builder.rb
@@ -25,7 +25,11 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
     else
       label = tag.span sanitize(label_text(attribute, options[:label])), class: "checkbox"
 
-      super(attribute, options.merge(label: label, label_options: label_options_for(options)))
+      # TODO: add test; note adding options[:label_options][:class] would overwrite it; is it OK like this?
+      super(attribute, options.merge(
+        label: label,
+        label_options: { class: "checkbox-label" }.merge(label_options_for(options))
+      ))
     end
   end

spec/lib/consul_form_builder_spec.rb Outdated Show resolved Hide resolved
app/assets/stylesheets/layout.scss Outdated Show resolved Hide resolved
We are use a display: block style for labels containing check boxes inside
them, and the label has a width of 100%.

This means that clicking on the blank space on the right of the label text
will check/uncheck the checkbox. To avoid this behaviour we modify the
"display" attribute of the labels.

In order to prevent unexpected behaviour in terms_of_service form labels,
we add specific css for this case when define a checkbox within the
.actions class.
@taitus taitus requested a review from javierm April 4, 2022 16:56
@javierm javierm changed the title Fix admin checkbox label styles Fix checkbox label styles Apr 4, 2022
Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taitus Nice! 🎉

@taitus taitus merged commit fbc74e8 into master Apr 4, 2022
@taitus taitus deleted the checkbox_label_styles branch April 4, 2022 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants