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 column alignment in the "More on GOV.UK" homepage component #3253

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions app/assets/stylesheets/views/_homepage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,44 @@
padding: 0;

@include govuk-media-query($from: desktop) {
@include columns($items: 10, $columns: 2, $selector: "li", $flow: column);
width: 66.66%;
columns: 2;
column-gap: 15px;
patrickpatrickpatrick marked this conversation as resolved.
Show resolved Hide resolved
}
}

& > li {
margin: 0 0 govuk-spacing(4) 0;
@include govuk-font($size: 19);
.homepage-most-active-list__item {
margin: 0 0 govuk-spacing(4) 0;
@include govuk-font($size: 19);
@include govuk-media-query($from: desktop) {
break-inside: avoid-column;
margin-bottom: 0;
padding-top: .1875rem;
padding-bottom: calc(#{govuk-spacing(2)} - .1875rem);

@include govuk-media-query($from: desktop) {
margin-bottom: govuk-spacing(2);
}
// After much experimentation, I've used break-inside: avoid-column
// and some tweaks to padding-top and padding-bottom on the list
// items. This prevents triggering a possible bug in Safari where
// focused anchors in a multi-column layout cause links to jump
// between columns.

// Magic numbers in CSS aren't recommended, but the .1875rem value
// used in the padding is to compensate for the value used in our
// global hover states for links, eg:

// text-decoration-thickness: max(3px, .1875rem, .12em);

// This value could be tweaked, and may not be "correct" but when
// added to the top padding, it prevents Safari from rendering a
// sliver of the focus state in the opposite column.

// The bottom margin was removed and the spacing instead added as
// padding-bottom -- this gives some space within the element for
// the focus/hover states to render without being cropped off,
// another possible Safari bug.

// This likely isn't a long-term robust solution and may require
// a full refactor in the future.
}
}

Expand Down
43 changes: 19 additions & 24 deletions app/views/homepage/_more_on_govuk.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@
font_size: "m",
} %>
</div>

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half govuk-grid-column-two-thirds-from-desktop">
<ul class="homepage-most-active-list" data-module="gem-track-click">
<% t("homepage.index.more_links").each do | item | %>
<li>
<%= link_to(
item[:title],
item[:link],
class: "govuk-link",
data: {
"track-category": "homepageClicked",
"track-action": "moreLink",
"track-label": item[:link],
"track-value": "1",
"track-dimension": item[:title],
"track-dimension-index": "29",
}
) %>
</li>
<% end %>
</ul>
</div>
</div>
<ul class="homepage-most-active-list" data-module="gem-track-click">
<% t("homepage.index.more_links").each do | item | %>
<li class="homepage-most-active-list__item">
<%= link_to(
item[:title],
item[:link],
class: "govuk-link",
data: {
"track-category": "homepageClicked",
"track-action": "moreLink",
"track-label": item[:link],
"track-value": "1",
"track-dimension": item[:title],
"track-dimension-index": "29",
}
) %>
</li>
<% end %>
</ul>
</section>