Skip to content

Commit

Permalink
Merge pull request #700 from alphagov/breadcrumb-component
Browse files Browse the repository at this point in the history
Create a breadcrumb component
  • Loading branch information
dsingleton committed Jan 13, 2016
2 parents b0cc136 + bd74f85 commit 12c72ba
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/assets/stylesheets/govuk-component/_breadcrumbs.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.govuk-breadcrumbs {
padding-top: 0.75em;
padding-bottom: 0.75em;

ol {
@extend %contain-floats;

li {
@include core-16;
background-image: image-url("separator.png");
background-position: 0% 50%;
background-repeat: no-repeat;
float: left;
list-style: none;
margin-left: 0.6em;
margin-right: 0;
margin-bottom: 0.4em;
padding-left: 0.9em;

@include device-pixel-ratio() {
background-image: image-url("separator-2x.png");
background-size: 6px 11px;
}

a {
color: $text-colour;
}

&:first-child {
background-image: none;
margin-left: 0;
padding-left: 0;
}
}
}
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/govuk-component/_component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
@import "title";
@import "option-select";
@import "previous-and-next-navigation";
@import "breadcrumbs";
15 changes: 15 additions & 0 deletions app/views/govuk_component/breadcrumbs.raw.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%
breadcrumbs ||= []
%>
<div class="govuk-breadcrumbs">
<ol role="breadcrumbs">
<li>
<a href="/">Home</a>
</li>
<% breadcrumbs.each do |crumb| %>
<li>
<a href="<%= crumb[:url] %>"><%= crumb[:title] %></a>
</li>
<% end %>
</ol>
</div>
31 changes: 31 additions & 0 deletions app/views/govuk_component/docs/breadcrumbs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Breadcrumbs"
description: "Navigational breadcrumbs, showing page hierarchy"
body: |
Accepts an array of breadcrumb objects. Each crumb must have a title and a URL.
fixtures:
default:
breadcrumbs:
- title: 'Section'
url: '/section'
- title: 'Sub-section'
url: '/section/sub-section'
no_breadcrumbs:
breadcrumbs: []
single_section:
breadcrumbs:
- title: 'Section'
url: '/section'
many_breadcrumbs:
breadcrumbs:
- title: 'Section'
url: '/section'
- title: 'Sub-section'
url: '/section/sub-section'
- title: 'Sub Sub-section'
url: '/section/sub-section/sub-sub-section'
real:
breadcrumbs:
- title: 'Passports, travel and living abroad'
url: '/browse/abroad'
- title: 'Travel abroad'
url: '/browse/abroad/travel-abroad'
34 changes: 34 additions & 0 deletions test/govuk_component/breadcrumbs_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'govuk_component_test_helper'

class BreadcrumbsTestCase < ComponentTestCase
def component_name
"breadcrumbs"
end

test "no error if no parameters passed in" do
assert_nothing_raised do
render_component({})
assert_select ".govuk-breadcrumbs"
end
end

test "renders a single breadcrumb" do
render_component({ breadcrumbs: [{title: 'Section', url: '/section'}] })

assert_link_with_text_in('ol li:first-child', '/', 'Home')
assert_link_with_text_in('ol li:last-child', '/section', 'Section')
end

test "renders a list of breadcrumbs" do
render_component({
breadcrumbs: [
{title: 'Section', url: '/section'},
{title: 'Sub-section', url: '/sub-section'},
]
})

assert_link_with_text_in('ol li:first-child', '/', 'Home')
assert_link_with_text_in('ol li:first-child + li', '/section', 'Section')
assert_link_with_text_in('ol li:last-child', '/sub-section', 'Sub-section')
end
end

0 comments on commit 12c72ba

Please sign in to comment.