Skip to content

The open alternative to Salesforce, designed for AI.

Unify Tooltip width defaults (#28298)

Raphaël Bosi86a1c0f10e45
diff --git a/packages/twenty-docs/snippets/ui/generated/surfaces/tooltip.mdx b/packages/twenty-docs/snippets/ui/generated/surfaces/tooltip.mdx
index be49f618699..16c6736b36d 100644
--- a/packages/twenty-docs/snippets/ui/generated/surfaces/tooltip.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/surfaces/tooltip.mdx
@@ -137,7 +137,7 @@
</ParamField>
<ParamField body="maxWidth" type="MaxWidth&lt;string | number&gt;">
- Maximum popup width. Defaults to 300 pixels.
+ Maximum popup width. Defaults to 300 pixels and is capped by the space available beside the anchor.
</ParamField>
<ParamField body="onOpenChange" type="((open: boolean, eventDetails: TooltipRootChangeEventDetails) =&gt; void)">
@@ -157,7 +157,7 @@
</ParamField>
<ParamField body="positionerProps" type="TooltipPositionerProps">
- Full Positioner props, including native props, ref and render. Overrides shorthand placement and width defaults.
+ Full Positioner props, including native props, ref and render. Overrides shorthand placement defaults.
</ParamField>
<ParamField body="positionMethod" type="&quot;absolute&quot; | &quot;fixed&quot;" default="absolute">
@@ -467,7 +467,7 @@
</ParamField>
<ParamField body="Popup.maxWidth" type="MaxWidth&lt;string | number&gt;">
- Maximum popup width, still capped by the space available beside the anchor.
+ Maximum popup width. Defaults to 300 pixels and is capped by the space available beside the anchor.
</ParamField>
<ParamField body="Popup.ref" type="Ref&lt;HTMLDivElement&gt;">
diff --git a/packages/twenty-docs/ui/primitives/surfaces/tooltip.mdx b/packages/twenty-docs/ui/primitives/surfaces/tooltip.mdx
index f07042af073..374ec12f0df 100644
--- a/packages/twenty-docs/ui/primitives/surfaces/tooltip.mdx
+++ b/packages/twenty-docs/ui/primitives/surfaces/tooltip.mdx
@@ -130,7 +130,7 @@ Every DOM part accepts native props, refs, and element or callback `render` comp
Replace `content={<Tooltip.Content description={description} startIcon={icon}>title</Tooltip.Content>}` with `content={title} description={description} startIcon={icon}`. In compound usage, compose title and description nodes directly. `Tooltip.Content` and `TooltipContentProps` are removed.
-Existing compound Popup positioning props move to Positioner. Wrap it in Portal, move `container` and `keepMounted` to Portal, replace `maxWidth` with Positioner `style`, and replace `arrow` with an Arrow child. Preserve the former assembly defaults explicitly with `sideOffset={10}` and `style={{ maxWidth: '300px' }}` when needed. Compound Positioner keeps Base UI's `sideOffset={0}` and does not impose a maximum width.
+Existing compound Popup positioning props move to Positioner. Wrap it in Portal, move `container` and `keepMounted` to Portal, keep `maxWidth` on Popup, and replace `arrow` with an Arrow child. Preserve the former spacing explicitly with `sideOffset={10}` when needed. Compound Positioner keeps Base UI's `sideOffset={0}`. Both forms cap Popup at 300 pixels by default.
## Disabled controls
@@ -153,7 +153,7 @@ Setting `disabled` on shorthand or Root suppresses the tooltip itself. Trigger `
## Placement and overflowing text
-Shorthand defaults to `side="top"`, `align="center"`, `sideOffset={10}`, and a maximum width of `300` pixels. Placement adjusts to available space. An open tooltip hides while its anchor is scrolled out of view, including out of a scroll container. Use `arrow` for an arrow and `container` to override the theme's portal destination; see [theming](/ui/theming).
+Shorthand defaults to `side="top"`, `align="center"`, and `sideOffset={10}`. Both shorthand and compound tooltips have a maximum width of 300 pixels, capped by the available space beside the anchor. Pass `maxWidth` to shorthand or `Tooltip.Popup` to choose a different maximum, including wider previews. Native popup styles remain available for custom sizing. Placement adjusts to available space. An open tooltip hides while its anchor is scrolled out of view, including out of a scroll container. Use `arrow` for an arrow and `container` to override the theme's portal destination; see [theming](/ui/theming).
Use [OverflowingTextWithTooltip](/ui/primitives/typography/overflowing-text-with-tooltip) when a text label should show its full value only when truncated. Its existing `text`, `tooltipContent`, and `tooltipPlace` props remain available.
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-tooltip.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-tooltip.front-component.tsx
index 50d2fcc637a..e230f17d61f 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-tooltip.front-component.tsx
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-tooltip.front-component.tsx
@@ -34,7 +34,7 @@ const TooltipExample = () => {
<Button>Export details</Button>
</Tooltip.Trigger>
<Tooltip.Portal>
- <Tooltip.Positioner sideOffset={10} style={{ maxWidth: '300px' }}>
+ <Tooltip.Positioner sideOffset={10}>
<Tooltip.Popup>
<Tooltip.Arrow />
<Tooltip.Viewport>
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/components/FieldDescriptionTooltipProvider.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/components/FieldDescriptionTooltipProvider.tsx
index 47fd9b3e0c8..d6aca10371b 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/components/FieldDescriptionTooltipProvider.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/components/FieldDescriptionTooltipProvider.tsx
@@ -53,7 +53,7 @@ export const FieldDescriptionTooltipProvider = ({
positionMethod="fixed"
sideOffset={10}
>
- <Tooltip.Popup maxWidth={300}>
+ <Tooltip.Popup>
<TooltipTextContent description={payload?.description}>
{payload?.title}
</TooltipTextContent>
diff --git a/packages/twenty-front/src/modules/object-record/record-list/components/RecordListFieldTooltip.tsx b/packages/twenty-front/src/modules/object-record/record-list/components/RecordListFieldTooltip.tsx
index a0b343f99ae..237f3ba261a 100644
--- a/packages/twenty-front/src/modules/object-record/record-list/components/RecordListFieldTooltip.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-list/components/RecordListFieldTooltip.tsx
@@ -35,7 +35,7 @@ export const RecordListFieldTooltip = ({
positionMethod="fixed"
sideOffset={10}
>
- <Tooltip.Popup maxWidth={300}>
+ <Tooltip.Popup>
<TooltipTextContent
startIcon={isDefined(FieldIcon) ? <FieldIcon /> : undefined}
>
diff --git a/packages/twenty-front/src/modules/onboarding/components/free-credits/OnboardingFreeCreditsPill.tsx b/packages/twenty-front/src/modules/onboarding/components/free-credits/OnboardingFreeCreditsPill.tsx
index 6b12ec7de57..05af0b35d3b 100644
--- a/packages/twenty-front/src/modules/onboarding/components/free-credits/OnboardingFreeCreditsPill.tsx
+++ b/packages/twenty-front/src/modules/onboarding/components/free-credits/OnboardingFreeCreditsPill.tsx
@@ -269,7 +269,7 @@ export const OnboardingFreeCreditsPill = ({
align="end"
sideOffset={10}
>
- <Tooltip.Popup maxWidth={300} withExitAnimation>
+ <Tooltip.Popup withExitAnimation>
<StyledTooltipContents>
<AnimatePresence initial={false}>
{isDefined(tooltipContent) && (
diff --git a/packages/twenty-ui/docs/tooltipPartPropDescriptions.ts b/packages/twenty-ui/docs/tooltipPartPropDescriptions.ts
index 01ffee129b4..5a33c0f3dcb 100644
--- a/packages/twenty-ui/docs/tooltipPartPropDescriptions.ts
+++ b/packages/twenty-ui/docs/tooltipPartPropDescriptions.ts
@@ -30,7 +30,7 @@ export const TOOLTIP_PART_PROP_DESCRIPTIONS = {
ref: 'Ref to the popup div. Native props, styles and render target this element.',
withExitAnimation: 'Enables the optional Twenty exit transition.',
maxWidth:
- 'Maximum popup width, still capped by the space available beside the anchor.',
+ 'Maximum popup width. Defaults to 300 pixels and is capped by the space available beside the anchor.',
},
Arrow: {
ref: 'Ref to the arrow div. Compose inside Popup.',
diff --git a/packages/twenty-ui/docs/tooltipPropDescriptions.ts b/packages/twenty-ui/docs/tooltipPropDescriptions.ts
index c73abb40a31..4e8cbaf9b4a 100644
--- a/packages/twenty-ui/docs/tooltipPropDescriptions.ts
+++ b/packages/twenty-ui/docs/tooltipPropDescriptions.ts
@@ -9,7 +9,7 @@ export const TOOLTIP_PROP_DESCRIPTIONS = {
triggerProps:
'Full Trigger props, including native props, ref, render and payload. Overrides the shorthand trigger defaults.',
positionerProps:
- 'Full Positioner props, including native props, ref and render. Overrides shorthand placement and width defaults.',
+ 'Full Positioner props, including native props, ref and render. Overrides shorthand placement defaults.',
portalProps:
'Full Portal props, including native props, ref and render. Overrides shorthand portal defaults.',
arrowPadding: 'Minimum distance from the arrow to the popup edges.',
@@ -23,7 +23,8 @@ export const TOOLTIP_PROP_DESCRIPTIONS = {
arrow: 'Displays an arrow pointing to the trigger. Defaults to false.',
withExitAnimation:
'Fades and slides the popup out when it closes instead of hiding it at once.',
- maxWidth: 'Maximum popup width. Defaults to 300 pixels.',
+ maxWidth:
+ 'Maximum popup width. Defaults to 300 pixels and is capped by the space available beside the anchor.',
positionMethod: 'CSS positioning method for the popup.',
open: 'Controlled visibility of the tooltip.',
defaultOpen: 'Initial visibility when the tooltip manages its own state.',
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index dcb82bd2b58..d48f599fde7 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -9861,7 +9861,7 @@
"type": "MaxWidth<string | number>",
"required": false,
"defaultValue": null,
- "description": "Maximum popup width. Defaults to 300 pixels."
+ "description": "Maximum popup width. Defaults to 300 pixels and is capped by the space available beside the anchor."
},
{
"name": "onOpenChange",
@@ -9896,7 +9896,7 @@
"type": "TooltipPositionerProps",
"required": false,
"defaultValue": null,
- "description": "Full Positioner props, including native props, ref and render. Overrides shorthand placement and width defaults."
+ "description": "Full Positioner props, including native props, ref and render. Overrides shorthand placement defaults."
},
{
"name": "positionMethod",
@@ -10334,7 +10334,7 @@
"type": "MaxWidth<string | number>",
"required": false,
"defaultValue": null,
- "description": "Maximum popup width, still capped by the space available beside the anchor."
+ "description": "Maximum popup width. Defaults to 300 pixels and is capped by the space available beside the anchor."
},
{
"name": "ref",
diff --git a/packages/twenty-ui/src/primitives/surfaces/Tooltip/Tooltip.module.scss b/packages/twenty-ui/src/primitives/surfaces/Tooltip/Tooltip.module.scss
index 68ecc5d7758..b68c48ee82c 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Tooltip/Tooltip.module.scss
+++ b/packages/twenty-ui/src/primitives/surfaces/Tooltip/Tooltip.module.scss
@@ -20,7 +20,7 @@
word-break: break-word;
inline-size: max-content;
max-inline-size: min(
- var(--tw-tooltip-max-width, var(--available-width)),
+ var(--tw-tooltip-max-width, 300px),
var(--available-width)
);
will-change: opacity;
diff --git a/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/Tooltip.stories.tsx b/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/Tooltip.stories.tsx
index 9d12bded9c4..2e46d752788 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/Tooltip.stories.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/Tooltip.stories.tsx
@@ -6,6 +6,7 @@ import { IconInfoCircle } from '@ui/icon';
import { Button } from '@ui/primitives/input/Button/Button';
import { Text } from '@ui/primitives/typography/Text/Text';
import { ComponentDecorator } from '@ui/testing';
+import { isDefined } from '@ui/utilities/utils/isDefined';
import { Tooltip } from '../Tooltip';
import styles from './Tooltip.stories.module.scss';
@@ -181,7 +182,7 @@ export const SharedPopup: Story = {
<Button>Second field</Button>
</Tooltip.Trigger>
<Tooltip.Portal>
- <Tooltip.Positioner sideOffset={10} style={{ maxWidth: '300px' }}>
+ <Tooltip.Positioner sideOffset={10}>
<Tooltip.Popup>{payload}</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
@@ -532,3 +533,108 @@ export const ProviderDelays: Story = {
);
},
};
+
+const WIDTH_EXAMPLES = [
+ { name: 'Shorthand default', compound: false, expectedWidth: 300 },
+ { name: 'Compound default', compound: true, expectedWidth: 300 },
+ {
+ name: 'Shorthand narrow number',
+ compound: false,
+ maxWidth: 180,
+ expectedWidth: 180,
+ },
+ {
+ name: 'Compound narrow string',
+ compound: true,
+ maxWidth: '200px',
+ expectedWidth: 200,
+ },
+ {
+ name: 'Shorthand wider string',
+ compound: false,
+ maxWidth: '360px',
+ expectedWidth: 360,
+ },
+ {
+ name: 'Compound wider number',
+ compound: true,
+ maxWidth: 420,
+ expectedWidth: 420,
+ },
+ { name: 'Viewport clamp', compound: true, maxWidth: 10000 },
+];
+const WIDTH_EXAMPLE_CONTENT =
+ 'Export all visible records with their related companies and current workspace filters. '.repeat(
+ 12,
+ );
+
+export const SharedWidth: Story = {
+ tags: ['!autodocs'],
+ render: () => (
+ <Text
+ render={<div />}
+ style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}
+ >
+ {WIDTH_EXAMPLES.map(({ name, compound, maxWidth }) =>
+ compound ? (
+ <Tooltip.Root key={name}>
+ <Tooltip.Trigger render={<Button>{name}</Button>} delay={0} />
+ <Tooltip.Portal>
+ <Tooltip.Positioner side="bottom" sideOffset={10}>
+ <Tooltip.Popup maxWidth={maxWidth}>
+ {WIDTH_EXAMPLE_CONTENT}
+ </Tooltip.Popup>
+ </Tooltip.Positioner>
+ </Tooltip.Portal>
+ </Tooltip.Root>
+ ) : (
+ <Tooltip
+ key={name}
+ content={WIDTH_EXAMPLE_CONTENT}
+ maxWidth={maxWidth}
+ delay={0}
+ side="bottom"
+ >
+ <Button>{name}</Button>
+ </Tooltip>
+ ),
+ )}
+ </Text>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const ownerDocument = canvasElement.ownerDocument;
+
+ for (const { name, expectedWidth } of WIDTH_EXAMPLES) {
+ await userEvent.hover(canvas.getByRole('button', { name }));
+ const tooltip = await findTooltip(canvasElement);
+
+ await waitFor(() => {
+ const popupBounds = tooltip.getBoundingClientRect();
+ const viewportWidth = ownerDocument.documentElement.clientWidth;
+
+ if (isDefined(expectedWidth)) {
+ expect(popupBounds.width).toBeCloseTo(expectedWidth, 0);
+ }
+
+ if (!isDefined(expectedWidth)) {
+ expect(popupBounds.width).toBeGreaterThan(420);
+ }
+
+ expect(popupBounds.left).toBeGreaterThanOrEqual(0);
+ expect(popupBounds.right).toBeLessThanOrEqual(viewportWidth);
+ expect(popupBounds.width).toBeLessThanOrEqual(viewportWidth);
+ expect(
+ tooltip.parentElement?.getBoundingClientRect().width,
+ ).toBeCloseTo(popupBounds.width, 0);
+ });
+
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(
+ within(ownerDocument.body).queryByRole('tooltip'),
+ ).not.toBeInTheDocument(),
+ );
+ }
+ },
+};
diff --git a/packages/twenty-ui/src/primitives/surfaces/Tooltip/__tests__/Tooltip.test.tsx b/packages/twenty-ui/src/primitives/surfaces/Tooltip/__tests__/Tooltip.test.tsx
index cc51bfba289..c73fc043794 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Tooltip/__tests__/Tooltip.test.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Tooltip/__tests__/Tooltip.test.tsx
@@ -178,7 +178,7 @@ describe('Tooltip interactions', () => {
<Tooltip.Root handle={handle}>
{({ payload }) => (
<Tooltip.Portal>
- <Tooltip.Positioner sideOffset={10} style={{ maxWidth: '300px' }}>
+ <Tooltip.Positioner sideOffset={10}>
<Tooltip.Popup>{payload}</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
diff --git a/packages/twenty-ui/src/primitives/surfaces/Tooltip/internal/TooltipComponent.tsx b/packages/twenty-ui/src/primitives/surfaces/Tooltip/internal/TooltipComponent.tsx
index 29b4ce964bc..c8922cebccf 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Tooltip/internal/TooltipComponent.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Tooltip/internal/TooltipComponent.tsx
@@ -13,7 +13,6 @@ import { TooltipPortal } from './TooltipPortal';
import { TooltipPositioner } from './TooltipPositioner';
const DEFAULT_SIDE_OFFSET = 10;
-const DEFAULT_MAX_WIDTH = '300px';
export const TooltipComponent = <TPayload,>({
content,
@@ -47,7 +46,7 @@ export const TooltipComponent = <TPayload,>({
arrowPadding,
disableAnchorTracking,
arrow = false,
- maxWidth = DEFAULT_MAX_WIDTH,
+ maxWidth,
container,
keepMounted,
triggerProps,
diff --git a/packages/twenty-ui/src/primitives/typography/OverflowingTextWithTooltip/OverflowingTextWithTooltip.tsx b/packages/twenty-ui/src/primitives/typography/OverflowingTextWithTooltip/OverflowingTextWithTooltip.tsx
index 50b34c382bc..8ee9cf43186 100644
--- a/packages/twenty-ui/src/primitives/typography/OverflowingTextWithTooltip/OverflowingTextWithTooltip.tsx
+++ b/packages/twenty-ui/src/primitives/typography/OverflowingTextWithTooltip/OverflowingTextWithTooltip.tsx
@@ -139,7 +139,6 @@ export const OverflowingTextWithTooltip = memo(
<Tooltip.Portal>
<Tooltip.Positioner sideOffset={5} side={tooltipPlace}>
<Tooltip.Popup
- maxWidth={300}
className={
isTooltipMultiline ? styles.multilineTooltip : undefined
}