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

Allow context in titles to be a link #1160

Merged
merged 1 commit into from Oct 2, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/assets/stylesheets/govuk-component/_title.scss
Expand Up @@ -23,6 +23,24 @@
color: $secondary-text-colour;
}

.pub-c-title__context-link {
text-decoration: none;

&:link,
&:visited {
color: inherit;

&:focus {
color: $black;
}
}

&:hover,
&:focus {
text-decoration: underline;
}
}

.pub-c-title__text {
@include bold-48;
}
Expand Down
25 changes: 25 additions & 0 deletions app/views/govuk_component/docs/title.yml
Expand Up @@ -14,6 +14,8 @@ accessibility_criteria: |
- be part of a correct heading structure for a page
- be semantically represented as a heading
- convey the heading level
shared_accessibility_criteria:
- link
examples:
default:
data:
Expand All @@ -22,6 +24,18 @@ examples:
data:
context: Publication
title: My page title
with_context_link:
description: |
It’s unclear if links in the context of a title are useful and are being clicked by users. Data attributes are included to track this behaviour.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this!


Context links are used on [topic pages](https://www.gov.uk/topic/business-tax/vat) where there is also a breadcrumb.
data:
context:
text: Publication
href: '/link'
data:
some_tracking_parameter: 'tracking-param'
title: My page title
long_title_with_context:
data:
context: Publication
Expand All @@ -36,3 +50,14 @@ examples:
margin_bottom: 0
context:
dark_background: true
in_html_publication_with_context_link:
description: Page titles are used in HTML Publications ([see example](https://www.gov.uk/government/publications/fees-for-civil-and-family-courts/court-fees-for-the-high-court-county-court-and-family-court))
data:
context:
text: Publication
href: '/link'
title: HTML publication page title
inverse: true
margin_bottom: 0
context:
dark_background: true
8 changes: 7 additions & 1 deletion app/views/govuk_component/title.raw.html.erb
@@ -1,6 +1,10 @@
<%
average_title_length ||= false
context ||= false
context_text = context.is_a?(Hash) ? context[:text] : context
context_href = context.is_a?(Hash) ? context[:href] : false
context_data = context.is_a?(Hash) ? context[:data] : false

inverse ||= false
margin_bottom ||= 1
margin_bottom_class = "pub-c-title--bottom-margin" if margin_bottom == 1
Expand All @@ -9,7 +13,9 @@
<% if inverse %>pub-c-title--inverse<% end %>
<%= margin_bottom_class %>">
<% if context %>
<p class="pub-c-title__context"><%= context %></p>
<p class="pub-c-title__context">
<%= context_href ? link_to(context_text, context_href, class: 'pub-c-title__context-link', data: context_data) : context_text %>
</p>
<% end %>
<h1 class="pub-c-title__text <% if average_title_length %>pub-c-title__text--<%= average_title_length %><% end %>">
<%= title %>
Expand Down
5 changes: 5 additions & 0 deletions test/govuk_component/title_test.rb
Expand Up @@ -21,6 +21,11 @@ def component_name
assert_select ".pub-c-title__context", text: "Format"
end

test "title context link appears" do
render_component(title: "Hello World", context: { text: "Format", href: "/format", data: { tracking: true } })
assert_select ".pub-c-title__context-link[href='/format'][data-tracking]", text: "Format"
end

test "applies title length if supplied" do
render_component(title: "Hello World", context: "format", average_title_length: 'long')
assert_select ".pub-c-title .pub-c-title__text--long", text: "Hello World"
Expand Down