Skip to content

Commit

Permalink
Merge pull request #1952 from alphagov/add-border-to-breadcrumb
Browse files Browse the repository at this point in the history
Add bottom border option to breadcrumb
  • Loading branch information
injms authored Mar 2, 2021
2 parents 0ae84f3 + 7d6d9a7 commit 77496db
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
useful summary for people upgrading their application, not a replication
of the commit log.

## Unreleased

* Add border option to breadcrumb ([PR #1952])(https://github.com/alphagov/govuk_publishing_components/pull/1952) MINOR

## 24.3.1

* Show password fixes ([PR #1947](https://github.com/alphagov/govuk_publishing_components/pull/1947))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
border-color: govuk-colour("white");
}

.gem-c-breadcrumbs--border-bottom {
border-bottom: 1px solid $govuk-border-colour;
padding-bottom: govuk-spacing(1);

&.govuk-breadcrumbs--collapse-on-mobile {
@include govuk-media-query($until: tablet) {
padding-bottom: 0;
}
}
}

.govuk-breadcrumbs--collapse-on-mobile {
@include govuk-media-query($until: tablet) {
.govuk-breadcrumbs__list-item {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<%
border ||= false
breadcrumbs ||= []
inverse ||= false
collapse_on_mobile ||= false
inverse ||= false

breadcrumb_presenter = GovukPublishingComponents::Presenters::Breadcrumbs.new(breadcrumbs)

classes = "gem-c-breadcrumbs govuk-breadcrumbs"
classes << " govuk-breadcrumbs--collapse-on-mobile" if collapse_on_mobile
classes << " gem-c-breadcrumbs--inverse" if inverse
classes = %w[gem-c-breadcrumbs govuk-breadcrumbs]
classes << "govuk-breadcrumbs--collapse-on-mobile" if collapse_on_mobile
classes << "gem-c-breadcrumbs--inverse" if inverse
classes << "gem-c-breadcrumbs--border-bottom" if border == "bottom"
%>

<script type="application/ld+json">
<%= raw JSON.pretty_generate(breadcrumb_presenter.structured_data) %>
</script>

<div class="<%= classes %>" data-module="gem-track-click">
<div class="<%= classes.join(" ") %>" data-module="gem-track-click">
<ol class="govuk-breadcrumbs__list">
<% breadcrumbs.each_with_index do |crumb, index| %>
<% breadcrumb = GovukPublishingComponents::Presenters::Breadcrumb.new(crumb, index) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,25 @@ examples:
url: '/browse/abroad'
- title: 'Travel abroad'
url: '/browse/abroad/travel-abroad'
with_border:
description: "Set a border below the breadcrumb. Off by default."
data:
border: "bottom"
breadcrumbs:
- title: "Section"
url: "/section"
- title: "Sub-section"
url: "/section/sub-section"
- title: "Sub-sub-section"
url: "/section/sub-section/sub-section"
with_border_and_collapse_on_mobile:
data:
border: "bottom"
collapse_on_mobile: true
breadcrumbs:
- title: "Section"
url: "/section"
- title: "Sub-section"
url: "/section/sub-section"
- title: "Sub-sub-section"
url: "/section/sub-section/sub-section"
15 changes: 15 additions & 0 deletions spec/components/breadcrumbs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,19 @@ def assert_link_with_text_in(selector, link, text)

assert_select(".gem-c-breadcrumbs.govuk-breadcrumbs.govuk-breadcrumbs--collapse-on-mobile")
end

it "has a border when passed a border parameter" do
render_component(
border: "bottom",
breadcrumbs: [
{ title: "Home", url: "/" },
{ title: "Section", url: "/section" },
{ title: "Sub-section", url: "/sub-section" },
{ title: "Sub-sub-section", url: "/sub-sub-section" },
{ title: "Sub-sub-sub-section", url: "/sub-sub-sub-section" },
],
)

assert_select(".gem-c-breadcrumbs.govuk-breadcrumbs.gem-c-breadcrumbs--border-bottom")
end
end

0 comments on commit 77496db

Please sign in to comment.