feat(web): using None instead of Element (#3012)

Can mount the Dioxus component into every node.
As `Element` and `ShadowRoot` are `Node` we can
now mount a dioxus component into a shadow root.
This commit is contained in:
igor authored and GitHub committed 2024-09-30 07:02:06 -05:00
1 parent 9f22e9043c
commit d3e1ba415f
3 files changed
+17 -7

No files matched your search

+12 -2
View File
@@ -1,3 +1,5 @@
use wasm_bindgen::JsCast as _;
/// Configuration for the WebSys renderer for the Dioxus VirtualDOM.
///
/// This struct helps configure the specifics of hydration and render destination for WebSys.
@@ -15,7 +17,7 @@ pub struct Config {
pub(crate) enum ConfigRoot {
RootName(String),
RootElement(web_sys::Element),
RootNode(web_sys::Node),
}
impl Config {
@@ -52,7 +54,15 @@ impl Config {
///
/// This is akin to calling React.render() on the given element.
pub fn rootelement(mut self, elem: web_sys::Element) -> Self {
self.root = ConfigRoot::RootElement(elem);
self.root = ConfigRoot::RootNode(elem.unchecked_into());
self
}
/// Set the node that Dioxus will use as root.
///
/// This is akin to calling React.render() on the given element.
pub fn rootnode(mut self, node: web_sys::Node) -> Self {
self.root = ConfigRoot::RootNode(node);
self
}