-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
There was a problem hiding this 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.
app/assets/stylesheets/admin.scss
Outdated
@@ -315,6 +315,16 @@ $table-header: #ecf1f6; | |||
.proposal-new { | |||
padding-top: 0; | |||
} | |||
|
|||
form { |
There was a problem hiding this comment.
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
54ea57d
to
80ef774
Compare
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.
80ef774
to
923c2a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taitus Nice! 🎉
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.