mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-27 14:40:44 +00:00
Merge pull request #112 from sassman/master
feat(example:todomvc): add editing support
This commit is contained in:
commit
06205e425f
5 changed files with 32 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
|||
html,
|
||||
body {
|
||||
body, pre {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
|
|
@ -116,8 +116,12 @@ pub fn todo_entry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
|
|||
let todo = &cx.props.todos[&cx.props.id];
|
||||
let is_editing = use_state(&cx, || false);
|
||||
let completed = if todo.checked { "completed" } else { "" };
|
||||
let editing = if *is_editing.get() { "editing" } else { "" };
|
||||
|
||||
rsx!(cx, li { class: "{completed}",
|
||||
rsx!(cx, li {
|
||||
class: "{completed} {editing}",
|
||||
onclick: move |_| is_editing.set(true),
|
||||
onfocusout: move |_| is_editing.set(false),
|
||||
div { class: "view",
|
||||
input { class: "toggle", r#type: "checkbox", id: "cbg-{todo.id}", checked: "{todo.checked}",
|
||||
onchange: move |evt| {
|
||||
|
@ -125,12 +129,20 @@ pub fn todo_entry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
|
|||
}
|
||||
}
|
||||
label { r#for: "cbg-{todo.id}", pointer_events: "none", "{todo.contents}" }
|
||||
}
|
||||
is_editing.then(|| rsx!{
|
||||
input {
|
||||
class: "edit",
|
||||
value: "{todo.contents}",
|
||||
oninput: move |evt| cx.props.todos.modify()[&cx.props.id].contents = evt.value.clone(),
|
||||
autofocus: "true",
|
||||
onkeydown: move |evt| {
|
||||
match evt.key.as_str() {
|
||||
"Enter" | "Escape" | "Tab" => is_editing.set(false),
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ fn make_synthetic_event(name: &str, val: serde_json::Value) -> Arc<dyn Any + Sen
|
|||
let evt = serde_json::from_value::<KeyboardData>(val).unwrap();
|
||||
Arc::new(evt)
|
||||
}
|
||||
"focus" | "blur" => {
|
||||
"focus" | "blur" | "focusout" | "focusin" => {
|
||||
//
|
||||
Arc::new(FocusData {})
|
||||
}
|
||||
|
@ -117,6 +117,8 @@ fn event_name_from_typ(typ: &str) -> &'static str {
|
|||
"keypress" => "keypress",
|
||||
"keyup" => "keyup",
|
||||
"focus" => "focus",
|
||||
"focusout" => "focusout",
|
||||
"focusin" => "focusin",
|
||||
"blur" => "blur",
|
||||
"change" => "change",
|
||||
"input" => "input",
|
||||
|
|
|
@ -91,6 +91,12 @@ pub mod on {
|
|||
/// onfocus
|
||||
onfocus
|
||||
|
||||
// onfocusout
|
||||
onfocusout
|
||||
|
||||
// onfocusin
|
||||
onfocusin
|
||||
|
||||
/// onblur
|
||||
onblur
|
||||
];
|
||||
|
@ -1092,7 +1098,7 @@ pub(crate) fn _event_meta(event: &UserEvent) -> (bool, EventPriority) {
|
|||
"keydown" | "keypress" | "keyup" => (true, High),
|
||||
|
||||
// Focus
|
||||
"focus" | "blur" => (true, Low),
|
||||
"focus" | "blur" | "focusout" | "focusin" => (true, Low),
|
||||
|
||||
// Form
|
||||
"change" | "input" | "invalid" | "reset" | "submit" => (true, Medium),
|
||||
|
|
|
@ -203,6 +203,8 @@ pub static BUILTIN_INTERNED_STRINGS: &[&'static str] = &[
|
|||
"onended",
|
||||
"onerror",
|
||||
"onfocus",
|
||||
"onfocusout",
|
||||
"onfocusin",
|
||||
"onhashchange",
|
||||
"oninput",
|
||||
"oninvalid",
|
||||
|
|
Loading…
Reference in a new issue