diff --git a/src/components/binder/mod.rs b/src/components/binder/mod.rs index 6e504ee..c6f36b8 100644 --- a/src/components/binder/mod.rs +++ b/src/components/binder/mod.rs @@ -158,20 +158,19 @@ fn FollowerContainer( } is_show }); + + let children = html::div() + .classes("thaw-binder-follower-container") + .style("display", move || (!is_show.get()).then_some("none")) + .child( + html::div() + .classes("thaw-binder-follower-content") + .node_ref(content_ref) + .attr("style", move || content_style.get()) + .child(children()), + ); view! { - -
-
- {children()} -
-
-
+ } } diff --git a/src/teleport/mod.rs b/src/teleport/mod.rs index 777c49b..cfa976e 100644 --- a/src/teleport/mod.rs +++ b/src/teleport/mod.rs @@ -1,30 +1,36 @@ use cfg_if::cfg_if; -use leptos::*; +use leptos::{html::AnyElement, *}; /// https://github.com/solidjs/solid/blob/main/packages/solid/web/src/index.ts#L56 #[component] pub fn Teleport( #[prop(into, optional)] mount: Option, - children: Children, + #[prop(optional, into)] element: Option>, + #[prop(optional)] children: Option, ) -> impl IntoView { cfg_if! { if #[cfg(target_arch = "wasm32")] { - use leptos::{ - wasm_bindgen::JsCast, - leptos_dom::Mountable - }; + use leptos::wasm_bindgen::JsCast; let mount = mount.unwrap_or_else(|| { document() .body() .expect("body element not to exist") .unchecked_into() }); - let node = children().into_view(); - let node = node.get_mountable_node(); - _ = mount.append_child(&node); + + let render_root = if let Some(element) = element { + element + } else if let Some(children) = children { + html::div().child(children()).into_any() + } else { + return; + }; + + _ = mount.append_child(&render_root); on_cleanup(move || { - _ = mount.remove_child(&node); + _ = mount.remove_child(&render_root); }); } else { _ = mount; + _ = element; _ = children; }} }