Skip to content

Commit

Permalink
fix(select): ajustement mutationObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
aesteves60 committed Oct 12, 2023
1 parent 24ea3ca commit 355f6e5
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class OsdsSelect implements OdsSelectAttribute, OdsSelectEvent, OdsSelect
/** is the select was touched by the user */
dirty = false;
selectedLabelSlot: HTMLElement | null = null;
observer?: MutationObserver = undefined;
observer?: MutationObserver;

@Element() el!: HTMLStencilElement;

Expand Down Expand Up @@ -118,13 +118,9 @@ export class OsdsSelect implements OdsSelectAttribute, OdsSelectEvent, OdsSelect
* in order to synchronize the already set value with the placeholder
*/
async componentDidLoad() {
this.observer = new MutationObserver(async () => this.selectedOptionLabel = await this.optionSelected?.getLabel() || '');
this.setSelectOptions();
await this.updateSelectOptionStates(this.value);
this.observer = new MutationObserver(async () => this.selectedOptionLabel = await this.optionSelected?.getLabel() || '');
if (!this.controller.selectOptions[0]) {
return;
}
this.observer?.observe(this.controller.selectOptions[0], { childList: true });
}

@Watch('opened')
Expand Down Expand Up @@ -287,6 +283,7 @@ export class OsdsSelect implements OdsSelectAttribute, OdsSelectEvent, OdsSelect

setSelectOptions() {
this.controller.selectOptions = this.getSelectOptionList();
this.controller.selectOptions.forEach((option) => this.observer?.observe(option, { childList: true }))
}

getSelectOptionList(): (HTMLElement & OsdsSelectOption)[] {
Expand Down

0 comments on commit 355f6e5

Please sign in to comment.