fix(turbo morph): make the morph morph again
This commit is contained in:
parent
1ebf7e2d9d
commit
4e082d6424
1 changed files with 13 additions and 2 deletions
|
@ -38,8 +38,19 @@ const enable: TurboStreamAction = function () {
|
|||
};
|
||||
const morph: TurboStreamAction = function () {
|
||||
this.targetElements.forEach((element: Element) => {
|
||||
morphdom(element, this.templateContent, {
|
||||
onBeforeElUpdated(fromEl, toEl) {
|
||||
let content: Element | DocumentFragment = this.templateContent;
|
||||
|
||||
// content.children ignores text node, the empty text nodes in particular
|
||||
// so if templateContent contains an empty text node,
|
||||
// we only keep the first element and happily morph it
|
||||
if (content.children.length == 1) {
|
||||
content = content.children[0];
|
||||
}
|
||||
|
||||
// morphom morphes if content is an element
|
||||
// swaps if content if a documentFragment
|
||||
morphdom(element, content, {
|
||||
onBeforeElUpdated: function (fromEl, toEl) {
|
||||
if (isTouchedInput(fromEl)) {
|
||||
fromEl.removeAttribute('data-touched');
|
||||
mergeInputValue(fromEl as HTMLInputElement, toEl as HTMLInputElement);
|
||||
|
|
Loading…
Reference in a new issue