Skip to content

Commit 878aa46

Browse files
committed
update
1 parent b25c82b commit 878aa46

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

src/routes/reference/components/portal.mdx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Creates an SVG `<g>` container instead of an HTML `<div>`.
6161

6262
- **Type:** `HTMLDivElement | SVGGElement | ((el: HTMLDivElement | SVGGElement) => void)`
6363

64-
Receives the portal container element.
64+
Receives the created portal container element. This is a `<div>` by default or a `<g>` when `isSVG` is `true`.
6565

6666
### `children`
6767

@@ -80,24 +80,42 @@ Returns a marker node used to preserve the portal position in the component tree
8080
- `<Portal>` renders its children outside the parent DOM hierarchy, but events still propagate through the Solid component hierarchy.
8181
- When the mount target is not `document.head`, the portal creates a container element and appends it to the mount target.
8282
- When the mount target is `document.head`, the portal inserts its children without creating that container element.
83+
- During server rendering, `<Portal>` returns no output.
8384
- Portals render only on the client and are skipped during hydration.
8485

8586
## Examples
8687

8788
### Basic usage
8889

8990
```tsx
91+
import { createSignal, Show } from "solid-js";
9092
import { Portal } from "solid-js/web";
9193

92-
function Example() {
93-
return (
94-
<Portal mount={document.getElementById("modal-root")!}>
95-
<div>My Content</div>
96-
</Portal>
94+
function App() {
95+
const [open, setOpen] = createSignal(false);
96+
97+
return (
98+
<>
99+
<button onClick={() => setOpen(true)}>Open</button>
100+
101+
<Show when={open()}>
102+
<Portal>
103+
<div
104+
style={{
105+
position: "fixed",
106+
top: "2rem",
107+
left: "2rem",
108+
padding: "1rem",
109+
background: "white",
110+
border: "1px solid #ccc",
111+
}}
112+
>
113+
<div>Popup</div>
114+
<button onClick={() => setOpen(false)}>Close</button>
115+
</div>
116+
</Portal>
117+
</Show>
118+
</>
97119
);
98120
}
99121
```
100-
101-
## Related
102-
103-
- [`<Dynamic>`](/reference/components/dynamic)

0 commit comments

Comments
 (0)