Skip to content

Commit

Permalink
Fixing whitespace in rendered LinkComponent (#1274)
Browse files Browse the repository at this point in the history
* Fixing whitespace in rendered link

* Create brave-planets-reply.md
  • Loading branch information
jonrohan authored Aug 4, 2022
1 parent f38517a commit c153f73
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-planets-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": patch
---

Fixing whitespace in rendered LinkComponent
12 changes: 0 additions & 12 deletions app/components/primer/link_component.html.erb

This file was deleted.

14 changes: 14 additions & 0 deletions app/components/primer/link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,19 @@ 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
if tooltip.present?
render Primer::BaseComponent.new(tag: :span, position: :relative) do
render(Primer::BaseComponent.new(**@system_arguments)) do
content
end.to_s + tooltip.to_s
end
else
render(Primer::BaseComponent.new(**@system_arguments)) do
content
end
end
end
end
end
13 changes: 11 additions & 2 deletions test/components/link_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def test_renders_content_and_not_muted_link
end

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

assert_text(/^content$/)
assert_match(%r{^<a[^>]+>content</a>$}, result.to_s)
end

def test_renders_without_trailing_newline
Expand Down Expand Up @@ -83,4 +83,13 @@ def test_raises_if_a_tag_and_href_nil
def test_status
assert_component_state(Primer::LinkComponent, :beta)
end

def test_renders_with_tooltip_sibling
render_inline(Primer::LinkComponent.new(id: "1", href: "http://google.com")) do |c|
c.tooltip(text: "Tooltip text")
"content"
end

assert_selector("a[href='http://google.com'] + tool-tip", text: "Tooltip text", visible: false)
end
end

0 comments on commit c153f73

Please sign in to comment.