Skip to content

Commit 263b185

Browse files
TylerJDevCopilot
andauthored
Fix tooltip in AvatarStack (primer#3676)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2da25b2 commit 263b185

5 files changed

Lines changed: 31 additions & 9 deletions

File tree

.changeset/blue-phones-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': minor
3+
---
4+
5+
Utilize modern `Tooltip` component for `AvatarStack`

app/components/primer/beta/avatar_stack.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
<%= avatar %>
88
<% end %>
99
<% end %>
10+
<% if @tooltipped %>
11+
<%= render Primer::Alpha::Tooltip.new(**@tooltip_arguments) %>
12+
<% end %>
1013
<% end %>

app/components/primer/beta/avatar_stack.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, body_a
3131
@system_arguments = system_arguments
3232
@tooltipped = tooltipped
3333
@body_arguments = body_arguments
34+
@direction = @body_arguments[:direction]
3435

3536
body_tag = @body_arguments[:tag] || DEFAULT_BODY_TAG
3637
@body_arguments[:tag] = fetch_or_fallback(BODY_TAG_OPTIONS, body_tag, DEFAULT_BODY_TAG)
@@ -45,14 +46,27 @@ def initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, body_a
4546
system_arguments[:classes],
4647
"AvatarStack--right" => @align == :right
4748
)
49+
50+
@body_arguments[:tabindex] = tooltipped ? 0 : nil
51+
@body_arguments[:id] = tooltipped ? @body_arguments[:id] ||= self.class.generate_id : @body_arguments[:id]
52+
53+
@tooltip_arguments = {
54+
for_id: @body_arguments[:id],
55+
}
56+
57+
@tooltip_arguments[:direction] = @direction || Primer::Alpha::Tooltip::DIRECTION_DEFAULT
58+
@tooltip_arguments[:text] = @body_arguments[:label]
59+
@tooltip_arguments[:type] = :description
60+
61+
@body_arguments[:aria] ||= {}
62+
if tooltipped && @body_arguments[:label].present?
63+
@body_arguments[:aria][:label] = @body_arguments[:label]
64+
@body_arguments[:label] = nil
65+
end
4866
end
4967

5068
def body_component
51-
if @tooltipped
52-
Primer::Tooltip.new(**@body_arguments) # rubocop:disable Primer/ComponentNameMigration
53-
else
54-
Primer::BaseComponent.new(**@body_arguments)
55-
end
69+
Primer::BaseComponent.new(**@body_arguments)
5670
end
5771

5872
def before_render

previews/primer/beta/avatar_stack_preview.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ def align_right
9292
# @label With tooltip
9393
def with_tooltip
9494
render(Primer::Beta::AvatarStack.new(tooltipped: true, body_arguments: { label: "This is a tooltip!" })) do |component|
95-
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser")
96-
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser")
97-
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser")
95+
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser", href: "primer.style")
96+
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser", href: "primer.style")
97+
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser", href: "primer.style")
9898
end
9999
end
100100
#

test/components/beta/avatar_stack_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_renders_tooltipped_body
6363
end
6464

6565
assert_selector(".AvatarStack") do
66-
assert_selector("div[aria-label=\"Tooltip\"].AvatarStack-body.tooltipped") do
66+
assert_selector("div[aria-label=\"Tooltip\"]") do
6767
assert_selector("img.avatar", count: 1)
6868
end
6969
end

0 commit comments

Comments
 (0)