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

fix: Tooltip: render non-string content outside of the Text component #557

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions apps/playground/app/sink/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@ export default function Sink() {
Multiline
</Button>
</Tooltip>

<Tooltip
textAs="div"
content={
<DataList.Root my="1">
<DataList.Item>
<DataList.Label style={{ color: 'var(--gray-5)'}}>Name</DataList.Label>
<DataList.Value style={{ color: 'var(--gray-1)'}}>Susan Kare</DataList.Value>
</DataList.Item>
<DataList.Item>
<DataList.Label style={{ color: 'var(--gray-5)'}}>Email</DataList.Label>
<DataList.Value style={{ color: 'var(--gray-1)'}}>[email protected]</DataList.Value>
</DataList.Item>
</DataList.Root>
}
>
<Button variant="solid" size="1">
Non-string ReactNode
</Button>
</Tooltip>
</Flex>
</DocsGridSectionItem>

Expand Down
3 changes: 3 additions & 0 deletions packages/radix-ui-themes/src/components/tooltip.props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { widthPropDefs } from '../props/width.props.js';
import { textPropDefs } from './text.props.js';

import type { PropDef, GetPropDefTypes } from '../props/prop-def.js';

Expand All @@ -7,11 +8,13 @@ const tooltipPropDefs = {
width: widthPropDefs.width,
minWidth: widthPropDefs.minWidth,
maxWidth: { ...widthPropDefs.maxWidth, default: '360px' },
textAs: textPropDefs['as']
} satisfies {
width: PropDef<string>;
minWidth: PropDef<string>;
maxWidth: PropDef<string>;
content: PropDef<React.ReactNode>;
textAs: PropDef<string>;
};

type TooltipOwnProps = GetPropDefTypes<typeof tooltipPropDefs & typeof widthPropDefs>;
Expand Down
3 changes: 2 additions & 1 deletion packages/radix-ui-themes/src/components/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Tooltip = React.forwardRef<TooltipElement, TooltipProps>((props, forwarded
content,
container,
forceMount,
textAs,
...tooltipContentProps
} = extractProps(props, tooltipPropDefs);
const rootProps = { open, defaultOpen, onOpenChange, delayDuration, disableHoverableContent };
Expand All @@ -47,7 +48,7 @@ const Tooltip = React.forwardRef<TooltipElement, TooltipProps>((props, forwarded
ref={forwardedRef}
className={classNames('rt-TooltipContent', className)}
>
<Text as="p" className="rt-TooltipText" size="1">
<Text as={textAs ?? 'p'} className="rt-TooltipText" size="1">
{content}
</Text>
<TooltipPrimitive.Arrow className="rt-TooltipArrow" />
Expand Down