Apply given custom AvatarComponent classes to the link if present
MODIFY
app/components/primer/avatar_component.rb
app/components/primer/avatar_component.rb
@@ -34,29 +34,21 @@ module Primer
@system_arguments[:height] = size
@system_arguments[:width] = size
- avatar_class_names = class_names(
+ @classes = class_names(
+ system_arguments.delete(:classes),
"avatar",
"avatar--small" => size < SMALL_THRESHOLD,
"circle" => !square
)
-
- if @href
- @link_arguments = { href: href, classes: avatar_class_names }
- else
- @system_arguments[:classes] = class_names(
- system_arguments[:classes],
- avatar_class_names
- )
- end
end
def call
if @href
- render(Primer::LinkComponent.new(**@link_arguments)) do
+ render(Primer::LinkComponent.new(classes: @classes, href: @href)) do
render(Primer::BaseComponent.new(**@system_arguments)) { content }
end
else
- render(Primer::BaseComponent.new(**@system_arguments)) { content }
+ render(Primer::BaseComponent.new(classes: @classes, **@system_arguments)) { content }
end
end
end

MODIFY
test/components/avatar_component_test.rb
test/components/avatar_component_test.rb
@@ -94,6 +94,15 @@ class PrimerAvatarComponentTest < Minitest::Test
refute_selector(".avatar--small")
end
+ def test_adds_custom_classes_to_link_wrapper
+ render_inline(Primer::AvatarComponent.new(src: "https://github.com/github.png", alt: "github", href: "#", classes: "custom-class"))
+
+ assert_selector("a.avatar.custom-class") do
+ assert_selector("img")
+ end
+ refute_selector("img.custom-class")
+ end
+
def test_status
assert_component_state(Primer::AvatarComponent, :beta)
end

Apply given custom AvatarComponent classes to the link if present