diff --git a/src/liquid/components/ld-select/ld-select.tsx b/src/liquid/components/ld-select/ld-select.tsx index f8214495bd..1a8eb9872a 100644 --- a/src/liquid/components/ld-select/ld-select.tsx +++ b/src/liquid/components/ld-select/ld-select.tsx @@ -103,7 +103,6 @@ export class LdSelect { @State() hasMore = false @State() hasCustomIcon = false @State() renderHiddenInput = false - @State() ignoreSlotChanges = false @Watch('selected') emitEventsAndUpdateHidden( @@ -335,11 +334,6 @@ export class LdSelect { } private initOptions() { - this.ignoreSlotChanges = true - setTimeout(() => { - this.ignoreSlotChanges = false - }) - const initialized = this.initialized let children if (!initialized) { @@ -387,8 +381,8 @@ export class LdSelect { } this.internalOptionsHTML = internalOptionsHTML } - this.selected = selectedChildren.map((child) => ({ - value: child.getAttribute('value'), + this.selected = selectedChildren.map((child: HTMLLdOptionElement) => ({ + value: child.value, text: child.innerText, })) @@ -432,8 +426,6 @@ export class LdSelect { } private handleSlotChange(mutationsList: MutationRecord[]) { - if (this.ignoreSlotChanges) return - if ( mutationsList.some( (record) => (record.target as HTMLElement).tagName !== 'LD-OPTION' diff --git a/src/liquid/components/ld-select/test/__snapshots__/ld-select.spec.ts.snap b/src/liquid/components/ld-select/test/__snapshots__/ld-select.spec.ts.snap index e96e6e3992..05ab2be132 100644 --- a/src/liquid/components/ld-select/test/__snapshots__/ld-select.spec.ts.snap +++ b/src/liquid/components/ld-select/test/__snapshots__/ld-select.spec.ts.snap @@ -77,7 +77,107 @@ exports[`ld-select creates hidden input field, if inside a form 1`] = ` `; -exports[`ld-select fills hidden input fields with initially selected option values 1`] = ` +exports[`ld-select observes slot content changes and updates internal options in popper and hidden input fields 1`] = ` +
+ + +`; + +exports[`ld-select renders initially selected options as internal options and hidden input fields 1`] = `