Skip to content

Commit fce2657

Browse files
authored
[Bug Fix] Constrain Tooltip content width (#384)
* [Bug Fix] Constrain Tooltip content width (#180) * docs(tooltip): add long content wrap example
1 parent 7f74bb1 commit fce2657

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

docs/app/views/docs/tooltip.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ def view_template
2424
RUBY
2525
end
2626

27+
render Docs::VisualCodeExample.new(title: "Long content", context: self) do
28+
<<~RUBY
29+
Tooltip do
30+
TooltipTrigger do
31+
Button(variant: :outline) { "Hover me" }
32+
end
33+
TooltipContent do
34+
Text { "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." }
35+
end
36+
end
37+
RUBY
38+
end
39+
2740
render Components::ComponentSetup::Tabs.new(component_name: component)
2841

2942
render Docs::ComponentsTable.new(component_files(component))

gem/lib/ruby_ui/tooltip/tooltip_content.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def default_attrs
1919
data: {
2020
ruby_ui__tooltip_target: "content"
2121
},
22-
class: "invisible peer-hover:visible peer-focus:visible w-max absolute top-0 left-0 z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md peer-focus:zoom-in-95 animate-out fade-out-0 zoom-out-95 peer-hover:animate-in peer-focus:animate-in peer-hover:fade-in-0 peer-focus:fade-in-0 peer-hover:zoom-in-95 group-data-[ruby-ui--tooltip-placement-value=bottom]:slide-in-from-top-2 group-data-[ruby-ui--tooltip-placement-value=left]:slide-in-from-right-2 group-data-[ruby-ui--tooltip-placement-value=right]:slide-in-from-left-2 group-data-[ruby-ui--tooltip-placement-value=top]:slide-in-from-bottom-2 delay-500"
22+
class: "invisible peer-hover:visible peer-focus:visible w-fit max-w-[calc(100vw-2rem)] text-balance break-words absolute top-0 left-0 z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md peer-focus:zoom-in-95 animate-out fade-out-0 zoom-out-95 peer-hover:animate-in peer-focus:animate-in peer-hover:fade-in-0 peer-focus:fade-in-0 peer-hover:zoom-in-95 group-data-[ruby-ui--tooltip-placement-value=bottom]:slide-in-from-top-2 group-data-[ruby-ui--tooltip-placement-value=left]:slide-in-from-right-2 group-data-[ruby-ui--tooltip-placement-value=right]:slide-in-from-left-2 group-data-[ruby-ui--tooltip-placement-value=top]:slide-in-from-bottom-2 delay-500"
2323
}
2424
end
2525
end

gem/lib/ruby_ui/tooltip/tooltip_docs.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ def view_template
2424
RUBY
2525
end
2626

27+
render Docs::VisualCodeExample.new(title: "Long content", context: self) do
28+
<<~RUBY
29+
Tooltip do
30+
TooltipTrigger do
31+
Button(variant: :outline) { "Hover me" }
32+
end
33+
TooltipContent do
34+
Text { "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." }
35+
end
36+
end
37+
RUBY
38+
end
39+
2740
render Components::ComponentSetup::Tabs.new(component_name: component)
2841

2942
render Docs::ComponentsTable.new(component_files(component))

gem/test/ruby_ui/tooltip_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,14 @@ def test_render_with_all_items
1717

1818
assert_match(/Add to library/, output)
1919
end
20+
21+
def test_tooltip_content_wraps_long_text_within_viewport
22+
output = phlex do
23+
RubyUI.TooltipContent { "Long tooltip content" }
24+
end
25+
26+
assert_match(/w-fit/, output)
27+
assert_match(/max-w-\[calc\(100vw-2rem\)\]/, output)
28+
assert_match(/break-words/, output)
29+
end
2030
end

0 commit comments

Comments
 (0)