Precise DOM morphing
morphing typescript dom
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve attribute selection

+24 -18
+24 -18
src/morphlex.ts
··· 199 199 } 200 200 } 201 201 202 - private morphProperties([element, reference]: PairOfMatchingElements<Element>): void { 202 + private morphProperties([from, to]: PairOfMatchingElements<Element>): void { 203 203 // For certain types of elements, we need to do some extra work to ensure 204 204 // the element’s state matches the reference elements’ state. 205 - if (isInputElement(element) && isInputElement(reference)) { 206 - this.updateProperty(element, "checked", reference.checked) 207 - this.updateProperty(element, "disabled", reference.disabled) 208 - this.updateProperty(element, "indeterminate", reference.indeterminate) 205 + if (isInputElement(from) && isInputElement(to)) { 206 + this.updateProperty(from, "disabled", to.disabled) 207 + 209 208 if ( 210 - element.type !== "file" && 211 - !(this.options.ignoreActiveValue && document.activeElement === element) && 212 - !(this.options.preserveModifiedValues && element.name === reference.name && element.value !== element.defaultValue) 209 + from.type !== "file" && 210 + !(this.options.ignoreActiveValue && document.activeElement === from) && 211 + !(this.options.preserveModifiedValues && from.name === to.name && from.value !== from.defaultValue) 213 212 ) { 214 - this.updateProperty(element, "value", reference.value) 213 + this.updateProperty(from, "value", to.value) 214 + this.updateProperty(from, "checked", to.checked) 215 + this.updateProperty(from, "indeterminate", to.indeterminate) 215 216 } 216 - } else if (isOptionElement(element) && isOptionElement(reference)) { 217 - this.updateProperty(element, "selected", reference.selected) 218 217 } else if ( 219 - isTextAreaElement(element) && 220 - isTextAreaElement(reference) && 221 - !(this.options.ignoreActiveValue && document.activeElement === element) && 222 - !(this.options.preserveModifiedValues && element.name === reference.name && element.value !== element.defaultValue) 218 + isOptionElement(from) && 219 + isOptionElement(to) && 220 + !(this.options.ignoreActiveValue && document.activeElement === from.parentElement) && 221 + !(this.options.preserveModifiedValues && from.defaultSelected !== to.defaultSelected) 222 + ) { 223 + this.updateProperty(from, "selected", to.selected) 224 + } else if ( 225 + isTextAreaElement(from) && 226 + isTextAreaElement(to) && 227 + !(this.options.ignoreActiveValue && document.activeElement === from) && 228 + !(this.options.preserveModifiedValues && from.name === to.name && from.value !== from.defaultValue) 223 229 ) { 224 - this.updateProperty(element, "value", reference.value) 230 + this.updateProperty(from, "value", to.value) 225 231 226 - const text = element.firstElementChild 227 - if (text) this.updateProperty(text, "textContent", reference.value) 232 + const text = from.firstElementChild 233 + if (text) this.updateProperty(text, "textContent", to.value) 228 234 } 229 235 } 230 236