Skip to content

Commit 2cf68db

Browse files
committed
[delta_q] properly initialise popup input fields
1 parent 452a350 commit 2cf68db

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

delta_q/src/render.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ pub fn name_component(props: &NameProps) -> Html {
118118
}
119119
));
120120

121+
use_effect_with(
122+
popup.clone(),
123+
cloned!(new_name, name; move |popup| {
124+
if **popup {
125+
new_name.set(name.clone());
126+
}
127+
}),
128+
);
129+
121130
html! {
122131
<div class={classes!("name", "anchor")} onclick={cloned!(popup; move |_| if !*popup { popup.set(true) })}>
123132
{ &props.name }
@@ -330,10 +339,16 @@ pub fn branch_kind_component(props: &BranchProps) -> Html {
330339

331340
let top_frac = use_state(|| props.kind.choice_frac().0);
332341
let bottom_frac = use_state(|| props.kind.choice_frac().1);
333-
let top_input = Callback::from(cloned!(top_frac;
334-
move |e: InputEvent| top_frac.set(e.target_unchecked_into::<HtmlInputElement>().value_as_number() as f32)));
335-
let bottom_input = Callback::from(cloned!(bottom_frac;
336-
move |e: InputEvent| bottom_frac.set(e.target_unchecked_into::<HtmlInputElement>().value_as_number() as f32)));
342+
let top_input = Callback::from(cloned!(top_frac; move |e: InputEvent| {
343+
if let Ok(f) = e.target_unchecked_into::<HtmlInputElement>().value().parse::<f32>() {
344+
top_frac.set(f);
345+
}
346+
}));
347+
let bottom_input = Callback::from(cloned!(bottom_frac; move |e: InputEvent| {
348+
if let Ok(f) = e.target_unchecked_into::<HtmlInputElement>().value().parse::<f32>() {
349+
bottom_frac.set(f);
350+
}
351+
}));
337352
let frac_submit = Callback::from(
338353
cloned!(popup, on_change, top, bottom, top_frac, bottom_frac, ctx;
339354
move |e: SubmitEvent| {
@@ -343,6 +358,17 @@ pub fn branch_kind_component(props: &BranchProps) -> Html {
343358
}),
344359
);
345360

361+
let choices = props.kind.choice_frac();
362+
use_effect_with(
363+
popup.clone(),
364+
cloned!(top_frac, bottom_frac; move |popup| {
365+
if **popup {
366+
top_frac.set(choices.0);
367+
bottom_frac.set(choices.1);
368+
}
369+
}),
370+
);
371+
346372
let abstract_name = use_state(|| "".to_string());
347373
let abstract_input = Callback::from(cloned!(abstract_name;
348374
move |e: InputEvent| abstract_name.set(e.target_unchecked_into::<HtmlInputElement>().value())));

0 commit comments

Comments
 (0)