-
Hi, please consider adding the children-as-a-function pattern as an option to use instead of Example of how this would work using // note that in the TooltipPrimitive.Trigger/Primitive code you can do:
// return typeof children === 'function' ? children(radixProps) : render_primitive_normally...
const MyTooltip = ({ children, content }) => (
<TooltipPrimitive.Root>
<TooltipPrimitive.Trigger>
{children}
</TooltipPrimitive.Trigger>
<TooltipPrimitive.Content>
{content}
<TooltipPrimitive.Arrow />
</TooltipPrimitive.Content>
</TooltipPrimitive.Root>
);
<MyTooltip content="Tooltip content">
{(radixProps) => <button {...radixProps}>Tooltip trigger</button>}
</MyTooltip>; Why?
The While my suggestion would be to replace Also, as a side note, I was reading through some of the code and I don't think this |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
Hi @rafgraph, It's entirely up to you whether you use const Button = React.forwardRef((props) => <button {...props}>Tooltip trigger</button>);
<Tooltip content="Tooltip without slot">
<TooltipTrigger as={Button} />
</Tooltip> We're purposefully avoiding render props with our API for a few reasons:
That's not to say we would never use/consider them though, they're just more of a last resort for us.
If you do decide to use We're aware that the
We can perhaps look into improving types for
It is doing something 🙂 but this is all internal stuff that our consumers shouldn't need to be impacted by. |
Beta Was this translation helpful? Give feedback.
-
@jjenzz just want to make sure I understand the suggested solution if I want to avoid using // create MyTooltip with closed api
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
export const MyTooltip = ({ children, content }) => (
<TooltipPrimitive.Root>
{children}
<TooltipPrimitive.Content>
{content}
<TooltipPrimitive.Arrow />
</TooltipPrimitive.Content>
</TooltipPrimitive.Root>
); import * as TooltipPrimitive from '@radix-ui/react-tooltip';
import { MyTooltip } from '...';
const MyButton = React.forwardRef((props) => <button {...props} />);
const App = () => (
<MyTooltip content="Tooltip content">
<TooltipPrimitive.Trigger as={MyButton}>Tooltip name</TooltipPrimitive.Trigger>
</MyTooltip>
); |
Beta Was this translation helpful? Give feedback.
Hi @rafgraph,
It's entirely up to you whether you use
Slot
or not. If you would prefer not to, this is the way we propose:We're purposefully avoiding render props with our API for a few reasons:
Slot
because;