You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -159,10 +138,54 @@ Just include it with a script tag *after* Vue itself
159
138
160
139
The plugin will automatically register the `<portal>` component globally.
161
140
162
-
## Features
141
+
## Props
163
142
164
143
This library aims to do one thing only, and do it well: move stuff to the end of the documentfor things like modals. But it still gives the developer a few props to influence how exactly that happens:
165
144
145
+
### `selector`
146
+
147
+
|type|required|default|
148
+
|------|------|-------|
149
+
|String|no |'vue-portal-target-<randomId>'|
150
+
151
+
A query selector that defines the **target element** to which to append the content of the portal.
152
+
153
+
If no selector is given, a random default selector (created at startup) is used.
154
+
155
+
I no element matches the selector, a newelement is created and appended to `<body>`
156
+
157
+
Consequently, this means that using the `<portal>` without a `selector` prop will always append to a div at the end of the `<body>` element, which is a sensible default for the goal ofthis plugin.
158
+
159
+
### `disabled`
160
+
161
+
|type|required|default|
162
+
|-----|-------|-------|
163
+
|Boolean|no |false|
164
+
165
+
When `true`, renders the `<portal>`'s slot content in place instead of appending it to the target element. See Caveats section for a small footgun here.
166
+
167
+
### `prepend`
168
+
169
+
|type|required|default|
170
+
|-----|-------|-------|
171
+
|Boolean|no | false |
172
+
173
+
Usually, the slot content of a portal will be *appended* to the target element, which means, if that element has child nodes, our content will be inserted as the last node in that list.
174
+
175
+
Set the `prepend` prop if you want to *prepend* the content instead.
176
+
177
+
### `tag`
178
+
179
+
|type|required|default|
180
+
|------|-------|------|
181
+
|String|no |'DIV' |
182
+
183
+
When the content of `<poral>` is appended to the target element, it's actually wrapped in a small, transparent component (for technical reasons). Likeall (*non-functional*) components in Vue, it requires a single root element.
184
+
185
+
The `tag` prop can be used to define what that element should be.
186
+
187
+
**Heads up**: When used in combination with`disabled`, it's used to define the root element of the `<portal>` itself!
188
+
166
189
## Caveats
167
190
168
191
Some caveats still exist, such as:
@@ -177,11 +200,11 @@ If you need to keep state between these switches, keep it in a [global state man
177
200
178
201
### Transitions
179
202
180
-
When you use a `<transition>` as the root element of the portal and then remove the portal (i.e. with `v-if`) or set `disabled` to `true`, no leave transition will happen.
203
+
When you use a `<transition>` as the root element of the portal and then remove the portal (i.e. with `v-if`) or set its `disabled` prop to `true`, no leave transition will happen.
181
204
182
-
This is to expected, as the same thing would happen if you removed a div that contains a `<transition>`, but often trips people up nonetheless.
205
+
While this is to expected, as the same thing would happen if you removed a div that contains a `<transition>`, it often trips people up, which is why it's mentioned here.
183
206
184
-
If you need to remove or disable the portal *after* a transition has finished, you woulld have to work around this like this:
207
+
If you need to remove or disable the portal *after* a transition has finished, you can make it work like this:
185
208
186
209
<details>
187
210
<summary>Show Example</summary>
@@ -215,8 +238,24 @@ If you need to remove or disable the portal *after* a transition has finished, y
215
238
</script>
216
239
```
217
240
241
+
Of course this only works if you actually can listen to the events of the `<transition>`, and could be problematic or even impossible with3rd-Party components, depending on their implementations.
242
+
243
+
As a last resort you can always use a Timeout if yu know the duration of the leave transition.
244
+
218
245
</details>
219
246
247
+
### Devtools
248
+
249
+
If the slot content of the `<portal>` contains components, they will show up as children of the `<portal>`in the devtools, even though their root elements were mounted/moved to the target element, outside of the current component tree.
250
+
251
+
### Target elements inside of your Vue app
252
+
253
+
The general advise is to only mount to elements *outside*of your Vue app, as that's the prime use case of this library. If you need to mount to locations *inside of* your app, consider using [portal-vue](https://portal-vue.linusb.org) instead.
254
+
255
+
That being said, you *can* move content to an element that is controlled by Vue, i.e. is part of the template of some other component.
256
+
257
+
However, be advised that this element could be removed or replaced by Vue when that component re-renders, while the component instances bound to that element (or its children) are still in memory. This could potentialy be a memory leak if you're not careful.
0 commit comments