# svelte-portal

> Svelte component for rendering outside the DOM of parent component

Latest version **2.2.1** (published 2024-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install svelte-portal
pnpm add svelte-portal
yarn add svelte-portal
bun add svelte-portal
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2024-01-17 |
| First published | 2019-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 474 |
| Maintainers | rodych |
| Keywords | svelte, portal |

## Links

- npm: https://www.npmjs.com/package/svelte-portal
- Repository: https://github.com/romkor/svelte-portal
- Homepage: https://github.com/romkor/svelte-portal#readme
- Issues: https://github.com/romkor/svelte-portal/issues
- npm.io page: https://npm.io/package/svelte-portal

## Recent versions

- 2.2.1 (latest) — 2024-01-17
- 2.2.0 — 2022-06-02
- 2.1.2 — 2021-03-29
- 2.1.1 — 2020-12-17
- 2.1.0 — 2020-12-17
- 2.0.0 — 2020-10-18
- 1.0.0 — 2020-09-14
- 0.1.0 — 2020-01-16
- 0.0.5 — 2020-01-14
- 0.0.4 — 2019-11-06
- 0.0.3 — 2019-11-06
- 0.0.2 — 2019-11-05
- 0.0.1 — 2019-11-05

## README

Svelte component for rendering outside the DOM of parent component

Idea borrowed from here: https://github.com/sveltejs/svelte/issues/3088#issuecomment-505785516

# Installation

```sh
npm install --save svelte-portal
```

or

```sh
yarn add svelte-portal
```

# Usage Portal component

The `<Portal />` component has only one property: `target`

target can be a HTMLElement `target={document.body}` or a css selector `target="#modals"` that points to an already existing element.

When no target is given it defaults to: `document.body`.

## Example

```html
<script>
  import Portal from "svelte-portal";
</script>

<Portal target="body">
  <div class="toast">Entity successfully updated!</div>
</Portal>
```

# Usage portal action

The functionality can also be applied to DOM elements directly via a svelte action:

## Example

```html
<script>
  import { portal } from "svelte-portal";
</script>

<div class="toast" use:portal={"body"} hidden>Entity successfully updated!</div>
```

The `hidden` atrribute is only needed when using ssr, when portal has moved the element to it's targetted location it removes the hidden attribute.

## TypeScript support

`<script lang="ts">` users should import from `"svelte-portal/src/Portal.svelte"` instead of `"svelte-portal"` to get typing support.

---
_Source: https://npm.io/package/svelte-portal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
