diff --git a/Cargo.lock b/Cargo.lock index f4c7c99..e60f01b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,7 +195,7 @@ dependencies = [ [[package]] name = "respo" -version = "0.1.11" +version = "0.1.12" dependencies = [ "cirru_parser", "js-sys", diff --git a/respo/Cargo.toml b/respo/Cargo.toml index 4128ea6..aef374b 100644 --- a/respo/Cargo.toml +++ b/respo/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "respo" -version = "0.1.11" +version = "0.1.12" edition = "2021" description = "a tiny virtual DOM library migrated from ClojureScript" license = "Apache-2.0" diff --git a/respo/src/app/patch.rs b/respo/src/app/patch.rs index b5878dc..1e42d86 100644 --- a/respo/src/app/patch.rs +++ b/respo/src/app/patch.rs @@ -13,6 +13,7 @@ use web_sys::console::warn_1; use crate::node::{RespoComponent, RespoEffectType, RespoEvent, RespoEventMark, RespoEventMarkFn, RespoNode}; use super::renderer::load_coord_target_tree; +use super::util; use crate::node::dom_change::{ChildDomOp, DomChange, RespoCoord}; use crate::app::renderer::build_dom_tree; @@ -386,11 +387,25 @@ pub fn attach_event(element: &Element, key: &str, coord: &[RespoCoord], handle_e .run(RespoEventMark::new("change", &coord, wrap_event)) .expect("handle change event"); }) as Box); - element - .dyn_ref::() - .expect("convert to html input element") - .set_onchange(Some(handler.as_ref().unchecked_ref())); - handler.forget(); + match element.tag_name().as_str() { + "INPUT" => { + element + .dyn_ref::() + .expect("convert to html input element") + .set_onchange(Some(handler.as_ref().unchecked_ref())); + handler.forget(); + } + "TEXTAREA" => { + element + .dyn_ref::() + .expect("convert to html input element") + .set_onchange(Some(handler.as_ref().unchecked_ref())); + handler.forget(); + } + _ => { + util::warn_log!("not handled change event for element: {}", element.tag_name()); + } + } } "keydown" => { let handler = Closure::wrap(Box::new(move |e: KeyboardEvent| { @@ -409,11 +424,26 @@ pub fn attach_event(element: &Element, key: &str, coord: &[RespoCoord], handle_e .run(RespoEventMark::new("keydown", &coord, wrap_event)) .expect("handle keydown event"); }) as Box); - element - .dyn_ref::() - .expect("convert to html input element") - .set_onkeydown(Some(handler.as_ref().unchecked_ref())); - handler.forget(); + + match element.tag_name().as_str() { + "INPUT" => { + element + .dyn_ref::() + .expect("convert to html input element") + .set_onkeydown(Some(handler.as_ref().unchecked_ref())); + handler.forget(); + } + "TEXTAREA" => { + element + .dyn_ref::() + .expect("convert to html input element") + .set_onkeydown(Some(handler.as_ref().unchecked_ref())); + handler.forget(); + } + _ => { + util::warn_log!("not handled keydown event for element: {}", element.tag_name()); + } + } } "keyup" => { let handler = Closure::wrap(Box::new(move |e: KeyboardEvent| { @@ -431,11 +461,25 @@ pub fn attach_event(element: &Element, key: &str, coord: &[RespoCoord], handle_e .run(RespoEventMark::new("keyup", &coord, wrap_event)) .expect("handle keyup event"); }) as Box); - element - .dyn_ref::() - .expect("convert to html input element") - .set_onkeyup(Some(handler.as_ref().unchecked_ref())); - handler.forget(); + match element.tag_name().as_str() { + "INPUT" => { + element + .dyn_ref::() + .expect("convert to html input element") + .set_onkeyup(Some(handler.as_ref().unchecked_ref())); + handler.forget(); + } + "TEXTAREA" => { + element + .dyn_ref::() + .expect("convert to html input element") + .set_onkeyup(Some(handler.as_ref().unchecked_ref())); + handler.forget(); + } + _ => { + util::warn_log!("not handled keyup event for element: {}", element.tag_name()); + } + } } "keypress" => { let handler = Closure::wrap(Box::new(move |e: KeyboardEvent| { @@ -453,11 +497,25 @@ pub fn attach_event(element: &Element, key: &str, coord: &[RespoCoord], handle_e .run(RespoEventMark::new("keypress", &coord, wrap_event)) .expect("handle keypress event"); }) as Box); - element - .dyn_ref::() - .expect("convert to html input element") - .set_onkeypress(Some(handler.as_ref().unchecked_ref())); - handler.forget(); + match element.tag_name().as_str() { + "INPUT" => { + element + .dyn_ref::() + .expect("convert to html input element") + .set_onkeypress(Some(handler.as_ref().unchecked_ref())); + handler.forget(); + } + "TEXTAREA" => { + element + .dyn_ref::() + .expect("convert to html input element") + .set_onkeypress(Some(handler.as_ref().unchecked_ref())); + handler.forget(); + } + _ => { + util::warn_log!("not handled keypress event for element: {}", element.tag_name()); + } + } } "focus" => { let handler = Closure::wrap(Box::new(move |e: FocusEvent| {