-
-
::new();
+ let drawer_ref = NodeRef::
::new();
- style=move || css_vars.get()
+ let is_lock = RwSignal::new(show.get_untracked());
+ Effect::new(move |_| {
+ if show.get() {
+ is_lock.set(true);
+ }
+ });
+ use_lock_html_scroll(is_lock.into());
+ let on_after_leave = move |_| {
+ is_lock.set(false);
+ };
+
+ view! {
+
+
- {children()}
-
+
+
+
+
+ {children()}
+
+
}
}
match mount {
- DrawerMount::None => view! {
-
- },
+ DrawerMount::None => view! {
},
DrawerMount::Body => view! {
-
+
},
}
@@ -76,6 +112,8 @@ pub enum DrawerPlacement {
Right,
}
+impl Copy for DrawerPlacement {}
+
impl DrawerPlacement {
pub fn as_str(&self) -> &'static str {
match self {
diff --git a/thaw/src/utils/mod.rs b/thaw/src/utils/mod.rs
index e953ee2..59dc9ac 100644
--- a/thaw/src/utils/mod.rs
+++ b/thaw/src/utils/mod.rs
@@ -8,6 +8,7 @@ mod optional_prop;
mod signal;
mod stored_maybe_signal;
mod time;
+mod use_lock_html_scroll;
// pub use callback::AsyncCallback;
pub use component_ref::{create_component_ref, ComponentRef};
@@ -18,6 +19,7 @@ pub(crate) use optional_prop::OptionalProp;
pub use signal::SignalWatch;
pub(crate) use stored_maybe_signal::*;
pub(crate) use time::*;
+pub(crate) use use_lock_html_scroll::*;
pub(crate) fn with_hydration_off
(f: impl FnOnce() -> T) -> T {
#[cfg(feature = "hydrate")]
diff --git a/thaw/src/utils/use_lock_html_scroll.rs b/thaw/src/utils/use_lock_html_scroll.rs
new file mode 100644
index 0000000..091178c
--- /dev/null
+++ b/thaw/src/utils/use_lock_html_scroll.rs
@@ -0,0 +1,39 @@
+use leptos::MaybeSignal;
+
+pub fn use_lock_html_scroll(is_lock: MaybeSignal) {
+ #[cfg(any(feature = "csr", feature = "hydrate"))]
+ {
+ use leptos::{create_render_effect, document, on_cleanup, SignalGet, StoredValue};
+ let style_el = StoredValue::new(None::);
+ let remove_style_el = move || {
+ style_el.update_value(move |el| {
+ if let Some(el) = el.take() {
+ let head = document().head().expect("head no exist");
+ _ = head.remove_child(&el);
+ }
+ });
+ };
+
+ create_render_effect(move |_| {
+ if is_lock.get() {
+ let head = document().head().expect("head no exist");
+ let style = document()
+ .create_element("style")
+ .expect("create style element error");
+ _ = style.set_attribute("data-id", &format!("thaw-lock-html-scroll"));
+ style.set_text_content(Some("html { overflow: hidden; }"));
+ _ = head.append_child(&style);
+ style_el.set_value(Some(style));
+ } else {
+ remove_style_el();
+ }
+ });
+
+ on_cleanup(remove_style_el)
+ }
+
+ #[cfg(not(any(feature = "csr", feature = "hydrate")))]
+ {
+ _ = is_lock;
+ }
+}