mirror of
https://github.com/yewstack/yew.git
synced 2026-01-25 16:43:15 +00:00
Fix TodoMVC example bugs (#1468)
This commit is contained in:
parent
e1bffa7e19
commit
fbda559e2b
@ -104,6 +104,7 @@ impl Component for Model {
|
||||
}
|
||||
Msg::ToggleEdit(idx) => {
|
||||
self.state.edit_value = self.state.entries[idx].description.clone();
|
||||
self.state.clear_all_edit();
|
||||
self.state.toggle_edit(idx);
|
||||
}
|
||||
Msg::ToggleAll => {
|
||||
@ -229,7 +230,7 @@ impl Model {
|
||||
html! {
|
||||
<input class="edit"
|
||||
type="text"
|
||||
value=&entry.description
|
||||
value=&self.state.edit_value
|
||||
oninput=self.link.callback(|e: InputData| Msg::UpdateEdit(e.value))
|
||||
onblur=self.link.callback(move |_| Msg::Edit(idx))
|
||||
onkeypress=self.link.callback(move |e: KeyboardEvent| {
|
||||
@ -334,6 +335,11 @@ impl State {
|
||||
entry.editing = !entry.editing;
|
||||
}
|
||||
|
||||
fn clear_all_edit(&mut self) {
|
||||
for entry in self.entries.iter_mut() {
|
||||
entry.editing = false;
|
||||
}
|
||||
}
|
||||
fn complete_edit(&mut self, idx: usize, val: String) {
|
||||
let filter = self.filter.clone();
|
||||
let mut entries = self
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user