DioxusLabs / DioxusLabs/dioxus
incorrect display in a `div` which has `contenteditable`
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
**Problem**
I want to use a `div` to capture user input. I want to be able to clear the div when a button is pressed. I try to do this by using a UseState to capture and display the user input. I can use `oninput` to capture the input, but if I display that value inside of the div, extra keystrokes are recorded.
**Steps To Reproduce**
Steps to reproduce the behavior:
- minimal reproducible example
```
use dioxus::prelude::*;
use dioxus_html::KeyCode;
fn main() {
dioxus::desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let text = use_state(&cx, || String::from(""));
cx.render(rsx! (
main {
p {
"some text"
}
div {
contenteditable: "true",
"text_align": "left",
onkeypress: move |evt| {
if evt.key_code == KeyCode::Enter {
println!("text submitted: {}", &text);
// fails to update the UI. enter "abcd" and it outputs "abcdabcaba"
text.set(String::from(""));
}
},
// maybe oninput is only supposed to work on input and textarea elements.
oninput: move |evt| {
// doesn't quite work until the content is deleted
text.set(evt.value.clone());
},
// if this next line is commented out, the input no longer contains extra characters. but there's still not a way to clear the text
"{text}"
}
p {
"more text"
}
}
))
}
```
- type "abc" and press Enter
- the console displays "text submitted: abcdabcaba"
**Expected behavior**
- I expect the console to display "text submitted: abc"
**Screenshots**
after inputting "a"

after inputting "ab"

after inputting "abc"

**Environment:**
- Dioxus version: v0.2.4, features = [ "desktop"]
- Rust version:1.64.0
- OS info: pop!_os 22.04
- App platform: desktop
**Questionnaire**
- [ ] I'm interested in fixing this myself but don't know where to start
- [ ] I would like to fix and I have a solution
- [ x ] I don't have time to fix this right now, but maybe later
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.