Skip to content

Commit c3affff

Browse files
authored
fix(list, list-item): ensure change and select events are emitted after state is updated (#11079)
**Related Issue:** #10731 ## Summary Changes `calcite-list` and `calcite-list-item` to wait for their update to be complete before emitting the change and selection events.
1 parent 99789ad commit c3affff

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/calcite-components/src/components/list-item/list-item.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ export class ListItem
578578
this.toggleSelected(event.shiftKey);
579579
}
580580

581-
private toggleSelected(shiftKey: boolean): void {
581+
private async toggleSelected(shiftKey: boolean): Promise<void> {
582582
const { selectionMode, selected } = this;
583583

584584
if (this.disabled) {
@@ -594,6 +594,8 @@ export class ListItem
594594
this.calciteInternalListItemSelectMultiple.emit({
595595
selectMultiple: shiftKey && selectionMode === "multiple",
596596
});
597+
598+
await this.updateComplete;
597599
this.calciteListItemSelect.emit();
598600
}
599601

packages/calcite-components/src/components/list/list.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,9 @@ export class List
654654
}
655655
}
656656

657-
private updateSelectedItems(emit = false): void {
657+
private async updateSelectedItems(emit = false): Promise<void> {
658+
await this.updateComplete;
659+
658660
this.selectedItems = this.visibleItems.filter((item) => item.selected);
659661
if (emit) {
660662
this.calciteListChange.emit();

0 commit comments

Comments
 (0)