diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 4158dc7..f9ee643 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -21,6 +21,7 @@ send_wrapper = "0.6" console_error_panic_hook = "0.1.7" console_log = "1" log = "0.4" +js-sys = "0.3.70" [features] default = ["csr"] diff --git a/demo/src/app.rs b/demo/src/app.rs index b763c09..5351827 100644 --- a/demo/src/app.rs +++ b/demo/src/app.rs @@ -58,60 +58,62 @@ fn TheRouter() -> impl IntoView { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {view!{ + + + + + + + + + + + + + + + }.into_inner()} + {view!{ + + + + + + + + + + + + + + + + + }.into_inner()} + {view!{ + + + + + + + + + + + + + + + + + }.into_inner()} + {view!{ + + + }.into_inner()} diff --git a/demo/src/components/site_header.rs b/demo/src/components/site_header.rs index 57dcee7..ecdf7b7 100644 --- a/demo/src/components/site_header.rs +++ b/demo/src/components/site_header.rs @@ -77,14 +77,17 @@ pub fn SiteHeader() -> impl IntoView { #[cfg(any(feature = "csr", feature = "hydrate"))] { use leptos::ev; - let handle = window_event_listener(ev::keydown, move |event| { - let key = event.key(); - if key == *"/" { - if let Some(auto_complete_ref) = auto_complete_ref.get_untracked() { - event.prevent_default(); - auto_complete_ref.focus(); + let handle = window_event_listener(ev::keydown, move |e| { + if js_sys::Reflect::has(&e, &js_sys::wasm_bindgen::JsValue::from_str("key")).unwrap_or_default() { + let key = e.key(); + if key == *"/" { + if let Some(auto_complete_ref) = auto_complete_ref.get_untracked() { + e.prevent_default(); + auto_complete_ref.focus(); + } } } + }); on_cleanup(move || handle.remove()); }