Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove trailing newlines from the output of LinkComponent #1183

Merged
merged 2 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sour-berries-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Remove trailing newlines from the output of LinkComponent
1 change: 0 additions & 1 deletion app/components/primer/link_component.erb

This file was deleted.

6 changes: 6 additions & 0 deletions app/components/primer/link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ def initialize(href: nil, tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, muted: false
def before_render
raise ArgumentError, "href is required when using <a> tag" if @system_arguments[:tag] == :a && @system_arguments[:href].nil? && !Rails.env.production?
end

def call
render(Primer::BaseComponent.new(**@system_arguments)) do
content.to_s + tooltip.to_s
end
end
end
end
6 changes: 6 additions & 0 deletions test/components/link_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def test_renders_no_additional_whitespace
assert_text(/^content$/)
end

def test_renders_without_trailing_newline
render_inline(Primer::LinkComponent.new(href: "http://joe-jonas-shirtless.com")) { "content" }

refute @rendered_content.end_with?("\n")
end

def test_renders_as_a_link
render_inline(Primer::LinkComponent.new(href: "http://google.com")) { "content" }

Expand Down