Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 896306c

Browse files
authored
Merge pull request #33 from DioxusLabs/fix/disable-editing-when-completed-todomvc
fix: Disable editing when task is completed in todomvc example
2 parents fbf0636 + 77d1fec commit 896306c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
Cargo.lock
3+
dist

todomvc/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,20 @@ pub fn todo_entry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
118118

119119
let todos = cx.props.set_todos.read();
120120
let todo = &todos[&cx.props.id];
121-
let completed = if todo.checked { "completed" } else { "" };
121+
let is_checked = todo.checked;
122+
let completed = if is_checked { "completed" } else { "" };
122123
let is_editing = (**editing).then_some("editing").unwrap_or_default();
123124

124125
render!(li {
125126
class: "{completed} {is_editing}",
126-
onclick: move |_| editing.set(true),
127+
onclick: move |_| {
128+
if !is_checked {
129+
editing.set(true)
130+
}
131+
},
127132
onfocusout: move |_| editing.set(false),
128133
div { class: "view",
129-
input { class: "toggle", r#type: "checkbox", id: "cbg-{todo.id}", checked: "{todo.checked}",
134+
input { class: "toggle", r#type: "checkbox", id: "cbg-{todo.id}", checked: "{is_checked}",
130135
onchange: move |evt| {
131136
cx.props.set_todos.write()[&cx.props.id].checked = evt.value.parse().unwrap();
132137
}

0 commit comments

Comments
 (0)