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

Update layout header component #1902

Merged
merged 2 commits into from
Feb 5, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Fix bugs on the feedback component ([PR #1900](https://github.com/alphagov/govuk_publishing_components/pull/1900))
* Add data attributes to layout footer component ([PR #1904](https://github.com/alphagov/govuk_publishing_components/pull/1904))
* Add option to remove border from document list items ([PR #1907](https://github.com/alphagov/govuk_publishing_components/pull/1907))
* Update layout header component ([PR #1902](https://github.com/alphagov/govuk_publishing_components/pull/1902))

## 23.14.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ examples:
- text: News and communications
href: "item-6"
active: true
with_navigation_link_data_attributes:
description: Supports adding data attributes i.e for tracking
data:
navigation_items:
- text: Departments
href: "item-1"
data:
module: "a custom attribute"
something_else: "some other custom attribute"
- text: Worldwide
href: "item-2"
full_width:
description: |
This is difficult to preview because the preview windows are constrained, but the header will stretch to the size of its container.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<% if navigation_items.any? %>
<button role="button" class="govuk-header__menu-button gem-c-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="Show or hide Top Level Navigation">Menu</button>
<%= tag.nav(class: "gem-c-header__nav", 'aria-label': navigation_aria_label ? navigation_aria_label : nil ) do %>
<%= tag.nav class: "gem-c-header__nav", aria: { label: navigation_aria_label } do %>
<ul id="navigation" class="govuk-header__navigation govuk-header__navigation--end">
<% navigation_items.each_with_index do |item, index| %>
<li class="govuk-header__navigation-item <%= "govuk-header__navigation-item--active" if item[:active] %>
<%= "govuk-header__navigation-item--collapsed-menu-only" if item[:show_only_in_collapsed_menu] %>">
<%
li_classes = %w(govuk-header__navigation-item)
li_classes << "govuk-header__navigation-item--active" if item[:active]
li_classes << "govuk-header__navigation-item--collapsed-menu-only" if item[:show_only_in_collapsed_menu]
danacotoran marked this conversation as resolved.
Show resolved Hide resolved
%>
<%= tag.li class: li_classes do %>
<%= link_to(
item[:text],
item[:href],
class: 'govuk-header__link',
data: item[:data],
) %>
</li>
<% end %>
<% end %>
</ul>
danacotoran marked this conversation as resolved.
Show resolved Hide resolved
<% end %>
Expand Down
24 changes: 24 additions & 0 deletions spec/components/layout_header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ def component_name
assert_select ".gem-c-header__nav[aria-label='My fancy label']"
end

it "renders the navigation links with data attributes when specified" do
navigation_items = [
{
text: "Foo",
href: "/foo",
data: {
hello: "world",
},
},
{
text: "Bar",
href: "/bar",
data: {
more_than_one_word: "test",
},
},
]

render_component(navigation_items: navigation_items)

assert_select ".gem-c-header__nav .govuk-header__link[data-hello='world']", text: "Foo"
assert_select ".gem-c-header__nav .govuk-header__link[data-more-than-one-word='test']", text: "Bar"
end

it "renders the header without the bottom border" do
render_component(remove_bottom_border: true, environment: "public")

Expand Down