idiomorph
idiomorph copied to clipboard
How preserve attributes values?
How preserve attribute values missed from new content? For example:
let details1 = make('<details open><summary>Details1</summary>Something</details>')
let details2 = make('<details><summary>Details2</summary>Something</details>')
Idiomorph.morph(details1, details2);
should.equal(null, details2.getAttribute("open"));
details1.getAttribute("open").should.equal("");
I want that details1 have openattribute and the content of details2
Did you try with options { morphStyle: 'innerHTML' }?
the new content doesn't have the open attribute so it's being removed. if you want to preserve it you can either do an innerHTML morph, as @genezys suggests, or you can register a beforeAttributeUpdated function and return false if the attribute is named open:
https://github.com/bigskysoftware/idiomorph/blob/65f32e578340b78e2deb8e9ec8ae3f86d066044d/src/idiomorph.js#L130C17-L130C39