exclude value and id from the settle swap to avoid flicker

This commit is contained in:
carson 2020-06-19 06:29:46 -07:00
parent 2524fcf436
commit 276082f2c2
2 changed files with 17 additions and 2 deletions

View File

@ -334,14 +334,17 @@ return (function () {
}
}
var EXCLUDED_ATTRIBUTES = ['id', 'value'];
function cloneAttributes(mergeTo, mergeFrom) {
forEach(mergeTo.attributes, function (attr) {
if (!mergeFrom.hasAttribute(attr.name)) {
if (!mergeFrom.hasAttribute(attr.name) && EXCLUDED_ATTRIBUTES.indexOf(attr.name) === -1) {
mergeTo.removeAttribute(attr.name)
}
});
forEach(mergeFrom.attributes, function (attr) {
mergeTo.setAttribute(attr.name, attr.value);
if (EXCLUDED_ATTRIBUTES.indexOf(attr.name) === -1) {
mergeTo.setAttribute(attr.name, attr.value);
}
});
}

View File

@ -444,6 +444,7 @@ describe("Core htmx AJAX Tests", function(){
return false;
});
div.click();
this.server.respond();
path.should.not.be.null;
});
@ -456,8 +457,19 @@ describe("Core htmx AJAX Tests", function(){
return false;
});
div.click();
this.server.respond();
path.should.not.be.null;
});
it('input values are not settle swapped (causes flicker)', function()
{
this.server.respondWith("GET", "/test", "<input id='i1' value='bar'/>");
var input = make("<input id='i1' hx-get='/test' value='foo' hx-swap='outerHTML settle:50' hx-trigger='click'/>");
input.click();
this.server.respond();
input = byId('i1');
input.value.should.equal('bar');
});
})