Skip to content

The open alternative to Salesforce, designed for AI.

Expose Tooltip body composition (#28311)

Raphaël Bosif47a6931400b
diff --git a/packages/twenty-docs/snippets/ui/generated/surfaces/tooltip.mdx b/packages/twenty-docs/snippets/ui/generated/surfaces/tooltip.mdx
index 16c6736b36d..7d7f664c68e 100644
--- a/packages/twenty-docs/snippets/ui/generated/surfaces/tooltip.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/surfaces/tooltip.mdx
@@ -490,6 +490,28 @@
Enables the optional Twenty exit transition.
</ParamField>
+### Tooltip.Body
+
+<ParamField body="Body.children" type="ReactNode">
+ Optional title content, displayed with medium weight. Omit it for a description-only tooltip.
+</ParamField>
+
+<ParamField body="Body.description" type="ReactNode">
+ Optional secondary content. Preserves line breaks and wraps long text.
+</ParamField>
+
+<ParamField body="Body.ref" type="Ref&lt;HTMLDivElement&gt;">
+ Ref to the body div. Native props, styles and render target this element.
+</ParamField>
+
+<ParamField body="Body.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, {}&gt;">
+ Composes the body root through an element or render callback while preserving its layout and content.
+</ParamField>
+
+<ParamField body="Body.startIcon" type="ReactNode">
+ Optional decorative node before the title. Omitted when the title is empty.
+</ParamField>
+
### Tooltip.Arrow
<ParamField body="Arrow.className" type="string | ((state: TooltipArrowState) =&gt; string | undefined)">
diff --git a/packages/twenty-docs/ui/primitives/surfaces/tooltip.mdx b/packages/twenty-docs/ui/primitives/surfaces/tooltip.mdx
index 374ec12f0df..e15052f1f31 100644
--- a/packages/twenty-docs/ui/primitives/surfaces/tooltip.mdx
+++ b/packages/twenty-docs/ui/primitives/surfaces/tooltip.mdx
@@ -82,12 +82,11 @@ export const ExportDetails = () => (
);
```
-Compound usage exposes every installed Base UI part. Assemble the portal, positioning, popup and optional arrow explicitly. Popup renders its children as supplied.
+Compound usage exposes every installed Base UI part and the optional `Tooltip.Body` layout. Assemble the portal, positioning, popup and optional arrow explicitly. Popup renders its children as supplied; Body provides the same title, description and decorative icon layout as shorthand.
```tsx
import { Button } from 'twenty-ui/primitives/input';
import { Tooltip } from 'twenty-ui/primitives/surfaces';
-import { Text } from 'twenty-ui/primitives/typography';
export const ComposedExportDetails = () => (
<Tooltip.Provider delay={300} closeDelay={100} timeout={400}>
@@ -98,10 +97,9 @@ export const ComposedExportDetails = () => (
<Tooltip.Popup>
<Tooltip.Arrow />
<Tooltip.Viewport>
- <Text style={{ fontWeight: 500 }}>Export visible records</Text>
- <Text>
- Only records matching your current filters are included.
- </Text>
+ <Tooltip.Body description="Only records matching your current filters are included.">
+ Export visible records
+ </Tooltip.Body>
</Tooltip.Viewport>
</Tooltip.Popup>
</Tooltip.Positioner>
@@ -119,16 +117,19 @@ export const ComposedExportDetails = () => (
| `Portal` | The portal div. Defaults to the theme container, then document body. |
| `Positioner` | The positioning div. Owns anchor, physical/logical side, offsets, collision handling, sticky positioning and arrow padding. |
| `Popup` | The popup div. Owns content, native props, styles, `render` and ref. |
+| `Body` | The optional body div inside Popup or Viewport. Native props, styles, `render` and ref target its root. |
| `Arrow` | The arrow div inside Popup. |
| `Viewport` | The optional div for transitions between trigger payloads. |
+`Tooltip.Body` accepts optional title children, `description` and `startIcon` nodes. Titles use medium weight; descriptions use the secondary tooltip color, preserve line breaks and wrap long text. Omit title children for a description-only tooltip. The icon is decorative and appears only with a title. Body adds no tooltip role, popup styling, sizing or positioning. Arbitrary Popup content remains supported. Import `TooltipBodyProps` from `twenty-ui/primitives/surfaces` when typing a wrapper.
+
Every DOM part accepts native props, refs, and element or callback `render` composition. Shorthand's top-level native props, `render` and ref target Popup. Use `triggerProps`, `positionerProps` and `portalProps` to customize the other targets; these override shorthand defaults. Children supply the default trigger render element. Both forms preserve controlled/uncontrolled Root state and Base UI callback event details, including cancellation, reason, original event and active trigger.
`Tooltip.createHandle<TPayload>()` connects detached triggers to either form through `handle`. Compound Root's children or shorthand's `content` can be a function receiving the typed active payload. `Tooltip.Handle` and the public `TooltipHandle` type expose the installed handle contract. Handles support imperative `open(triggerId)` and `close()` while their Root is mounted.
## Migration
-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.
+Replace `content={<Tooltip.Content description={description} startIcon={icon}>title</Tooltip.Content>}` with `content={title} description={description} startIcon={icon}`. In compound usage, use `Tooltip.Body` for the shared title and description layout or compose your own content. `Tooltip.Content` and `TooltipContentProps` are removed.
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.
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 e230f17d61f..750d0789202 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
@@ -2,7 +2,6 @@ import { useEffect, useState } from 'react';
import { defineFrontComponent } from 'twenty-sdk/define';
import { Button } from 'twenty-ui/primitives/input';
import { Tooltip } from 'twenty-ui/primitives/surfaces';
-import { Text } from 'twenty-ui/primitives/typography';
import { ThemeProvider } from 'twenty-ui/theme';
import { TwentyUiGalleryCard } from '@/__stories__/shared/front-components/twenty-ui-gallery-card';
@@ -38,10 +37,9 @@ const TooltipExample = () => {
<Tooltip.Popup>
<Tooltip.Arrow />
<Tooltip.Viewport>
- <Text style={{ fontWeight: 500 }}>
+ <Tooltip.Body description="Your current filters are applied.">
Export visible records
- </Text>
- <Text>Your current filters are applied.</Text>
+ </Tooltip.Body>
</Tooltip.Viewport>
</Tooltip.Popup>
</Tooltip.Positioner>
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 d6aca10371b..4ad067712c6 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
@@ -1,6 +1,5 @@
import { FieldDescriptionTooltipContext } from '@/object-record/record-field/ui/contexts/FieldDescriptionTooltipContext';
import { type FieldDescriptionTooltipContent } from '@/object-record/record-field/ui/types/FieldDescriptionTooltipContent';
-import { TooltipTextContent } from '@/ui/layout/tooltip/components/TooltipTextContent';
import { type ReactNode, useRef, useState } from 'react';
import { isDefined } from 'twenty-shared/utils';
import { Tooltip } from 'twenty-ui/primitives/surfaces';
@@ -54,9 +53,9 @@ export const FieldDescriptionTooltipProvider = ({
sideOffset={10}
>
<Tooltip.Popup>
- <TooltipTextContent description={payload?.description}>
+ <Tooltip.Body description={payload?.description}>
{payload?.title}
- </TooltipTextContent>
+ </Tooltip.Body>
</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
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 237f3ba261a..61d8458f6da 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
@@ -1,5 +1,4 @@
import { useRecordIndexContextOrThrow } from '@/object-record/record-index/contexts/RecordIndexContext';
-import { TooltipTextContent } from '@/ui/layout/tooltip/components/TooltipTextContent';
import { type ReactNode } from 'react';
import { isDefined } from 'twenty-shared/utils';
import { useIcons } from 'twenty-ui/icon';
@@ -36,11 +35,11 @@ export const RecordListFieldTooltip = ({
sideOffset={10}
>
<Tooltip.Popup>
- <TooltipTextContent
+ <Tooltip.Body
startIcon={isDefined(FieldIcon) ? <FieldIcon /> : undefined}
>
{fieldDefinition?.label}
- </TooltipTextContent>
+ </Tooltip.Body>
</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
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 05af0b35d3b..19011515199 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
@@ -14,7 +14,6 @@ import { currentFocusedItemSelector } from '@/ui/utilities/focus/states/currentF
import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
-import { TooltipTextContent } from '@/ui/layout/tooltip/components/TooltipTextContent';
import { styled } from '@linaria/react';
import { plural } from '@lingui/core/macro';
import { useLingui } from '@lingui/react/macro';
@@ -280,11 +279,9 @@ export const OnboardingFreeCreditsPill = ({
exit={{ opacity: 0, y: -tooltipSlideOffset }}
transition={{ duration: theme.animation.duration.normal }}
>
- <TooltipTextContent
- description={tooltipContent.description}
- >
+ <Tooltip.Body description={tooltipContent.description}>
{tooltipContent.title}
- </TooltipTextContent>
+ </Tooltip.Body>
</StyledTooltipContent>
)}
</AnimatePresence>
diff --git a/packages/twenty-front/src/modules/ui/layout/tooltip/components/TooltipTextContent.tsx b/packages/twenty-front/src/modules/ui/layout/tooltip/components/TooltipTextContent.tsx
deleted file mode 100644
index fcac6620ef1..00000000000
--- a/packages/twenty-front/src/modules/ui/layout/tooltip/components/TooltipTextContent.tsx
+++ /dev/null
@@ -1,66 +0,0 @@
-import { styled } from '@linaria/react';
-import { type ReactNode } from 'react';
-import { isDefined } from 'twenty-shared/utils';
-import { themeCssVariables } from 'twenty-ui/theme';
-
-const StyledContent = styled.div`
- display: flex;
- flex-direction: column;
- line-height: ${themeCssVariables.spacing[4]};
-`;
-
-const StyledTitle = styled.div`
- align-items: center;
- display: flex;
- font-weight: ${themeCssVariables.font.weight.medium};
- gap: ${themeCssVariables.spacing[1]};
- min-inline-size: 0;
-
- span {
- min-inline-size: 0;
- overflow-wrap: anywhere;
- }
-`;
-
-const StyledIcon = styled.span`
- align-items: center;
- display: inline-flex;
- flex-shrink: 0;
-
- & > svg {
- block-size: calc(${themeCssVariables.icon.size.sm} * 1px);
- inline-size: calc(${themeCssVariables.icon.size.sm} * 1px);
- }
-`;
-
-const StyledDescription = styled.div`
- color: ${themeCssVariables.tooltip.descriptionColor};
- overflow-wrap: anywhere;
- white-space: pre-wrap;
-`;
-
-type TooltipTextContentProps = {
- children?: ReactNode;
- description?: ReactNode;
- startIcon?: ReactNode;
-};
-
-export const TooltipTextContent = ({
- children,
- description,
- startIcon,
-}: TooltipTextContentProps) => (
- <StyledContent>
- {isDefined(children) && children !== '' && (
- <StyledTitle>
- {isDefined(startIcon) && (
- <StyledIcon aria-hidden>{startIcon}</StyledIcon>
- )}
- <span>{children}</span>
- </StyledTitle>
- )}
- {isDefined(description) && (
- <StyledDescription>{description}</StyledDescription>
- )}
- </StyledContent>
-);
diff --git a/packages/twenty-ui/docs/components.ts b/packages/twenty-ui/docs/components.ts
index a1fb4fd64a9..56d368d89d9 100644
--- a/packages/twenty-ui/docs/components.ts
+++ b/packages/twenty-ui/docs/components.ts
@@ -695,6 +695,7 @@ export const DOCUMENTED_COMPONENTS = [
'Portal',
'Positioner',
'Popup',
+ 'Body',
'Arrow',
'Viewport',
'Provider',
diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.json
index 23fb3b4c7be..edaf90e7001 100644
--- a/packages/twenty-ui/docs/public-exports.json
+++ b/packages/twenty-ui/docs/public-exports.json
@@ -1142,6 +1142,7 @@
"TooltipAlign": "primitives/surfaces/Tooltip/types/TooltipAlign",
"TooltipArrowProps": "primitives/surfaces/Tooltip/types/TooltipArrowProps",
"TooltipArrowState": "primitives/surfaces/Tooltip/types/TooltipArrowState",
+ "TooltipBodyProps": "primitives/surfaces/Tooltip/types/TooltipBodyProps",
"TooltipHandle": "primitives/surfaces/Tooltip/types/TooltipHandle",
"TooltipPopupProps": "primitives/surfaces/Tooltip/types/TooltipPopupProps",
"TooltipPopupState": "primitives/surfaces/Tooltip/types/TooltipPopupState",
diff --git a/packages/twenty-ui/docs/tooltipPartPropDescriptions.ts b/packages/twenty-ui/docs/tooltipPartPropDescriptions.ts
index 5a33c0f3dcb..ea1f9c01757 100644
--- a/packages/twenty-ui/docs/tooltipPartPropDescriptions.ts
+++ b/packages/twenty-ui/docs/tooltipPartPropDescriptions.ts
@@ -32,6 +32,17 @@ export const TOOLTIP_PART_PROP_DESCRIPTIONS = {
maxWidth:
'Maximum popup width. Defaults to 300 pixels and is capped by the space available beside the anchor.',
},
+ Body: {
+ children:
+ 'Optional title content, displayed with medium weight. Omit it for a description-only tooltip.',
+ description:
+ 'Optional secondary content. Preserves line breaks and wraps long text.',
+ startIcon:
+ 'Optional decorative node before the title. Omitted when the title is empty.',
+ ref: 'Ref to the body div. Native props, styles and render target this element.',
+ render:
+ 'Composes the body root through an element or render callback while preserving its layout and content.',
+ },
Arrow: {
ref: 'Ref to the arrow div. Compose inside Popup.',
},
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index d8288e04fe6..09687065d55 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -10366,6 +10366,46 @@
}
]
},
+ {
+ "name": "Body",
+ "props": [
+ {
+ "name": "children",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Optional title content, displayed with medium weight. Omit it for a description-only tooltip."
+ },
+ {
+ "name": "description",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Optional secondary content. Preserves line breaks and wraps long text."
+ },
+ {
+ "name": "ref",
+ "type": "Ref<HTMLDivElement>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Ref to the body div. Native props, styles and render target this element."
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Composes the body root through an element or render callback while preserving its layout and content."
+ },
+ {
+ "name": "startIcon",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Optional decorative node before the title. Omitted when the title is empty."
+ }
+ ]
+ },
{
"name": "Arrow",
"props": [
diff --git a/packages/twenty-ui/src/primitives/surfaces/Tooltip/Tooltip.tsx b/packages/twenty-ui/src/primitives/surfaces/Tooltip/Tooltip.tsx
index 848325451d5..b19d6001f1b 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Tooltip/Tooltip.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Tooltip/Tooltip.tsx
@@ -1,6 +1,7 @@
import { Tooltip as TooltipPrimitive } from '@base-ui/react/tooltip';
import { TooltipArrow } from './internal/TooltipArrow';
+import { TooltipBody } from './internal/TooltipBody';
import { TooltipComponent } from './internal/TooltipComponent';
import { TooltipPopup } from './internal/TooltipPopup';
import { TooltipPortal } from './internal/TooltipPortal';
@@ -12,6 +13,7 @@ export const Tooltip = Object.assign(TooltipComponent, {
Portal: TooltipPortal,
Positioner: TooltipPositioner,
Popup: TooltipPopup,
+ Body: TooltipBody,
Arrow: TooltipArrow,
Viewport: TooltipPrimitive.Viewport,
Provider: TooltipPrimitive.Provider,
diff --git a/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/Tooltip.interactions.stories.tsx b/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/Tooltip.interactions.stories.tsx
new file mode 100644
index 00000000000..f65e53ac2ce
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/Tooltip.interactions.stories.tsx
@@ -0,0 +1,225 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { type ComponentProps, useState } from 'react';
+import { expect, fn, spyOn, userEvent, waitFor, within } from 'storybook/test';
+
+import { Button } from '@ui/primitives/input/Button/Button';
+import { ComponentDecorator } from '@ui/testing';
+
+import { Tooltip } from '../Tooltip';
+import { type TooltipRootProps } from '../types/TooltipRootProps';
+import { findTooltip } from './findTooltip';
+
+const meta: Meta<typeof Tooltip> = {
+ title: 'UI/Surfaces/Tooltip',
+ component: Tooltip,
+ decorators: [ComponentDecorator],
+ args: { content: 'Account details' },
+ render: (args) => (
+ <Tooltip {...args}>
+ <Button>Account</Button>
+ </Tooltip>
+ ),
+};
+
+export default meta;
+type Story = StoryObj<typeof Tooltip>;
+
+const EnableTooltipExample = () => {
+ const [disabled, setDisabled] = useState(true);
+
+ return (
+ <>
+ <Button onClick={() => setDisabled(false)}>Enable tooltip</Button>
+ <Tooltip content="Account details" disabled={disabled}>
+ <Button>Account</Button>
+ </Tooltip>
+ </>
+ );
+};
+
+export const EnableUncontrolledTooltip: Story = {
+ render: () => <EnableTooltipExample />,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const consoleError = spyOn(console, 'error');
+
+ try {
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Enable tooltip' }),
+ );
+ await userEvent.tab();
+
+ expect(canvas.getByRole('button', { name: 'Account' })).toHaveFocus();
+ expect(await findTooltip(canvasElement)).toHaveTextContent(
+ 'Account details',
+ );
+ expect(consoleError).not.toHaveBeenCalled();
+ } finally {
+ consoleError.mockRestore();
+ }
+ },
+};
+
+const TriggerHandlersExample = ({
+ onFocus,
+ onClick,
+}: Pick<ComponentProps<typeof Button>, 'onFocus' | 'onClick'>) => (
+ <Tooltip content="Account details">
+ <Button onFocus={onFocus} onClick={onClick}>
+ Account
+ </Button>
+ </Tooltip>
+);
+
+export const TriggerHandlers: StoryObj<typeof TriggerHandlersExample> = {
+ args: { onFocus: fn(), onClick: fn() },
+ render: (args) => <TriggerHandlersExample {...args} />,
+ play: async ({ args, canvasElement }) => {
+ const trigger = within(canvasElement).getByRole('button', {
+ name: 'Account',
+ });
+
+ await userEvent.tab();
+
+ expect(args.onFocus).toHaveBeenCalledOnce();
+ expect(await findTooltip(canvasElement)).toHaveTextContent(
+ 'Account details',
+ );
+
+ await userEvent.click(trigger);
+
+ expect(args.onClick).toHaveBeenCalledOnce();
+ await waitFor(() =>
+ expect(
+ within(canvasElement.ownerDocument.body).queryByRole('tooltip'),
+ ).not.toBeInTheDocument(),
+ );
+ },
+};
+
+export const DescriptionWithoutTitle: Story = {
+ args: { content: '', description: 'Account help' },
+ play: async ({ canvasElement }) => {
+ await userEvent.tab();
+
+ expect(await findTooltip(canvasElement)).toHaveTextContent('Account help');
+ },
+};
+
+export const DescriptionWithoutPayloadTitle: Story = {
+ render: () => (
+ <Tooltip<string>
+ content={({ payload }) => payload}
+ description="Account help"
+ >
+ <Button>Account</Button>
+ </Tooltip>
+ ),
+ play: async ({ canvasElement }) => {
+ await userEvent.tab();
+
+ expect(await findTooltip(canvasElement)).toHaveTextContent('Account help');
+ },
+};
+
+const EmptyPayloadsExample = () => {
+ const [handle] = useState(() => Tooltip.createHandle<string>());
+
+ return (
+ <>
+ <Tooltip.Trigger handle={handle} render={<Button>Missing</Button>} />
+ <Tooltip.Trigger
+ handle={handle}
+ payload=""
+ render={<Button>Empty</Button>}
+ />
+ <Tooltip<string>
+ handle={handle}
+ content={({ payload }) => payload}
+ triggerProps={{ payload: 'Account help' }}
+ >
+ <Button>Account</Button>
+ </Tooltip>
+ </>
+ );
+};
+
+export const EmptyPayloads: Story = {
+ render: () => <EmptyPayloadsExample />,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const page = within(canvasElement.ownerDocument.body);
+
+ await userEvent.tab();
+ await userEvent.tab();
+ await userEvent.tab();
+ expect(await findTooltip(canvasElement)).toHaveTextContent('Account help');
+
+ await userEvent.tab({ shift: true });
+
+ expect(canvas.getByRole('button', { name: 'Empty' })).toHaveFocus();
+ await waitFor(() =>
+ expect(page.queryByRole('tooltip')).not.toBeInTheDocument(),
+ );
+
+ await userEvent.tab({ shift: true });
+
+ expect(canvas.getByRole('button', { name: 'Missing' })).toHaveFocus();
+ expect(page.queryByRole('tooltip')).not.toBeInTheDocument();
+
+ await userEvent.tab();
+ await userEvent.tab();
+ expect(await findTooltip(canvasElement)).toHaveTextContent('Account help');
+ },
+};
+
+const cancelTooltipOpening = fn<NonNullable<TooltipRootProps['onOpenChange']>>(
+ (...changeArguments) => {
+ const [, details] = changeArguments;
+ details.cancel();
+ },
+);
+
+export const CancelOpening: Story = {
+ args: {
+ onOpenChange: cancelTooltipOpening,
+ },
+ render: ({ onOpenChange }) => (
+ <>
+ <Tooltip content="Shorthand hint" onOpenChange={onOpenChange}>
+ <Button>Shorthand</Button>
+ </Tooltip>
+ <Tooltip.Root onOpenChange={onOpenChange}>
+ <Tooltip.Trigger render={<Button>Compound</Button>} />
+ <Tooltip.Portal>
+ <Tooltip.Positioner>
+ <Tooltip.Popup>Compound hint</Tooltip.Popup>
+ </Tooltip.Positioner>
+ </Tooltip.Portal>
+ </Tooltip.Root>
+ </>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const page = within(canvasElement.ownerDocument.body);
+
+ for (const name of ['Shorthand', 'Compound']) {
+ const trigger = canvas.getByRole('button', { name });
+
+ await userEvent.tab();
+
+ const [isOpen, details] =
+ cancelTooltipOpening.mock.calls.find(
+ ([isOpening, changeDetails]) =>
+ isOpening && changeDetails.trigger === trigger,
+ ) ?? [];
+
+ expect(isOpen).toBe(true);
+ expect(details?.reason).toBe('trigger-focus');
+ expect(details?.trigger).toBe(trigger);
+ expect(typeof details?.event).toBe('object');
+ expect(typeof details?.cancel).toBe('function');
+ expect(page.queryByRole('tooltip')).not.toBeInTheDocument();
+ }
+ },
+};
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 2e46d752788..eb369a17610 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
@@ -1,6 +1,6 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
import { type ComponentProps, useRef, useState } from 'react';
-import { expect, userEvent, waitFor, within } from 'storybook/test';
+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
import { IconInfoCircle } from '@ui/icon';
import { Button } from '@ui/primitives/input/Button/Button';
@@ -9,18 +9,11 @@ import { ComponentDecorator } from '@ui/testing';
import { isDefined } from '@ui/utilities/utils/isDefined';
import { Tooltip } from '../Tooltip';
+import { type TooltipRootActions } from '../types/TooltipRootActions';
+import { type TooltipRootProps } from '../types/TooltipRootProps';
+import { findTooltip } from './findTooltip';
import styles from './Tooltip.stories.module.scss';
-const findTooltip = async (canvasElement: HTMLElement) => {
- const tooltip = await within(canvasElement.ownerDocument.body).findByRole(
- 'tooltip',
- );
-
- await waitFor(() => expect(tooltip).toBeVisible());
-
- return tooltip;
-};
-
const meta: Meta<typeof Tooltip> = {
title: 'UI/Surfaces/Tooltip',
component: Tooltip,
@@ -124,6 +117,19 @@ const ControlledExample = () => {
export const Controlled: Story = {
...Default,
render: () => <ControlledExample />,
+ play: async (context) => {
+ await Default.play?.(context);
+
+ await userEvent.keyboard('{Escape}');
+
+ await waitFor(() =>
+ expect(
+ within(context.canvasElement.ownerDocument.body).queryByRole('tooltip'),
+ ).not.toBeInTheDocument(),
+ );
+ await userEvent.unhover(within(context.canvasElement).getByRole('button'));
+ await KeyboardFocus.play?.(context);
+ },
};
export const DisabledButton: Story = {
@@ -183,7 +189,14 @@ export const SharedPopup: Story = {
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Positioner sideOffset={10}>
- <Tooltip.Popup>{payload}</Tooltip.Popup>
+ <Tooltip.Popup>
+ <Tooltip.Body
+ description="Values use the workspace currency."
+ startIcon={<IconInfoCircle />}
+ >
+ {payload}
+ </Tooltip.Body>
+ </Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
</>
@@ -193,7 +206,14 @@ export const SharedPopup: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.hover(canvas.getByRole('button', { name: 'First field' }));
- expect(await findTooltip(canvasElement)).toHaveTextContent('First amount');
+ const firstTooltip = await findTooltip(canvasElement);
+ expect(firstTooltip).toHaveTextContent('First amount');
+ expect(firstTooltip).toHaveTextContent(
+ 'Values use the workspace currency.',
+ );
+ expect(
+ within(firstTooltip).getByText('First amount').parentElement,
+ ).toHaveStyle({ fontWeight: '500' });
await userEvent.hover(canvas.getByRole('button', { name: 'Second field' }));
@@ -202,14 +222,34 @@ export const SharedPopup: Story = {
within(canvasElement.ownerDocument.body).getByRole('tooltip'),
).toHaveTextContent('Second amount'),
);
+ expect(
+ within(canvasElement.ownerDocument.body).getAllByRole('tooltip'),
+ ).toHaveLength(1);
},
};
-export const Hidden: Story = {
- args: { disabled: true, open: true },
- play: async ({ canvasElement }) => {
- await userEvent.hover(within(canvasElement).getByRole('button'));
+const HiddenTooltipExample = ({
+ onClick,
+}: Pick<ComponentProps<typeof Button>, 'onClick'>) => (
+ <Tooltip content="Amount" disabled open>
+ <Button onClick={onClick}>Show details</Button>
+ </Tooltip>
+);
+export const Hidden: StoryObj<typeof HiddenTooltipExample> = {
+ args: { onClick: fn() },
+ render: (args) => <HiddenTooltipExample {...args} />,
+ play: async ({ args, canvasElement }) => {
+ const trigger = within(canvasElement).getByRole('button');
+ await userEvent.hover(trigger);
+
+ expect(
+ within(canvasElement.ownerDocument.body).queryByRole('tooltip'),
+ ).not.toBeInTheDocument();
+
+ await userEvent.click(trigger);
+
+ expect(args.onClick).toHaveBeenCalledOnce();
expect(
within(canvasElement.ownerDocument.body).queryByRole('tooltip'),
).not.toBeInTheDocument();
@@ -340,8 +380,12 @@ export const PartsAndProvider: Story = {
},
};
-const ShorthandHandleExample = () => {
+const ShorthandHandleExample = ({
+ onOpenChange,
+}: Pick<TooltipRootProps, 'onOpenChange'>) => {
const [handle] = useState(() => Tooltip.createHandle<string>());
+ const actionsRef = useRef<TooltipRootActions>(null);
+
return (
<>
<Tooltip.Trigger
@@ -351,18 +395,34 @@ const ShorthandHandleExample = () => {
/>
<Tooltip<string>
handle={handle}
+ actionsRef={actionsRef}
+ onOpenChange={onOpenChange}
content={({ payload }) => payload}
triggerProps={{ payload: 'Local amount' }}
>
- <Button>Local details</Button>
+ <Button
+ aria-keyshortcuts="F2"
+ onKeyDown={(event) => {
+ if (event.key !== 'F2') {
+ return;
+ }
+
+ actionsRef.current?.close();
+ }}
+ >
+ Local details
+ </Button>
</Tooltip>
</>
);
};
export const ShorthandHandle: Story = {
- render: () => <ShorthandHandleExample />,
- play: async ({ canvasElement }) => {
+ args: { onOpenChange: fn() },
+ render: ({ onOpenChange }) => (
+ <ShorthandHandleExample onOpenChange={onOpenChange} />
+ ),
+ play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.tab();
expect(
@@ -378,6 +438,22 @@ export const ShorthandHandle: Story = {
within(canvasElement.ownerDocument.body).getByRole('tooltip'),
).toHaveTextContent('Local amount'),
);
+ expect(
+ within(canvasElement.ownerDocument.body).getAllByRole('tooltip'),
+ ).toHaveLength(1);
+
+ await userEvent.keyboard('{F2}');
+
+ expect(canvas.getByRole('button', { name: 'Local details' })).toHaveFocus();
+ expect(args.onOpenChange).toHaveBeenLastCalledWith(
+ false,
+ expect.objectContaining({ reason: 'imperative-action' }),
+ );
+ await waitFor(() =>
+ expect(
+ within(canvasElement.ownerDocument.body).queryByRole('tooltip'),
+ ).not.toBeInTheDocument(),
+ );
},
};
diff --git a/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/findTooltip.ts b/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/findTooltip.ts
new file mode 100644
index 00000000000..66eee735b17
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Tooltip/__stories__/findTooltip.ts
@@ -0,0 +1,11 @@
+import { expect, waitFor, within } from 'storybook/test';
+
+export const findTooltip = async (canvasElement: HTMLElement) => {
+ const tooltip = await within(canvasElement.ownerDocument.body).findByRole(
+ 'tooltip',
+ );
+
+ await waitFor(() => expect(tooltip).toBeVisible());
+
+ return tooltip;
+};
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 c73fc043794..c055a24ecd9 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
@@ -1,13 +1,12 @@
-import { act, render, screen, waitFor } from '@testing-library/react';
-import userEvent from '@testing-library/user-event';
-import { createRef, type ReactNode, useState } from 'react';
-import { describe, expect, it, vi } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import { createRef, type ReactNode } from 'react';
+import { expect, it } from 'vitest';
import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';
+import { IconInfoCircle } from '@ui/icon';
import { Tooltip } from '../Tooltip';
import styles from '../Tooltip.module.scss';
-import { type TooltipRootActions } from '../types/TooltipRootActions';
const TooltipRootWrapper = ({ children }: { children: ReactNode }) => (
<Tooltip.Root>{children}</Tooltip.Root>
@@ -37,6 +36,27 @@ runComponentConformance({
ownClassName: styles.popup,
});
+runComponentConformance({
+ name: 'Tooltip.Body',
+ element: <Tooltip.Body>Details</Tooltip.Body>,
+ refInstanceOf: HTMLDivElement,
+ ownClassName: styles.content,
+});
+
+it('renders a description without adding an absent title or icon', () => {
+ const { container } = render(
+ <Tooltip.Body
+ description="Only workspace members can export records."
+ startIcon={<IconInfoCircle />}
+ />,
+ );
+
+ expect(
+ screen.getByText('Only workspace members can export records.'),
+ ).toBeInTheDocument();
+ expect(container.querySelector('svg')).toBeNull();
+});
+
const PopupWrapper = ({ children }: { children: ReactNode }) => (
<OpenTooltipWrapper>
<Tooltip.Popup>{children}</Tooltip.Popup>
@@ -88,316 +108,49 @@ runComponentConformance({
ownClassName: styles.popup,
});
-const ControlledTooltip = () => {
- const [open, setOpen] = useState(false);
-
- return (
- <Tooltip content="Controlled hint" open={open} onOpenChange={setOpen}>
- <button type="button">Details</button>
- </Tooltip>
+it('uses the existing child as its trigger', () => {
+ const { container } = render(
+ <Tooltip content="Account details">
+ <button type="button">Account</button>
+ </Tooltip>,
);
-};
-
-describe('Tooltip interactions', () => {
- it('can enable an uncontrolled tooltip without changing its state contract', async () => {
- const user = userEvent.setup();
- const consoleError = vi.spyOn(console, 'error');
- const { rerender } = render(
- <Tooltip content="Account details" disabled>
- <button type="button">Account</button>
- </Tooltip>,
- );
-
- rerender(
- <Tooltip content="Account details">
- <button type="button">Account</button>
- </Tooltip>,
- );
- await user.tab();
-
- expect(await screen.findByRole('tooltip')).toHaveTextContent(
- 'Account details',
- );
- expect(consoleError).not.toHaveBeenCalled();
- consoleError.mockRestore();
- });
-
- it('composes the existing trigger and preserves its handlers', async () => {
- const user = userEvent.setup();
- const onFocus = vi.fn();
- const onClick = vi.fn();
- const { container } = render(
- <Tooltip content="Account details">
- <button type="button" onFocus={onFocus} onClick={onClick}>
- Account
- </button>
- </Tooltip>,
- );
-
- expect(container.firstElementChild).toBe(screen.getByRole('button'));
-
- await user.tab();
-
- expect(onFocus).toHaveBeenCalledOnce();
- expect(await screen.findByRole('tooltip')).toHaveTextContent(
- 'Account details',
- );
-
- await user.click(screen.getByRole('button'));
-
- expect(onClick).toHaveBeenCalledOnce();
- await waitFor(() => expect(screen.queryByRole('tooltip')).toBeNull());
- });
-
- it('reports controlled opening and Escape dismissal', async () => {
- const user = userEvent.setup();
- render(<ControlledTooltip />);
-
- await user.tab();
- expect(await screen.findByRole('tooltip')).toHaveTextContent(
- 'Controlled hint',
- );
-
- await user.keyboard('{Escape}');
- await waitFor(() => expect(screen.queryByRole('tooltip')).toBeNull());
- expect(screen.getByRole('button')).toHaveFocus();
- });
-
- it('shares one popup across detached triggers with their own content', async () => {
- const user = userEvent.setup();
- const handle = Tooltip.createHandle<string>();
- render(
- <>
- <Tooltip.Trigger handle={handle} payload="First hint">
- First
- </Tooltip.Trigger>
- <Tooltip.Trigger handle={handle} payload="Second hint">
- Second
- </Tooltip.Trigger>
- <Tooltip.Root handle={handle}>
- {({ payload }) => (
- <Tooltip.Portal>
- <Tooltip.Positioner sideOffset={10}>
- <Tooltip.Popup>{payload}</Tooltip.Popup>
- </Tooltip.Positioner>
- </Tooltip.Portal>
- )}
- </Tooltip.Root>
- </>,
- );
-
- await user.tab();
- expect(await screen.findByRole('tooltip')).toHaveTextContent('First hint');
-
- await user.tab();
-
- await waitFor(() =>
- expect(screen.getByRole('tooltip')).toHaveTextContent('Second hint'),
- );
- expect(screen.getAllByRole('tooltip')).toHaveLength(1);
- });
-
- it('suppresses a disabled tooltip without disabling its action', async () => {
- const user = userEvent.setup();
- const onClick = vi.fn();
- render(
- <Tooltip content="Unavailable hint" disabled open>
- <button type="button" onClick={onClick}>
- Action
- </button>
- </Tooltip>,
- );
-
- await user.click(screen.getByRole('button'));
-
- expect(onClick).toHaveBeenCalledOnce();
- expect(screen.queryByRole('tooltip')).toBeNull();
- });
+ expect(container.firstElementChild).toBe(
+ screen.getByRole('button', { name: 'Account' }),
+ );
});
-describe('Tooltip shorthand configuration', () => {
- it('shows a description when its title is empty', async () => {
- const user = userEvent.setup();
- render(
- <Tooltip content="" description="Account help">
- <button type="button">Account</button>
- </Tooltip>,
- );
-
- await user.tab();
-
- expect(await screen.findByRole('tooltip')).toHaveTextContent(
- 'Account help',
- );
- });
-
- it('suppresses empty payloads without disconnecting their triggers', async () => {
- const user = userEvent.setup();
- const handle = Tooltip.createHandle<string>();
- render(
- <>
- <Tooltip.Trigger handle={handle}>Missing</Tooltip.Trigger>
- <Tooltip.Trigger handle={handle} payload="">
- Empty
- </Tooltip.Trigger>
- <Tooltip<string>
- handle={handle}
- content={({ payload }) => payload}
- triggerProps={{ payload: 'Account help' }}
- >
- <button type="button">Account</button>
- </Tooltip>
- </>,
- );
-
- await user.tab();
- await user.tab();
- await user.tab();
- expect(await screen.findByRole('tooltip')).toHaveTextContent(
- 'Account help',
- );
-
- await user.tab({ shift: true });
- expect(screen.getByRole('button', { name: 'Empty' })).toHaveFocus();
- await waitFor(() => expect(screen.queryByRole('tooltip')).toBeNull());
-
- await user.tab({ shift: true });
- expect(screen.getByRole('button', { name: 'Missing' })).toHaveFocus();
- expect(screen.queryByRole('tooltip')).toBeNull();
-
- await user.tab();
- await user.tab();
- expect(await screen.findByRole('tooltip')).toHaveTextContent(
- 'Account help',
- );
- });
-
- it('shows a description when a payload callback returns no title', async () => {
- const user = userEvent.setup();
- render(
- <Tooltip<string>
- content={({ payload }) => payload}
- description="Account help"
- >
- <button type="button">Account</button>
- </Tooltip>,
- );
-
- await user.tab();
-
- expect(await screen.findByRole('tooltip')).toHaveTextContent(
- 'Account help',
- );
- });
-
- it('shares typed payloads with detached triggers and exposes imperative actions', async () => {
- const user = userEvent.setup();
- const handle = Tooltip.createHandle<string>();
- const actionsRef = createRef<TooltipRootActions>();
- render(
- <>
- <Tooltip.Trigger handle={handle} payload="Detached hint">
- Detached
- </Tooltip.Trigger>
- <Tooltip<string>
- handle={handle}
- actionsRef={actionsRef}
- content={({ payload }) => payload}
- triggerProps={{ payload: 'Local hint' }}
- >
- <button type="button">Local</button>
- </Tooltip>
- </>,
- );
- await user.tab();
- expect(await screen.findByRole('tooltip')).toHaveTextContent(
- 'Detached hint',
- );
- await user.tab();
- await waitFor(() =>
- expect(screen.getByRole('tooltip')).toHaveTextContent('Local hint'),
- );
- expect(handle.isOpen).toBe(true);
- act(() => actionsRef.current?.close());
- await waitFor(() => expect(screen.queryByRole('tooltip')).toBeNull());
- expect(handle.isOpen).toBe(false);
- });
-
- it('preserves event details and cancellation in both forms', async () => {
- const user = userEvent.setup();
- const onOpenChange = vi.fn((...changeArguments) => {
- const [, details] = changeArguments;
- details.cancel();
- });
- render(
- <>
- <Tooltip content="Shorthand hint" onOpenChange={onOpenChange}>
- <button type="button">Shorthand</button>
- </Tooltip>
- <Tooltip.Root onOpenChange={onOpenChange}>
- <Tooltip.Trigger>Compound</Tooltip.Trigger>
- <Tooltip.Portal>
- <Tooltip.Positioner>
- <Tooltip.Popup>Compound hint</Tooltip.Popup>
- </Tooltip.Positioner>
- </Tooltip.Portal>
- </Tooltip.Root>
- </>,
- );
- await user.tab();
- expect(onOpenChange).toHaveBeenLastCalledWith(
- true,
- expect.objectContaining({
- reason: 'trigger-focus',
- trigger: screen.getByRole('button', { name: 'Shorthand' }),
- event: expect.any(Object),
- cancel: expect.any(Function),
- }),
- );
- await user.tab();
- expect(onOpenChange).toHaveBeenCalledWith(
- true,
- expect.objectContaining({
- reason: 'trigger-focus',
- trigger: screen.getByRole('button', { name: 'Compound' }),
- }),
- );
- expect(screen.queryByRole('tooltip')).toBeNull();
- });
-
- it('targets native props, render composition and refs at each shorthand part', () => {
- const triggerRef = createRef<HTMLButtonElement>();
- const positionerRef = createRef<HTMLDivElement>();
- const portalRef = createRef<HTMLDivElement>();
- const popupRef = createRef<HTMLDivElement>();
- render(
- <Tooltip
- content="Hint"
- open
- ref={popupRef}
- render={<section />}
- aria-label="Popup"
- triggerProps={{
- ref: triggerRef,
- 'aria-label': 'Trigger',
- render: (props) => <button {...props} type="button" />,
- }}
- positionerProps={{
- ref: positionerRef,
- 'aria-label': 'Positioner',
- style: { maxWidth: 240 },
- }}
- portalProps={{ ref: portalRef, 'aria-label': 'Portal' }}
- >
- <button type="button">Original</button>
- </Tooltip>,
- );
- expect(triggerRef.current).toBe(screen.getByLabelText('Trigger'));
- expect(positionerRef.current).toBe(screen.getByLabelText('Positioner'));
- expect(positionerRef.current).toHaveStyle({ maxWidth: '240px' });
- expect(portalRef.current).toBe(screen.getByLabelText('Portal'));
- expect(popupRef.current).toBe(screen.getByLabelText('Popup'));
- expect(popupRef.current?.localName).toBe('section');
- });
+it('targets native props, render composition and refs at each shorthand part', () => {
+ const triggerRef = createRef<HTMLButtonElement>();
+ const positionerRef = createRef<HTMLDivElement>();
+ const portalRef = createRef<HTMLDivElement>();
+ const popupRef = createRef<HTMLDivElement>();
+ render(
+ <Tooltip
+ content="Hint"
+ open
+ ref={popupRef}
+ render={<section />}
+ aria-label="Popup"
+ triggerProps={{
+ ref: triggerRef,
+ 'aria-label': 'Trigger',
+ render: (props) => <button {...props} type="button" />,
+ }}
+ positionerProps={{
+ ref: positionerRef,
+ 'aria-label': 'Positioner',
+ style: { maxWidth: 240 },
+ }}
+ portalProps={{ ref: portalRef, 'aria-label': 'Portal' }}
+ >
+ <button type="button">Original</button>
+ </Tooltip>,
+ );
+ expect(triggerRef.current).toBe(screen.getByLabelText('Trigger'));
+ expect(positionerRef.current).toBe(screen.getByLabelText('Positioner'));
+ expect(positionerRef.current).toHaveStyle({ maxWidth: '240px' });
+ expect(portalRef.current).toBe(screen.getByLabelText('Portal'));
+ expect(popupRef.current).toBe(screen.getByLabelText('Popup'));
+ expect(popupRef.current?.localName).toBe('section');
});
diff --git a/packages/twenty-ui/src/primitives/surfaces/Tooltip/internal/TooltipBody.tsx b/packages/twenty-ui/src/primitives/surfaces/Tooltip/internal/TooltipBody.tsx
index c2e54916bf1..c0e800e04bd 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Tooltip/internal/TooltipBody.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Tooltip/internal/TooltipBody.tsx
@@ -1,33 +1,42 @@
-import { type ReactNode } from 'react';
+import { useRender } from '@base-ui/react/use-render';
+import { clsx } from 'clsx';
import { isRenderableSlot } from '@ui/utilities/internal/isRenderableSlot';
import styles from '../Tooltip.module.scss';
-
-type TooltipBodyProps = {
- children: ReactNode;
- description?: ReactNode;
- startIcon?: ReactNode;
-};
+import { type TooltipBodyProps } from '../types/TooltipBodyProps';
export const TooltipBody = ({
children,
description,
startIcon,
-}: TooltipBodyProps) => (
- <div className={styles.content}>
- {isRenderableSlot(children) && (
- <div className={styles.title}>
- {isRenderableSlot(startIcon) && (
- <span className={styles.icon} aria-hidden>
- {startIcon}
- </span>
- )}
- <span>{children}</span>
- </div>
- )}
- {isRenderableSlot(description) && (
- <div className={styles.description}>{description}</div>
- )}
- </div>
-);
+ className,
+ render,
+ ref,
+ ...props
+}: TooltipBodyProps) =>
+ useRender({
+ render,
+ ref,
+ props: {
+ ...props,
+ className: clsx(styles.content, className),
+ children: (
+ <>
+ {isRenderableSlot(children) && (
+ <div className={styles.title}>
+ {isRenderableSlot(startIcon) && (
+ <span className={styles.icon} aria-hidden>
+ {startIcon}
+ </span>
+ )}
+ <span>{children}</span>
+ </div>
+ )}
+ {isRenderableSlot(description) && (
+ <div className={styles.description}>{description}</div>
+ )}
+ </>
+ ),
+ },
+ });
diff --git a/packages/twenty-ui/src/primitives/surfaces/Tooltip/types/TooltipBodyProps.ts b/packages/twenty-ui/src/primitives/surfaces/Tooltip/types/TooltipBodyProps.ts
new file mode 100644
index 00000000000..cf75d5904db
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Tooltip/types/TooltipBodyProps.ts
@@ -0,0 +1,7 @@
+import { type useRender } from '@base-ui/react/use-render';
+import { type ReactNode } from 'react';
+
+export type TooltipBodyProps = useRender.ComponentProps<'div'> & {
+ description?: ReactNode;
+ startIcon?: ReactNode;
+};
diff --git a/packages/twenty-ui/src/primitives/surfaces/index.ts b/packages/twenty-ui/src/primitives/surfaces/index.ts
index bafe8d6b6d1..1bfa8e9c99f 100644
--- a/packages/twenty-ui/src/primitives/surfaces/index.ts
+++ b/packages/twenty-ui/src/primitives/surfaces/index.ts
@@ -99,6 +99,7 @@ export { Tooltip } from './Tooltip/Tooltip';
export type { TooltipAlign } from './Tooltip/types/TooltipAlign';
export type { TooltipArrowProps } from './Tooltip/types/TooltipArrowProps';
export type { TooltipArrowState } from './Tooltip/types/TooltipArrowState';
+export type { TooltipBodyProps } from './Tooltip/types/TooltipBodyProps';
export type { TooltipHandle } from './Tooltip/types/TooltipHandle';
export type { TooltipPopupProps } from './Tooltip/types/TooltipPopupProps';
export type { TooltipPopupState } from './Tooltip/types/TooltipPopupState';