Skip to content

Commit 68f81a0

Browse files
authored
fix: use_lock_html_scroll (#215)
1 parent 089b3a0 commit 68f81a0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

thaw_utils/src/hooks/use_lock_html_scroll.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ pub fn use_lock_html_scroll(is_lock: MaybeSignal<bool>) {
88
let remove_style_el = move || {
99
style_el.update_value(move |el| {
1010
if let Some(el) = el.take() {
11-
let head = document().head().expect("head no exist");
12-
_ = head.remove_child(&el);
11+
el.remove();
1312
}
1413
});
1514
};
1615

17-
create_render_effect(move |_| {
18-
if is_lock.get() {
16+
create_render_effect(move |prev| {
17+
let is_lock = is_lock.get();
18+
let prev: bool = prev.unwrap_or_default();
19+
20+
if is_lock && !prev {
1921
let head = document().head().expect("head no exist");
2022
let style = document()
2123
.create_element("style")
@@ -24,9 +26,11 @@ pub fn use_lock_html_scroll(is_lock: MaybeSignal<bool>) {
2426
style.set_text_content(Some("html { overflow: hidden; }"));
2527
_ = head.append_child(&style);
2628
style_el.set_value(Some(style));
27-
} else {
29+
} else if !is_lock && prev {
2830
remove_style_el();
2931
}
32+
33+
is_lock
3034
});
3135

3236
on_cleanup(remove_style_el)

0 commit comments

Comments
 (0)