summaryrefslogtreecommitdiffstats
path: root/web/src/widget/text_input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/widget/text_input.rs')
-rw-r--r--web/src/widget/text_input.rs54
1 files changed, 32 insertions, 22 deletions
diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs
index 3fa458bd..0049a553 100644
--- a/web/src/widget/text_input.rs
+++ b/web/src/widget/text_input.rs
@@ -151,8 +151,26 @@ where
use dodrio::builder::*;
use wasm_bindgen::JsCast;
- let padding_class =
- style_sheet.insert(bump, css::Rule::Padding(self.padding));
+ let class = {
+ use dodrio::bumpalo::collections::String;
+
+ let padding_class =
+ style_sheet.insert(bump, css::Rule::Padding(self.padding));
+
+ String::from_str_in(&padding_class, bump).into_bump_str()
+ };
+
+ let placeholder = {
+ use dodrio::bumpalo::collections::String;
+
+ String::from_str_in(&self.placeholder, bump).into_bump_str()
+ };
+
+ let value = {
+ use dodrio::bumpalo::collections::String;
+
+ String::from_str_in(&self.value, bump).into_bump_str()
+ };
let on_change = self.on_change.clone();
let on_submit = self.on_submit.clone();
@@ -161,15 +179,14 @@ where
let style = self.style_sheet.active();
input(bump)
- .attr(
- "class",
- bumpalo::format!(in bump, "{}", padding_class).into_bump_str(),
- )
+ .attr("class", class)
.attr(
"style",
bumpalo::format!(
in bump,
- "width: {}; max-width: {}; font-size: {}px; background: {}; border-width: {}px; border-color: {}; border-radius: {}px; color: {}",
+ "width: {}; max-width: {}; font-size: {}px; \
+ background: {}; border-width: {}px; border-color: {}; \
+ border-radius: {}px; color: {}",
css::length(self.width),
css::max_length(self.max_width),
self.size.unwrap_or(20),
@@ -181,19 +198,9 @@ where
)
.into_bump_str(),
)
- .attr(
- "placeholder",
- bumpalo::format!(in bump, "{}", self.placeholder)
- .into_bump_str(),
- )
- .attr(
- "value",
- bumpalo::format!(in bump, "{}", self.value).into_bump_str(),
- )
- .attr(
- "type",
- bumpalo::format!(in bump, "{}", if self.is_secure { "password" } else { "text" }).into_bump_str(),
- )
+ .attr("placeholder", placeholder)
+ .attr("value", value)
+ .attr("type", if self.is_secure { "password" } else { "text" })
.on("input", move |_root, _vdom, event| {
let text_input = match event.target().and_then(|t| {
t.dyn_into::<web_sys::HtmlInputElement>().ok()
@@ -206,10 +213,13 @@ where
})
.on("keypress", move |_root, _vdom, event| {
if let Some(on_submit) = on_submit.clone() {
- let event = event.unchecked_into::<web_sys::KeyboardEvent>();
+ let event =
+ event.unchecked_into::<web_sys::KeyboardEvent>();
match event.key_code() {
- 13 => { submit_event_bus.publish(on_submit); }
+ 13 => {
+ submit_event_bus.publish(on_submit);
+ }
_ => {}
}
}