FIX: don't reset open state on details tag when morphing (#702)

This commit is contained in:
Régis Hanol 2024-07-05 00:07:28 +02:00 committed by GitHub
parent 442681a3d3
commit d555f18c6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 7 deletions

View File

@ -67,6 +67,12 @@ class StreamUpdater {
} }
class PostUpdater extends StreamUpdater { class PostUpdater extends StreamUpdater {
morphingOptions = {
beforeAttributeUpdated: (element, attributeName) => {
return !(element.tagName === "DETAILS" && attributeName === "open");
},
};
constructor(postStream, postId) { constructor(postStream, postId) {
super(); super();
this.postStream = postStream; this.postStream = postStream;
@ -116,13 +122,11 @@ class PostUpdater extends StreamUpdater {
async setCooked(value) { async setCooked(value) {
this.post.set("cooked", value); this.post.set("cooked", value);
const oldElement = this.postElement.querySelector(".cooked"); (await loadMorphlex()).morphInner(
this.postElement.querySelector(".cooked"),
// TODO: use `morphInner` once version morphlex 0.0.16 is out `<div>${value}</div>`,
const newElement = oldElement.cloneNode(false); this.morphingOptions
newElement.innerHTML = value; );
(await loadMorphlex()).morph(oldElement, newElement);
} }
get raw() { get raw() {