Skip to content

Commit de3c37a

Browse files
authored
allow for late coming elements (#1011)
1 parent 5e857de commit de3c37a

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

packages/uui-combobox/lib/uui-combobox.element.ts

+24-13
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
3434
return super.value;
3535
}
3636
set value(newValue) {
37+
super.value = newValue;
38+
3739
if (typeof newValue === 'string') {
38-
this.#updateValue(newValue);
40+
this.#updateValue();
3941
}
40-
41-
super.value = newValue;
4242
}
4343

4444
/**
@@ -166,7 +166,17 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
166166
this.#phoneMediaQuery.removeEventListener('change', this.#onPhoneChange);
167167
}
168168

169-
protected async firstUpdated() {
169+
#onSlotChange() {
170+
if (this.#comboboxList) {
171+
this.#comboboxList.removeEventListener(
172+
UUIComboboxListEvent.CHANGE,
173+
this.#onChange,
174+
);
175+
this.#comboboxList.removeEventListener(
176+
UUIComboboxListEvent.INNER_SLOT_CHANGE,
177+
this.#onInnerSlotChange,
178+
);
179+
}
170180
const list = this._comboboxListElements?.[0];
171181

172182
if (list) {
@@ -178,21 +188,22 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
178188
);
179189
this.#comboboxList.addEventListener(
180190
UUIComboboxListEvent.INNER_SLOT_CHANGE,
181-
this.#onSlotChange,
191+
this.#onInnerSlotChange,
182192
);
183-
184-
await this.updateComplete;
185-
this.#updateValue(this.value);
186193
}
194+
195+
this.updateComplete.then(() => {
196+
this.#updateValue();
197+
});
187198
}
188199

189200
#onPhoneChange = () => {
190201
this._isPhone = this.#phoneMediaQuery.matches;
191202
};
192203

193-
#updateValue(value: FormDataEntryValue | FormData) {
204+
#updateValue() {
194205
if (this.#comboboxList) {
195-
this.#comboboxList.value = value;
206+
this.#comboboxList.value = this.value;
196207
requestAnimationFrame(
197208
() => (this._displayValue = this.#comboboxList.displayValue || ''),
198209
);
@@ -233,9 +244,9 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
233244
this.#onOpen();
234245
};
235246

236-
#onSlotChange = () => {
247+
#onInnerSlotChange = () => {
237248
if (this.value && this.value !== this.#comboboxList?.value) {
238-
this.#updateValue(this.value);
249+
this.#updateValue();
239250
}
240251
};
241252

@@ -344,7 +355,7 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
344355
#renderDropdown = () => {
345356
return html`<div id="dropdown">
346357
<uui-scroll-container tabindex="-1" id="scroll-container">
347-
<slot></slot>
358+
<slot @slotchange=${this.#onSlotChange}></slot>
348359
</uui-scroll-container>
349360
</div>`;
350361
};

0 commit comments

Comments
 (0)