Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix issue where tooltip is only not shown for first item in navlist when not truncated #2729

Merged
merged 7 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 17 additions & 12 deletions app/components/primer/alpha/action_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@ export class ActionListTruncationObserver {
}

update(el: HTMLElement) {
const label = el.querySelector('.ActionListItem-label')
if (!label) return

const tooltip = el.querySelector('.ActionListItem-truncationTooltip') as HTMLElement | null
if (!tooltip) return

const isTruncated = label.scrollWidth > label.clientWidth

if (isTruncated) {
tooltip.style.display = ''
} else {
tooltip.style.display = 'none'
const items = el.querySelectorAll('li')
const labels = el.querySelectorAll('.ActionListItem-label')
const tooltips = el.querySelectorAll('.ActionListItem-truncationTooltip')

for (let i = 0; i < items.length; i++) {
const label = labels[i] as HTMLElement
if (!label) return
const tooltip = tooltips[i] as HTMLElement
if (!tooltip) return

const isTruncated = label.scrollWidth > label.clientWidth

if (isTruncated) {
tooltip.style.display = ''
} else {
tooltip.style.display = 'none'
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/primer/alpha/action_list/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def before_render
)

if @truncate_label == :show_tooltip && !tooltip?
with_tooltip(text: @label)
with_tooltip(text: @label, direction: :ne)
end

return unless leading_visual
Expand Down
20 changes: 19 additions & 1 deletion previews/primer/alpha/action_list_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,18 @@ def long_label_with_tooltip(truncate_label: :show_tooltip)
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
truncate_label: truncate_label
)
component.with_item(
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
truncate_label: truncate_label
)
component.with_item(
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
truncate_label: truncate_label
)
component.with_item(
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
truncate_label: truncate_label
)
end
end

Expand Down Expand Up @@ -499,8 +511,14 @@ def long_label_show_tooltip_with_truncate_label(truncate_label: :none)
) do |item|
item.with_tooltip(text: "this is a tooltip")
end
component.with_item(
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
truncate_label: truncate_label
) do |item|
item.with_tooltip(text: "this is a tooltip")
end
end
end
end
end
end
end
12 changes: 9 additions & 3 deletions previews/primer/beta/nav_list_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,15 @@ def long_label_with_tooltip(truncate_label: :show_tooltip)
component.with_item(
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
truncate_label: truncate_label
) do |item|
item.with_trailing_visual_icon(icon: :plus)
end
)
component.with_item(
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
truncate_label: truncate_label
)
component.with_item(
label: "Really really long label that may wrap, truncate, or appear as a tooltip",
truncate_label: truncate_label
)
end
end

Expand Down