Skip to content

Commit

Permalink
Add value and test for id
Browse files Browse the repository at this point in the history
Add Component wrapper helper
  • Loading branch information
davidtrussler committed Sep 18, 2024
1 parent ebe7f2a commit 4748e05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@

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 class: "gem-c-secondary-navigation", id: id, role: "navigation", aria: { label: aria_label } do %>
<%= tag.nav(**component_helper.all_attributes) do %>
<%= tag.ul class: "gem-c-secondary-navigation__list" do %>
<% items.each do |item| %>
<%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ accessibility_criteria: |
* 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
Expand Down
10 changes: 2 additions & 8 deletions spec/components/secondary_navigation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@ def component_name
"secondary_navigation"
end

it "renders the component" do
render_component({
aria_label: "Document navigation",
})

assert_select ".gem-c-secondary-navigation", count: 1
end

it "renders the component with current page" do
render_component({
aria_label: "Document navigation",
id: "nav_1234",
items: [
{
label: "Nav item 1",
Expand All @@ -38,5 +31,6 @@ def component_name
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

0 comments on commit 4748e05

Please sign in to comment.