Avoid rendering an empty list in footer

We've had an accessibility error reported by the Spanish "Portal
Administración electrónica" (PAe). While I can't find any accessibility
rule saying empty lists should be avoided, it looks like some screen
readers report finding lists with 0 items, which is annoying.

We could also do it with CSS using `ul:empty { display: none}`. However,
at the time of writing no browser supports this rule when the tag
contains whitespace.
This commit is contained in:
Javi Martín
2021-05-06 20:03:36 +02:00
parent 339c3c7eca
commit da76c848fc
2 changed files with 44 additions and 1 deletions

View File

@@ -1,6 +1,10 @@
class Layout::SocialComponent < ApplicationComponent
delegate :content_block, to: :helpers
def render?
sites.any? || footer_content_block.present?
end
private
def sites
@@ -10,7 +14,7 @@ class Layout::SocialComponent < ApplicationComponent
youtube: "https://www.youtube.com",
telegram: "https://www.telegram.me",
instragram: "https://www.instagram.com"
}.select { |name, _| setting["#{name}_handle"] }
}.select { |name, _| setting["#{name}_handle"].present? }
end
def link_title(site_name)

View File

@@ -0,0 +1,39 @@
require "rails_helper"
describe Layout::SocialComponent, type: :component do
describe "#render?" do
it "renders when a social setting is present" do
Setting["twitter_handle"] = "myhandle"
render_inline Layout::SocialComponent.new
expect(page).to have_css "ul"
end
it "renders when a content block is present" do
Setting["twitter_handle"] = ""
Setting["facebook_handle"] = ""
Setting["youtube_handle"] = ""
Setting["telegram_handle"] = ""
Setting["instagram_handle"] = ""
create(:site_customization_content_block, name: "footer")
render_inline Layout::SocialComponent.new
expect(page).to have_css "ul"
end
it "does not render with no settings present and no content block present" do
Setting["twitter_handle"] = ""
Setting["facebook_handle"] = ""
Setting["youtube_handle"] = ""
Setting["telegram_handle"] = ""
Setting["instagram_handle"] = ""
render_inline Layout::SocialComponent.new
expect(page).not_to have_css "ul"
end
end
end