Skip to content

Commit 0022bf4

Browse files
committed
docs(tooltip): add portal examples
1 parent 71c153d commit 0022bf4

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

docs/src/pages/components/Tooltip.svx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,39 @@ Hide the icon while keeping the tooltip functionality using `hideIcon`.
107107
<p>
108108
Resources are provisioned based on your account's organization.
109109
</p>
110-
</Tooltip>
110+
</Tooltip>
111+
112+
## Portal tooltip
113+
114+
Use `portalTooltip` to render the tooltip in a portal, preventing it from being clipped by `overflow: hidden` containers. This is automatically enabled when the tooltip is inside a `Modal`.
115+
116+
<Tooltip portalTooltip triggerText="Portalled">
117+
<p>
118+
This tooltip is rendered in a portal.
119+
</p>
120+
</Tooltip>
121+
122+
## Portal tooltip (hidden icon)
123+
124+
Portal tooltips also work with `hideIcon`.
125+
126+
<Tooltip portalTooltip hideIcon triggerText="Portalled (hidden icon)">
127+
<p>
128+
This tooltip is rendered in a portal without the icon.
129+
</p>
130+
</Tooltip>
131+
132+
## Portal tooltip directions
133+
134+
Position portalled tooltips in different directions.
135+
136+
<Tooltip portalTooltip triggerText="Top" direction="top"><p>Top</p></Tooltip>
137+
<Tooltip portalTooltip triggerText="Right" direction="right"><p>Right</p></Tooltip>
138+
<Tooltip portalTooltip triggerText="Bottom" direction="bottom"><p>Bottom</p></Tooltip>
139+
<Tooltip portalTooltip triggerText="Left" direction="left"><p>Left</p></Tooltip>
140+
141+
## Inside a modal
142+
143+
When a tooltip is used inside a [Modal](/components/Modal), it is automatically rendered in a portal so it is not clipped by the modal's overflow or z-index stacking. No need to set `portalTooltip` in this case.
144+
145+
<FileSource src="/framed/Tooltip/TooltipModal" />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script>
2+
import {
3+
Button,
4+
Modal,
5+
Portal,
6+
Stack,
7+
Tooltip,
8+
} from "carbon-components-svelte";
9+
10+
let open = false;
11+
</script>
12+
13+
<Button on:click={() => (open = true)}>Open modal</Button>
14+
15+
<Portal>
16+
<Modal
17+
bind:open
18+
size="sm"
19+
modalHeading="Tooltip in modal"
20+
primaryButtonText="Done"
21+
secondaryButtonText="Cancel"
22+
on:click:button--secondary={() => (open = false)}
23+
>
24+
<Tooltip triggerText="Top" direction="top"><p>Top</p></Tooltip>
25+
<Tooltip triggerText="Right" direction="right"><p>Right</p></Tooltip>
26+
<Tooltip triggerText="Bottom" direction="bottom"><p>Bottom</p></Tooltip>
27+
<Tooltip triggerText="Left" direction="left"><p>Left</p></Tooltip>
28+
</Modal>
29+
</Portal>

0 commit comments

Comments
 (0)