Skip to content

Commit 2b0a7bf

Browse files
authored
[Bug] Fix issue where tooltip is only not shown for first item in navlist when not truncated (#2729)
Co-authored-by: thesnowrose <[email protected]>
1 parent e77a77a commit 2b0a7bf

File tree

10 files changed

+47
-15
lines changed

10 files changed

+47
-15
lines changed

.changeset/healthy-colts-jog.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+
Fixes a bug where a tooltip was being shown in the navlist even when the text wasn't truncated for certain items.

app/components/primer/alpha/action_list.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ export class ActionListTruncationObserver {
2121
}
2222

2323
update(el: HTMLElement) {
24-
const label = el.querySelector('.ActionListItem-label')
25-
if (!label) return
24+
const items = el.querySelectorAll('li')
2625

27-
const tooltip = el.querySelector('.ActionListItem-truncationTooltip') as HTMLElement | null
28-
if (!tooltip) return
26+
for (const item of items) {
27+
const label = item.querySelector('.ActionListItem-label') as HTMLElement
28+
if (!label) continue
29+
const tooltip = item.querySelector('.ActionListItem-truncationTooltip') as HTMLElement
30+
if (!tooltip) continue
2931

30-
const isTruncated = label.scrollWidth > label.clientWidth
32+
const isTruncated = label.scrollWidth > label.clientWidth
3133

32-
if (isTruncated) {
33-
tooltip.style.display = ''
34-
} else {
35-
tooltip.style.display = 'none'
34+
if (isTruncated) {
35+
tooltip.style.display = ''
36+
} else {
37+
tooltip.style.display = 'none'
38+
}
3639
}
3740
}
3841
}

app/components/primer/alpha/action_list/item.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def before_render
303303
)
304304

305305
if @truncate_label == :show_tooltip && !tooltip?
306-
with_tooltip(text: @label)
306+
with_tooltip(text: @label, direction: :ne)
307307
end
308308

309309
return unless leading_visual

previews/primer/alpha/action_list_preview.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,18 @@ def long_label_with_tooltip(truncate_label: :show_tooltip)
470470
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
471471
truncate_label: truncate_label
472472
)
473+
component.with_item(
474+
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
475+
truncate_label: truncate_label
476+
)
477+
component.with_item(
478+
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
479+
truncate_label: truncate_label
480+
)
481+
component.with_item(
482+
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
483+
truncate_label: truncate_label
484+
)
473485
end
474486
end
475487

@@ -499,8 +511,14 @@ def long_label_show_tooltip_with_truncate_label(truncate_label: :none)
499511
) do |item|
500512
item.with_tooltip(text: "this is a tooltip")
501513
end
514+
component.with_item(
515+
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
516+
truncate_label: truncate_label
517+
) do |item|
518+
item.with_tooltip(text: "this is a tooltip")
519+
end
502520
end
503521
end
504522
end
505523
end
506-
end
524+
end

previews/primer/beta/nav_list_preview.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,15 @@ def long_label_with_tooltip(truncate_label: :show_tooltip)
139139
component.with_item(
140140
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
141141
truncate_label: truncate_label
142-
) do |item|
143-
item.with_trailing_visual_icon(icon: :plus)
144-
end
142+
)
143+
component.with_item(
144+
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
145+
truncate_label: truncate_label
146+
)
147+
component.with_item(
148+
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
149+
truncate_label: truncate_label
150+
)
145151
end
146152
end
147153

test/system/alpha/action_list_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_js_truncate_label_shows_tooltip
1313
assert_selector "li.ActionListItem span.ActionListItem-label--truncate"
1414
assert_selector "tool-tip", text: "Really really long label that may wrap, truncate, or appear as a tooltip", visible: :hidden
1515

16-
find("button").send_keys("tab") # sends focus to button
16+
first("button").send_keys("tab") # sends focus to button
1717
assert_selector "tool-tip", text: "Really really long label that may wrap, truncate, or appear as a tooltip", visible: :visible
1818
end
1919

0 commit comments

Comments
 (0)