Correctly align radio buttons with their labels

We were using a `height: $line-height` property for this task. One of
the disadvantages of this approach is that things don't look so great
when the label expands over more than one line.

Back when we added that property, browser support for flex layouts
wasn't that great. Now there's universal support for it, so we can use
it instead.
This commit is contained in:
Javi Martín
2025-07-09 14:28:11 +02:00
parent d5b4e5b7b9
commit b4eba055c7
11 changed files with 51 additions and 14 deletions

View File

@@ -168,6 +168,10 @@ $table-header: #ecf1f6;
font-weight: bold; font-weight: bold;
} }
.radio {
@include radio-or-checkbox-and-label-alignment;
}
select { select {
height: $input-height; height: $input-height;
} }

View File

@@ -0,0 +1,11 @@
.dashboard-action-form {
.collection-radio-buttons {
column-gap: $line-height;
display: flex;
flex-wrap: wrap;
}
.radio-and-label {
@include radio-or-checkbox-and-label-alignment;
}
}

View File

@@ -85,4 +85,12 @@
} }
} }
} }
.radio-and-label {
@include radio-or-checkbox-and-label-alignment;
span {
margin-left: 1ch;
}
}
} }

View File

@@ -1,6 +1,6 @@
.admin .locales-form { .admin .locales-form {
label { label {
display: table; @include radio-or-checkbox-and-label-alignment;
} }
select { select {

View File

@@ -0,0 +1,5 @@
.site-customization-pages-form {
.radio-and-label {
@include radio-or-checkbox-and-label-alignment;
}
}

View File

@@ -5,7 +5,7 @@
} }
.radio-and-label { .radio-and-label {
display: flex; @include radio-or-checkbox-and-label-alignment;
margin-bottom: calc($line-height / 3); margin-bottom: calc($line-height / 3);
&:last-of-type { &:last-of-type {

View File

@@ -909,7 +909,6 @@ form {
} }
[type="radio"] { [type="radio"] {
height: $line-height !important;
vertical-align: top; vertical-align: top;
+ label { + label {

View File

@@ -199,3 +199,9 @@
text-transform: uppercase; text-transform: uppercase;
} }
} }
@mixin radio-or-checkbox-and-label-alignment {
align-items: baseline;
display: flex;
max-width: max-content;
}

View File

@@ -3,13 +3,15 @@
<%= render "shared/errors" %> <%= render "shared/errors" %>
<div class="row expanded"> <div class="row expanded">
<fieldset class="small-12 medium-4 column"> <fieldset class="small-12 column">
<legend><%= attribute_name(:action_type) %></legend> <legend><%= attribute_name(:action_type) %></legend>
<% ::Dashboard::Action.action_types.keys.each do |action_type_value| %> <div class="collection-radio-buttons">
<span class="margin-right"> <% ::Dashboard::Action.action_types.keys.each do |action_type_value| %>
<%= f.radio_button :action_type, action_type_value %> <span class="radio-and-label">
</span> <%= f.radio_button :action_type, action_type_value %>
<% end %> </span>
<% end %>
</div>
</fieldset> </fieldset>
<div class="small-12 column margin-top"> <div class="small-12 column margin-top">

View File

@@ -63,9 +63,10 @@
<fieldset class="small-12 column"> <fieldset class="small-12 column">
<legend><%= attribute_name(:status) %></legend> <legend><%= attribute_name(:status) %></legend>
<% ::Legislation::DraftVersion::VALID_STATUSES.each do |status| %> <% ::Legislation::DraftVersion::VALID_STATUSES.each do |status| %>
<%= f.radio_button :status, status %> <span class="radio-and-label">
<span class="help-text"><%= t("admin.legislation.draft_versions.form.hints.status.#{status}") %></span> <%= f.radio_button :status, status %>
<br> <span class="help-text"><%= t("admin.legislation.draft_versions.form.hints.status.#{status}") %></span>
</span>
<% end %> <% end %>
</fieldset> </fieldset>

View File

@@ -13,8 +13,9 @@
<fieldset> <fieldset>
<legend><%= attribute_name(:status) %></legend> <legend><%= attribute_name(:status) %></legend>
<% ::SiteCustomization::Page::VALID_STATUSES.each do |status| %> <% ::SiteCustomization::Page::VALID_STATUSES.each do |status| %>
<%= f.radio_button :status, status %> <span class="radio-and-label">
<br> <%= f.radio_button :status, status %>
</span>
<% end %> <% end %>
</fieldset> </fieldset>