idiomorph icon indicating copy to clipboard operation
idiomorph copied to clipboard

How preserve attributes values?

Open dannluciano opened this issue 1 year ago • 1 comments

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

dannluciano avatar Jul 11 '24 23:07 dannluciano

Did you try with options { morphStyle: 'innerHTML' }?

genezys avatar Jul 19 '24 19:07 genezys

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

1cg avatar Dec 18 '24 01:12 1cg