Fixing tests and examples
This commit is contained in:
parent
588ebf51a5
commit
6949750668
|
@ -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<bool>) -> Element {
|
|||
#[component]
|
||||
pub fn ButtonB<F>(cx: Scope, on_click: F) -> Element
|
||||
where
|
||||
F: Fn(Event) + 'static,
|
||||
F: Fn(MouseEvent) + 'static,
|
||||
{
|
||||
view! {
|
||||
cx,
|
||||
|
@ -82,11 +82,11 @@ where
|
|||
</button>
|
||||
}
|
||||
|
||||
// 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<F> where F: Fn(Event) + 'static {
|
||||
// struct ButtonBProps<F> where F: Fn(MouseEvent) + 'static {
|
||||
// on_click: F
|
||||
// }
|
||||
//
|
||||
|
|
|
@ -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::<HtmlInputElement>(&ev);
|
||||
ev.stop_propagation();
|
||||
let key_code = ev.unchecked_ref::<web_sys::KeyboardEvent>().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::<web_sys::KeyboardEvent>().key_code();
|
||||
let key_code = ev.key_code();
|
||||
if key_code == ENTER_KEY {
|
||||
save(&event_target_value(&ev));
|
||||
} else if key_code == ESCAPE_KEY {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
/// <button on:click=|ev: web_sys::Event| {
|
||||
/// <button on:click=|ev: web_sys::MouseEvent| {
|
||||
/// log::debug!("click event: {ev:#?}");
|
||||
/// }>
|
||||
/// "Click me"
|
||||
|
@ -203,9 +204,9 @@ mod server;
|
|||
///
|
||||
/// // create event handlers for our buttons
|
||||
/// // note that `value` and `set_value` are `Copy`, so it's super easy to move them into closures
|
||||
/// let clear = move |_ev: web_sys::Event| set_value(0);
|
||||
/// let decrement = move |_ev: web_sys::Event| set_value.update(|value| *value -= 1);
|
||||
/// let increment = move |_ev: web_sys::Event| set_value.update(|value| *value += 1);
|
||||
/// let clear = move |_ev: web_sys::MouseEvent| set_value(0);
|
||||
/// let decrement = move |_ev: web_sys::MouseEvent| set_value.update(|value| *value -= 1);
|
||||
/// let increment = move |_ev: web_sys::MouseEvent| set_value.update(|value| *value += 1);
|
||||
///
|
||||
/// // this JSX is compiled to an HTML template string for performance
|
||||
/// view! {
|
||||
|
|
Loading…
Reference in New Issue