diff --git a/examples/parent-child/src/lib.rs b/examples/parent-child/src/lib.rs index fcd9077d9..e647753fc 100644 --- a/examples/parent-child/src/lib.rs +++ b/examples/parent-child/src/lib.rs @@ -1,5 +1,5 @@ use leptos::*; -use web_sys::Event; +use web_sys::MouseEvent; // This highlights four different ways that child components can communicate // with their parent: @@ -71,7 +71,7 @@ pub fn ButtonA(cx: Scope, setter: WriteSignal) -> Element { #[component] pub fn ButtonB(cx: Scope, on_click: F) -> Element where - F: Fn(Event) + 'static, + F: Fn(MouseEvent) + 'static, { view! { cx, @@ -82,11 +82,11 @@ where } - // just a note: in an ordinary function ButtonB could take on_click: impl Fn(Event) + 'static + // just a note: in an ordinary function ButtonB could take on_click: impl Fn(MouseEvent) + 'static // and save you from typing out the generic // the component macro actually expands to define a // - // struct ButtonBProps where F: Fn(Event) + 'static { + // struct ButtonBProps where F: Fn(MouseEvent) + 'static { // on_click: F // } // diff --git a/examples/todomvc/src/lib.rs b/examples/todomvc/src/lib.rs index 0be85d2ff..c0b567efe 100644 --- a/examples/todomvc/src/lib.rs +++ b/examples/todomvc/src/lib.rs @@ -136,10 +136,10 @@ pub fn TodoMVC(cx: Scope) -> Element { }); // Callback to add a todo on pressing the `Enter` key, if the field isn't empty - let add_todo = move |ev: web_sys::Event| { + let add_todo = move |ev: web_sys::KeyboardEvent| { let target = event_target::(&ev); ev.stop_propagation(); - let key_code = ev.unchecked_ref::().key_code(); + let key_code = ev.key_code(); if key_code == ENTER_KEY { let title = event_target_value(&ev); let title = title.trim(); @@ -311,7 +311,7 @@ pub fn Todo(cx: Scope, todo: Todo) -> Element { prop:value={move || todo.title.get()} on:focusout=move |ev| save(&event_target_value(&ev)) on:keyup={move |ev| { - let key_code = ev.unchecked_ref::().key_code(); + let key_code = ev.key_code(); if key_code == ENTER_KEY { save(&event_target_value(&ev)); } else if key_code == ESCAPE_KEY { diff --git a/leptos_dom/src/render_to_string.rs b/leptos_dom/src/render_to_string.rs index b93f9d606..70e188815 100644 --- a/leptos_dom/src/render_to_string.rs +++ b/leptos_dom/src/render_to_string.rs @@ -12,7 +12,7 @@ pub fn escape_attr(text: &str) -> Cow<'_, str> { } cfg_if! { - if #[cfg(any(doc, feature = "ssr"))] { + if #[cfg(not(any(feature = "csr", feature = "hydrate")))] { use leptos_reactive::*; use crate::Element; diff --git a/leptos_macro/src/lib.rs b/leptos_macro/src/lib.rs index be68ba046..c5616b8ce 100644 --- a/leptos_macro/src/lib.rs +++ b/leptos_macro/src/lib.rs @@ -111,14 +111,15 @@ mod server; /// # }); /// ``` /// -/// 5. Event handlers can be added with `on:` attributes. +/// 5. Event handlers can be added with `on:` attributes. In most cases, the events are given the correct type +/// based on the event name. /// ```rust /// # use leptos_reactive::*; use leptos_dom::*; use leptos_macro::view; use leptos_dom::wasm_bindgen::JsCast; /// # run_scope(create_runtime(), |cx| { /// # if !cfg!(any(feature = "csr", feature = "hydrate")) { /// view! { /// cx, -///