-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4229 from alphagov/Create-new-component_secondary…
…-navigation Add files for secondary navigation:
- Loading branch information
Showing
7 changed files
with
190 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
app/assets/stylesheets/govuk_publishing_components/components/_secondary-navigation.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
@import "govuk_publishing_components/individual_component_support"; | ||
|
||
.gem-c-secondary-navigation { | ||
@include govuk-font(19); | ||
@include govuk-responsive-margin(6, "bottom"); | ||
|
||
@include govuk-media-query($from: tablet) { | ||
box-shadow: inset 0 -1px 0 $govuk-border-colour; | ||
display: flex; | ||
} | ||
} | ||
|
||
.gem-c-secondary-navigation__list { | ||
list-style: none; | ||
margin-bottom: govuk-spacing(4); | ||
padding: 0; | ||
|
||
@include govuk-media-query($from: tablet) { | ||
box-shadow: none; | ||
display: flex; | ||
margin: 0; | ||
white-space: nowrap; | ||
} | ||
} | ||
|
||
.gem-c-secondary-navigation__list-item { | ||
box-shadow: inset 0 -1px 0 $govuk-border-colour; | ||
|
||
@include govuk-media-query($from: tablet) { | ||
display: flex; | ||
margin-right: 20px; | ||
|
||
&:last-child { | ||
margin-right: 0; | ||
} | ||
} | ||
|
||
&:last-child { | ||
box-shadow: none; | ||
} | ||
|
||
.gem-c-secondary-navigation__list-item-link, | ||
.gem-c-secondary-navigation__list-item-link:link, | ||
.gem-c-secondary-navigation__list-item-link:visited { | ||
background-color: inherit; | ||
border-left: 4px solid transparent; | ||
color: govuk-colour("blue"); | ||
display: block; | ||
padding: govuk-spacing(2); | ||
text-decoration: none; | ||
|
||
@include govuk-media-query($from: tablet) { | ||
border-bottom: 4px solid transparent; | ||
border-left: 0; | ||
padding: govuk-spacing(2) 0; | ||
padding-bottom: govuk-spacing(2) - 4px; // Compensate for 4px border | ||
} | ||
} | ||
|
||
.gem-c-secondary-navigation__list-item-link:hover { | ||
color: $govuk-link-hover-colour; | ||
} | ||
|
||
.gem-c-secondary-navigation__list-item-link:focus { | ||
@include govuk-focused-text; | ||
|
||
border-color: $govuk-focus-text-colour; | ||
border-left-color: transparent; | ||
position: relative; | ||
|
||
@include govuk-media-query($from: tablet) { | ||
box-shadow: none; | ||
} | ||
} | ||
} | ||
|
||
.gem-c-secondary-navigation__list-item--current { | ||
.gem-c-secondary-navigation__list-item-link:link, | ||
.gem-c-secondary-navigation__list-item-link:visited { | ||
border-color: govuk-colour("blue"); | ||
color: $govuk-text-colour; | ||
} | ||
|
||
.gem-c-secondary-navigation__list-item-link:focus { | ||
@include govuk-focused-text; | ||
|
||
border-color: $govuk-focus-text-colour; | ||
border-left-color: transparent; | ||
|
||
@include govuk-media-query($from: tablet) { | ||
box-shadow: none; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/views/govuk_publishing_components/components/_secondary_navigation.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<% | ||
add_gem_component_stylesheet("secondary-navigation") | ||
|
||
id ||= nil | ||
items ||= [] | ||
|
||
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns) | ||
component_helper.add_aria_attribute({label: aria_label}) | ||
component_helper.add_class('gem-c-secondary-navigation') | ||
component_helper.set_id(id) | ||
component_helper.add_role("navigation") | ||
%> | ||
|
||
<% if items.any? %> | ||
<%= tag.nav(**component_helper.all_attributes) do %> | ||
<%= tag.ul class: "gem-c-secondary-navigation__list" do %> | ||
<% items.each do |item| %> | ||
<% | ||
item_classes = %w( gem-c-secondary-navigation__list-item ) | ||
item_classes << "gem-c-secondary-navigation__list-item--current" if item[:current] | ||
item_aria_attributes = { current: "page" } if item[:current] | ||
%> | ||
<%= tag.li class: item_classes do %> | ||
<%= link_to item[:label], item[:href], class: "govuk-link govuk-link--no-visited-state gem-c-secondary-navigation__list-item-link", data: item[:data_attributes], aria: item_aria_attributes %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
28 changes: 28 additions & 0 deletions
28
app/views/govuk_publishing_components/components/docs/secondary_navigation.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Secondary navigation | ||
description: Displays a secondary navigation with the current page marked accordingly | ||
accessibility_criteria: | | ||
The component must: | ||
* indicate that it is navigation landmark | ||
* indicate if a navigation item links to the currently-displayed page | ||
shared_accessibility_criteria: | ||
- link | ||
uses_component_wrapper_helper: true | ||
examples: | ||
default: | ||
data: | ||
id: "nav_1234" | ||
aria_label: Document navigation | ||
items: | ||
- label: Tab 1 | ||
href: "#1" | ||
current: true | ||
data_attributes: | ||
gtm: tab | ||
- label: Tab 2 | ||
href: "#2" | ||
data_attributes: | ||
gtm: tab | ||
- label: Tab 3 | ||
href: "#3" | ||
data_attributes: | ||
gtm: tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "rails_helper" | ||
|
||
describe "Secondary navigation", type: :view do | ||
def component_name | ||
"secondary_navigation" | ||
end | ||
|
||
it "renders the component with current page" do | ||
render_component({ | ||
aria_label: "Document navigation", | ||
id: "nav_1234", | ||
items: [ | ||
{ | ||
label: "Nav item 1", | ||
href: "#", | ||
current: true, | ||
}, | ||
{ | ||
label: "Nav item 2", | ||
href: "#", | ||
}, | ||
{ | ||
label: "Nav item 3", | ||
href: "#", | ||
}, | ||
], | ||
}) | ||
|
||
assert_select ".gem-c-secondary-navigation", count: 1 | ||
assert_select ".gem-c-secondary-navigation__list-item", count: 3 | ||
assert_select ".gem-c-secondary-navigation__list-item--current", count: 1 | ||
assert_select ".gem-c-secondary-navigation__list-item--current", text: "Nav item 1" | ||
assert_select ".gem-c-secondary-navigation__list-item--current a[aria-current='page']" | ||
assert_select ".gem-c-secondary-navigation[id='nav_1234']" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters