Bug 1427950 - Only use the mutation observer for migrating new option children to the popup. r=jaws
This reduces the side-effects of render (which should ideally be pure) and should improve performance. We already have the mutation observer anyways.
MozReview-Commit-ID: KVhCVEhSvhi
--- a/toolkit/components/payments/res/components/rich-select.js
+++ b/toolkit/components/payments/res/components/rich-select.js
@@ -47,16 +47,22 @@ class RichSelect extends ObservedPropert
childList: true,
});
}
connectedCallback() {
this.tabIndex = 0;
this.appendChild(this.popupBox);
+ // Move options initially placed inside the select to the popup box.
+ let options = this.querySelectorAll(":scope > .rich-option:not(.rich-select-selected-clone)");
+ for (let option of options) {
+ this.popupBox.appendChild(option);
+ }
+
this.render();
}
get selectedOption() {
return this.popupBox.querySelector(":scope > [selected]");
}
@@ -166,21 +172,16 @@ class RichSelect extends ObservedPropert
return false;
}
}
return true;
}
render() {
- let options = this.querySelectorAll(":scope > .rich-option:not(.rich-select-selected-clone)");
- for (let option of options) {
- this.popupBox.appendChild(option);
- }
-
let selectedChild;
for (let child of this.popupBox.children) {
if (child.selected) {
selectedChild = child;
break;
}
}