Skip to content

Commit 0e79214

Browse files
fix: constrain Tooltip popup width to available viewport space (#530)
1 parent 4f2b47c commit 0e79214

4 files changed

Lines changed: 57 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/kumo": patch
3+
---
4+
5+
Fix Tooltip popup overflowing viewport when content is wider than available space. The popup now constrains its width to `var(--available-width)`, a CSS variable provided by Base UI's Positioner that reflects the space between the trigger and the viewport edge.

packages/kumo-docs-astro/src/components/demos/TooltipDemo.tsx

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Tooltip, TooltipProvider, Button } from "@cloudflare/kumo";
2-
import { Info, PlusIcon, TranslateIcon } from "@phosphor-icons/react";
1+
import { Tooltip, TooltipProvider, Button } from '@cloudflare/kumo';
2+
import { Info, PlusIcon, TranslateIcon } from '@phosphor-icons/react';
33

44
export function TooltipHeroDemo() {
55
return (
@@ -71,6 +71,43 @@ export function TooltipCustomTriggerDemo() {
7171
* Control the delay before opening and closing the tooltip.
7272
* `delay` controls open delay (default: 600ms), `closeDelay` controls close delay (default: 0ms).
7373
*/
74+
/**
75+
* Demonstrates that long tooltip content respects available viewport space.
76+
* Tooltips near the edge of the viewport constrain their width to
77+
* `--available-width` so they don't overflow.
78+
*/
79+
export function TooltipOverflowDemo() {
80+
const longContent =
81+
'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.';
82+
return (
83+
<TooltipProvider>
84+
<div className="flex w-full justify-between">
85+
<Tooltip
86+
content={longContent}
87+
side="bottom"
88+
render={<Button variant="secondary" />}
89+
>
90+
Near left edge
91+
</Tooltip>
92+
<Tooltip
93+
content={longContent}
94+
side="bottom"
95+
render={<Button variant="secondary" />}
96+
>
97+
Centered
98+
</Tooltip>
99+
<Tooltip
100+
content={longContent}
101+
side="bottom"
102+
render={<Button variant="secondary" />}
103+
>
104+
Near right edge
105+
</Tooltip>
106+
</div>
107+
</TooltipProvider>
108+
);
109+
}
110+
74111
export function TooltipDelayDemo() {
75112
return (
76113
<TooltipProvider>

packages/kumo-docs-astro/src/pages/components/tooltip.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
TooltipBasicDemo,
1515
TooltipMultipleDemo,
1616
TooltipDelayDemo,
17+
TooltipOverflowDemo,
1718
} from "~/components/demos/TooltipDemo";
1819

1920
{/* Hero Demo */}
@@ -84,6 +85,17 @@ For delay grouping across multiple tooltips, see [TooltipProvider](#tooltipprovi
8485
<TooltipMultipleDemo client:load />
8586
</ComponentExample>
8687

88+
### Long Content / Overflow
89+
90+
<p>
91+
Tooltips with long content automatically constrain their width to the available
92+
viewport space using `--available-width` from Base UI's Positioner. Hover over
93+
the edge buttons to see the tooltip wrap instead of overflowing the viewport.
94+
</p>
95+
<ComponentExample demo="TooltipOverflowDemo">
96+
<TooltipOverflowDemo client:load />
97+
</ComponentExample>
98+
8799
### Delay Control
88100

89101
<p>

packages/kumo/src/components/tooltip/tooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function Tooltip({
183183
{asChild ? undefined : (children as ReactNode)}
184184
</TooltipBase.Trigger>
185185
<TooltipBase.Portal container={container}>
186-
<TooltipBase.Positioner align={align} side={side} sideOffset={10}>
186+
<TooltipBase.Positioner align={align} side={side} sideOffset={10} className="max-w-[var(--available-width)]">
187187
<TooltipBase.Popup
188188
className={cn(
189189
"flex origin-[var(--transform-origin)] flex-col rounded-md bg-kumo-base px-2.5 py-1.5 text-sm text-kumo-default",

0 commit comments

Comments
 (0)