Fix callback handling of use_scroll

by bumping `default-struct-builder`
This commit is contained in:
Jens Krause 2023-07-13 08:04:01 +02:00
parent ef0989cbdd
commit ada0c27d71
3 changed files with 18 additions and 7 deletions

View file

@ -16,7 +16,7 @@ homepage = "https://leptos-use.rs"
leptos = "0.4"
wasm-bindgen = "0.2"
js-sys = "0.3"
default-struct-builder = "0.3"
default-struct-builder = "0.4"
num = { version = "0.4", optional = true }
serde = { version = "1", optional = true }
serde_json = { version = "1", optional = true }

View file

@ -3,6 +3,8 @@ use leptos::*;
use leptos_use::docs::{demo_or_body, BooleanDisplay};
use leptos_use::{use_scroll_with_options, ScrollBehavior, UseScrollOptions, UseScrollReturn};
use web_sys::Event;
#[component]
fn Demo(cx: Scope) -> impl IntoView {
let el = create_node_ref::<Div>(cx);
@ -24,7 +26,18 @@ fn Demo(cx: Scope) -> impl IntoView {
arrived_state,
directions,
..
} = use_scroll_with_options(cx, el, UseScrollOptions::default().behavior(behavior));
} = use_scroll_with_options(
cx,
el,
UseScrollOptions::default()
.behavior(behavior)
.on_stop(move |_: Event| {
log!("scrolling stopped");
})
.on_scroll(move |_: Event| {
log!("scrolling");
}),
);
view! { cx,
<div class="flex">

View file

@ -1,6 +1,6 @@
use crate::core::ElementMaybeSignal;
use crate::use_event_listener::use_event_listener_with_options;
use crate::utils::CloneableFnWithArg;
use crate::utils::CloneableFnMutWithArg;
use crate::{use_debounce_fn_with_arg, use_throttle_fn_with_arg_and_options, ThrottleOptions};
use default_struct_builder::DefaultBuilder;
use leptos::ev::EventDescriptor;
@ -456,12 +456,10 @@ pub struct UseScrollOptions {
offset: ScrollOffset,
/// Callback when scrolling is happening.
#[builder(into)]
on_scroll: Box<dyn CloneableFnWithArg<web_sys::Event>>,
on_scroll: Box<dyn CloneableFnMutWithArg<web_sys::Event> + 'static>,
/// Callback when scrolling stops (after `idle` + `throttle` milliseconds have passed).
#[builder(into)]
on_stop: Box<dyn CloneableFnWithArg<web_sys::Event>>,
on_stop: Box<dyn CloneableFnMutWithArg<web_sys::Event> + 'static>,
/// Options passed to the `addEventListener("scroll", ...)` call
event_listener_options: web_sys::AddEventListenerOptions,