fix(select): sync values with async option contents

This commit is contained in:
Thijs Louisse 2022-07-05 16:31:44 +02:00 committed by Thijs Louisse
parent bd24f82cc3
commit 853c517ec0

View file

@ -60,6 +60,19 @@ export class LionSelect extends LionFieldWithSelect {
connectedCallback() {
super.connectedCallback();
this._inputNode.addEventListener('change', this._proxyChangeEvent);
this.__selectObserver = new MutationObserver(() => {
this._syncValueUpwards();
// We need to force computation of other values in case model didn't change
// TODO: consider bringing this generically in FormatMixin._syncValueUpwards
this._calculateValues({ source: 'model' });
});
this.__selectObserver.observe(this._inputNode, {
attributes: true,
childList: true,
subtree: true,
});
}
/** @param {import('lit').PropertyValues } changedProperties */
@ -82,6 +95,7 @@ export class LionSelect extends LionFieldWithSelect {
disconnectedCallback() {
super.disconnectedCallback();
this._inputNode.removeEventListener('change', this._proxyChangeEvent);
this.__selectObserver?.disconnect();
}
/**