JSFiddle - React, Tailwind, and code Playground
HTML
<p contenteditable="true">Test thing</p>
JavaScript
//what I think Facebook is doing
function addListener() {
document.querySelector("p").addEventListener("keydown", e => {
if(e.key == "Enter") {
var oldText = document.querySelector("p").innerText;
document.querySelector("p").remove();
var newElement = document.createElement("p");
newElement.setAttribute("contenteditable", true);
newElement.innerText = oldText;
document.body.appendChild(newElement);
addListener();
}
});
}
addListener();
//my code
document.querySelector("p").addEventListener("keydown", e => {
console.log(e.key);
});