This is unreleased documentation for Yew Next version.
For up-to-date documentation, see the latest version on docs.rs.

yew/virtual_dom/
vportal.rs

1//! This module contains the implementation of a portal `VPortal`.
2
3use web_sys::{Element, Node};
4
5use super::VNode;
6
7#[derive(Debug, Clone, PartialEq)]
8pub struct VPortal {
9    /// The element under which the content is inserted.
10    pub host: Element,
11    /// The next sibling after the inserted content. Must be a child of `host`.
12    pub inner_sibling: Option<Node>,
13    /// The inserted node
14    pub node: VNode,
15}
16
17impl VPortal {
18    /// Creates a [VPortal] rendering `content` in the DOM hierarchy under `host`.
19    pub fn new(content: VNode, host: Element) -> Self {
20        Self {
21            host,
22            inner_sibling: None,
23            node: content,
24        }
25    }
26
27    /// Creates a [VPortal] rendering `content` in the DOM hierarchy under `host`.
28    /// If `inner_sibling` is given, the content is inserted before that [Node].
29    /// The parent of `inner_sibling`, if given, must be `host`.
30    pub fn new_before(content: VNode, host: Element, inner_sibling: Option<Node>) -> Self {
31        Self {
32            host,
33            inner_sibling,
34            node: content,
35        }
36    }
37}