Skip to content

Commit

Permalink
Add additional span inside the link to be able to limit the underline…
Browse files Browse the repository at this point in the history
… effect to the actual text instead of overflowing into the white space between text and leading/trailing icons
  • Loading branch information
HDinger committed Aug 30, 2024
1 parent 8a63255 commit 80b0d8b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
14 changes: 6 additions & 8 deletions app/components/primer/beta/link.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<%= render Primer::ConditionalWrapper.new(condition: tooltip?, trim: true, tag: :span, position: :relative) do %>
<%= render(Primer::BaseComponent.new(trim: true, **@system_arguments)) do %>
<% if leading_visual %>
<span>
<%= render(Primer::BaseComponent.new(tag: :span, classes: "Link-content", trim: true)) do %>
<% if leading_visual %>
<%= leading_visual %>
</span>
<% end %>
<%= content %>
<% if trailing_visual %>
<span>
<% end %>
<%= content %>
<% if trailing_visual %>
<%= trailing_visual %>
</span>
<% end %>
<% end %>
<% end %>
<%= tooltip if tooltip? %>
Expand Down
7 changes: 7 additions & 0 deletions app/components/primer/beta/link.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@
color: inherit !important;
}
}

.Link-content {
display: inline-flex;
align-items: center;
gap: var(--base-size-4);
text-decoration: inherit;
}
6 changes: 3 additions & 3 deletions test/components/beta/link_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_renders_content_and_not_muted_link
def test_renders_no_additional_whitespace
result = render_inline(Primer::Beta::Link.new(href: "http://joe-jonas-shirtless.com")) { "content" }

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

def test_renders_without_trailing_newline
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_renders_trailing_visual_icon
end

assert_selector("a[href='http://google.com']")
assert_selector("a span:first-child .octicon-plus")
assert_selector("a span:nth-child(2) .octicon-alert")
assert_selector("a svg:first-child.octicon-plus")
assert_selector("a svg:nth-child(2).octicon-alert")
end
end

0 comments on commit 80b0d8b

Please sign in to comment.