Skip to content

Commit 543c2e1

Browse files
authored
docs(tooltip): clarify props must be spread onto child components (#19408)
1 parent 91849a4 commit 543c2e1

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

packages/react/src/components/Tooltip/Tooltip.mdx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { stackblitzPrefillConfig } from '../../../previewer/codePreviewer';
1818

1919
- [Tooltip](#Tooltip)
2020
- [Overview](#overview)
21+
- [Usage](#usage)
2122
- [Toggletips vs Tooltips](#toggletips-vs-tooltips)
2223
- [Customizing the content of a tooltip](#customizing-the-content-of-a-tooltip)
2324
- [Tooltip alignment](#tooltip-alignment)
@@ -31,18 +32,41 @@ import { stackblitzPrefillConfig } from '../../../previewer/codePreviewer';
3132

3233
You can use the `Tooltip` component as a wrapper to display a popup for an
3334
interactive element that you provide. If you are trying to place interactive
34-
content inside of the `Tooltip` itself, consider using `Toggletip` instead. You
35-
can provide the interactive element as a child to `Tooltip`, for example:
35+
content inside of the `Tooltip` itself, consider using `Toggletip` instead.
36+
37+
### Usage
38+
39+
`Tooltip` accepts a single child for its `children` prop. It is important that
40+
the child is an interactive element, for example:
3641

3742
```jsx
3843
<Tooltip label="Close">
3944
<button type="button">X</button>
4045
</Tooltip>
4146
```
4247

43-
`Tooltip` accepts a single child for its `children` prop. It is important that
44-
the component you provide renders an interactive element. In addition, you can
45-
specify the contents of the popup through the `label` or `description` prop.
48+
When used with a component, props need to be spread on the child component.
49+
50+
```jsx
51+
export default function App() {
52+
return (
53+
<Tooltip label="Close">
54+
<CustomTrigger />
55+
</Tooltip>
56+
);
57+
}
58+
59+
function CustomTrigger(props) {
60+
return (
61+
<button type="button" {...props}>
62+
X
63+
</button>
64+
);
65+
}
66+
```
67+
68+
You can specify the contents of the popup through the `label` or `description`
69+
prop.
4670

4771
<Canvas
4872
of={TooltipStories.Default}

0 commit comments

Comments
 (0)