Skip to content

Commit

Permalink
Don't render empty SDG tag list div
Browse files Browse the repository at this point in the history
The same way we don't render empty regular tags since commit 4d27bbe.

This way we avoid adding an empty `<div class="sdg-tag-list">` tag,
which might have associated styles (in custom CONSUL installation
styles, for instance) and thus break the layout
  • Loading branch information
javierm committed Sep 11, 2021
1 parent 30bbd84 commit 4199cc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/components/sdg/tag_list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def initialize(record, limit: nil, linkable: true)
@linkable = linkable
end

def render?
record.sdg_goals.any? || record.sdg_targets.any?
end

private

def goals_list
Expand Down
8 changes: 8 additions & 0 deletions spec/components/sdg/tag_list_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
expect(page).to have_link "target 3.2.1"
end

it "does not render when there are no tags" do
record = build(:debate, sdg_goals: [], sdg_targets: [])

render_inline SDG::TagListComponent.new(record)

expect(page.native.inner_html).to be_empty
end

context "when linkable is false" do
let(:component) { SDG::TagListComponent.new(debate, linkable: false) }

Expand Down

0 comments on commit 4199cc5

Please sign in to comment.