contentedtiable elements.
See original GitHub issueconst choo = require('choo')
const app = choo()
app.model({
state: { title: 'Set the title' },
reducers: {
update: (action, state) => ({ title: action.value })
}
})
const mainView = (params, state, send) => choo.view`
<main>
<h1>${state.title}</h1>
<div
contenteditable="true"
oninput=${(e) => send('update', { value: e.target.value })}>Type here</div>
</main>
`
app.router((route) => [
route('/', mainView)
])
const tree = app.start()
document.body.appendChild(tree)
Doesn’t update the state, missing something?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
contenteditable - HTML: HyperText Markup Language | MDN
Chrome Edge
contenteditable Full support. ChromeYes. Toggle history Full suppo...
contenteditable="caret". Experimental Full support. ChromeYes. Toggle history Full suppo...
contenteditable="events". Experimental Full support. ChromeYes. Toggle history...
Read more >HTML DOM Element contentEditable Property
The contentEditable property sets or returns if the content of an element is editable. See Also. The isContentEditable Property · The HTML contenteditable...
Read more >HTML contenteditable Attribute
The HTML contenteditable attribute is used to specify whether or not the content of an element is editable. You can use this attribute...
Read more >How to make your content editable in HTML
To edit the content in HTML, we will use contenteditable attribute. The contenteditable is used to specify whether the element's content is ...
Read more >HTML contenteditable Attribute
The contenteditable attribute in HTML is used to set whether the content is editable or not using boolean values true or false. This...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This works:
The reason is that you’re sending the value of the
<div>
but not changing it. Every call tooninput
causes the DOM to update based on the current value of the state.So you delete the
type here
and it sends an oninput withe.target.innerText
equal to''
, and updates the state. Then it re-renders. But you haven’t changed what the input value for thecontenteditable
is, so it’s stilltype here
when you go to type in it.You delete, it sends, resets to
type here
, rerenders, etc.You need to track the state in the element which is sending the updates as well since the state is the source of truth, not the DOM.
<div>
s don’t have avalue
property - your looking forinnerText
. Here’s an example of a content editable div in a choo app.