Skip to content

Commit

Permalink
Add an aria-label and role to the cookie banner
Browse files Browse the repository at this point in the history
  • Loading branch information
peteryates committed Feb 17, 2021
1 parent c703e53 commit 5681ba0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/components/govuk_component/cookie_banner.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= tag.div(class: classes, **html_attributes) do %>
<%= tag.div(class: classes, role: "region", aria: { label: aria_label }, **html_attributes) do %>
<div class="govuk-cookie-banner__message govuk-width-container">
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
7 changes: 4 additions & 3 deletions app/components/govuk_component/cookie_banner.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
class GovukComponent::CookieBanner < GovukComponent::Base
with_content_areas :body, :actions

attr_accessor :title
attr_accessor :title, :aria_label

def initialize(title: nil, classes: [], html_attributes: {})
def initialize(title: nil, aria_label: "Cookie banner", classes: [], html_attributes: {})
super(classes: classes, html_attributes: html_attributes)

@title = title
@title = title
@aria_label = aria_label
end

private
Expand Down
9 changes: 9 additions & 0 deletions spec/components/govuk_component/cookie_banner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
end
end

context "custom aria labels" do
let(:aria_label) { "Cookie section" }
let(:kwargs) { { aria_label: aria_label } }

specify "sets the aria-label correctly" do
expect(page).to have_css(%(div.govuk-cookie-banner[aria-label="#{aria_label}"]))
end
end

context "when there is no title" do
let(:kwargs) { {} }

Expand Down

0 comments on commit 5681ba0

Please sign in to comment.