From 402fef7f76f186ea11a37950f6c621844a26f3b6 Mon Sep 17 00:00:00 2001 From: tiye Date: Mon, 29 Jul 2024 20:26:05 +0800 Subject: [PATCH] fix input.value set; tag 0.1.10 --- Cargo.lock | 2 +- respo/Cargo.toml | 2 +- respo/src/app/renderer.rs | 27 ++++++++++++++++----------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af16292..0f6237b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,7 +195,7 @@ dependencies = [ [[package]] name = "respo" -version = "0.1.9" +version = "0.1.10" dependencies = [ "cirru_parser", "js-sys", diff --git a/respo/Cargo.toml b/respo/Cargo.toml index da1351e..87ea7ce 100644 --- a/respo/Cargo.toml +++ b/respo/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "respo" -version = "0.1.9" +version = "0.1.10" edition = "2021" description = "a tiny virtual DOM library migrated from ClojureScript" license = "Apache-2.0" diff --git a/respo/src/app/renderer.rs b/respo/src/app/renderer.rs index fd13885..494d5fa 100644 --- a/respo/src/app/renderer.rs +++ b/respo/src/app/renderer.rs @@ -10,7 +10,7 @@ use std::sync::RwLock; use wasm_bindgen::{JsCast, JsValue}; use web_sys::console::{error_1, warn_1}; -use web_sys::{HtmlElement, HtmlLabelElement, Node}; +use web_sys::{HtmlElement, HtmlLabelElement, HtmlTextAreaElement, Node}; use crate::app::diff::{collect_effects_outside_in_as, diff_tree}; use crate::app::patch::{attach_event, patch_tree}; @@ -240,16 +240,21 @@ where let element = document.create_element(name)?; for (key, value) in attrs { let key = key.as_ref(); - if key == "style" { - warn_1(&"style is handled outside attrs".into()); - } else if key == "innerText" { - element.dyn_ref::().expect("into html element").set_inner_text(value); - } else if key == "innerHTML" { - element.set_inner_html(value); - } else if key == "htmlFor" { - element.dyn_ref::().ok_or("to label element")?.set_html_for(value); - } else { - element.set_attribute(key, value)?; + match key { + "style" => warn_1(&"style is handled outside attrs".into()), + "innerText" => element.dyn_ref::().expect("into html element").set_inner_text(value), + "innerHTML" => element.set_inner_html(value), + "htmlFor" => element + .dyn_ref::() + .expect("into label element") + .set_html_for(value), + "value" if &**name == "textarea" || &**name == "input" => element + .dyn_ref::() + .expect("into html element") + .set_value(value), + _ => { + element.set_attribute(key, value)?; + } } } if !style.is_empty() {