diff --git a/app/views/govuk_publishing_components/components/_image_card.html.erb b/app/views/govuk_publishing_components/components/_image_card.html.erb
index e8ecb9b7b7..548eb34ec7 100644
--- a/app/views/govuk_publishing_components/components/_image_card.html.erb
+++ b/app/views/govuk_publishing_components/components/_image_card.html.erb
@@ -2,6 +2,7 @@
brand ||= false
brand_helper = GovukPublishingComponents::AppHelpers::BrandHelper.new(brand)
card_helper = GovukPublishingComponents::Presenters::ImageCardHelper.new(local_assigns)
+ shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
%>
<% if card_helper.href || card_helper.extra_links.any? %>
<%= brand_helper.brand_class %>"
@@ -13,7 +14,7 @@
<%= card_helper.context %>
<% if card_helper.heading_text %>
- <%= content_tag(card_helper.heading_tag,
+ <%= content_tag(shared_helper.get_heading_level,
class: "gem-c-image-card__title") do %>
<% if card_helper.href %>
<%= link_to card_helper.heading_text, card_helper.href,
diff --git a/lib/govuk_publishing_components/presenters/image_card_helper.rb b/lib/govuk_publishing_components/presenters/image_card_helper.rb
index 4ca61f49c4..7fc1867ddf 100644
--- a/lib/govuk_publishing_components/presenters/image_card_helper.rb
+++ b/lib/govuk_publishing_components/presenters/image_card_helper.rb
@@ -16,7 +16,6 @@ def initialize(local_assigns)
@description = local_assigns[:description]
@large = local_assigns[:large]
@heading_text = local_assigns[:heading_text]
- @heading_level = local_assigns[:heading_level] || 2
@extra_links_no_indent = local_assigns[:extra_links_no_indent]
@metadata = local_assigns[:metadata]
end
@@ -59,11 +58,6 @@ def context
end
end
- def heading_tag
- return "h#{@heading_level}" if [1, 2, 3, 4, 5, 6].include? @heading_level
- return "span" if @heading_level.zero?
- end
-
def description
content_tag(:div, @description, class: "gem-c-image-card__description") if @description
end
diff --git a/lib/govuk_publishing_components/presenters/shared_helper.rb b/lib/govuk_publishing_components/presenters/shared_helper.rb
index ef12e11054..3e4b02d7c2 100644
--- a/lib/govuk_publishing_components/presenters/shared_helper.rb
+++ b/lib/govuk_publishing_components/presenters/shared_helper.rb
@@ -14,7 +14,9 @@ def get_margin_bottom
end
def get_heading_level
- [*1..6].include?(@heading_level) ? "h#{@heading_level}" : "h2"
+ return [*1..6].include?(@heading_level) ? "h#{@heading_level}" : "h2" unless @heading_level.zero?
+
+ "span"
end
end
end
diff --git a/spec/lib/components/shared_helper_spec.rb b/spec/lib/components/shared_helper_spec.rb
index 5b4a905a83..8e3cda5904 100644
--- a/spec/lib/components/shared_helper_spec.rb
+++ b/spec/lib/components/shared_helper_spec.rb
@@ -35,5 +35,11 @@
heading = shared_helper.get_heading_level
expect(heading).to eql('h2')
end
+
+ it "returns a span instead of a heading if heading level is 0" do
+ shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(heading_level: 0)
+ result = shared_helper.get_heading_level
+ expect(result).to eql('span')
+ end
end
end