From a60b4025a14e28c2135f8a9be430ea6e5ad9ed67 Mon Sep 17 00:00:00 2001 From: navedqb <109583873+navedqb@users.noreply.github.com> Date: Tue, 17 Dec 2024 05:30:03 +0530 Subject: [PATCH] fix: Resolve issue where Select All moves only half of the items (#17030) --- packages/primeng/src/picklist/picklist.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/primeng/src/picklist/picklist.ts b/packages/primeng/src/picklist/picklist.ts index f9f99ffa92f..166ec91f576 100755 --- a/packages/primeng/src/picklist/picklist.ts +++ b/packages/primeng/src/picklist/picklist.ts @@ -1318,8 +1318,9 @@ export class PickList extends BaseComponent implements AfterViewChecked, AfterCo moveRight() { if (this.selectedItemsSource && this.selectedItemsSource.length) { - for (let i = 0; i < this.selectedItemsSource.length; i++) { - let selectedItem = this.selectedItemsSource[i]; + let itemsToMove = [...this.selectedItemsSource]; + for (let i = 0; i < itemsToMove.length; i++) { + let selectedItem = itemsToMove[i]; if (findIndexInList(selectedItem, this.target) == -1) { this.target?.push(this.source?.splice(findIndexInList(selectedItem, this.source), 1)[0]); @@ -1330,13 +1331,14 @@ export class PickList extends BaseComponent implements AfterViewChecked, AfterCo } this.onMoveToTarget.emit({ - items: this.selectedItemsSource + items: itemsToMove }); if (this.keepSelection) { - this.selectedItemsTarget = [...this.selectedItemsTarget, ...this.selectedItemsSource]; + this.selectedItemsTarget = [...this.selectedItemsTarget, ...itemsToMove]; } + itemsToMove = []; this.selectedItemsSource = []; if (this.filterValueTarget) { @@ -1379,8 +1381,9 @@ export class PickList extends BaseComponent implements AfterViewChecked, AfterCo moveLeft() { if (this.selectedItemsTarget && this.selectedItemsTarget.length) { - for (let i = 0; i < this.selectedItemsTarget.length; i++) { - let selectedItem = this.selectedItemsTarget[i]; + let itemsToMove = [...this.selectedItemsTarget]; + for (let i = 0; i < itemsToMove.length; i++) { + let selectedItem = itemsToMove[i]; if (findIndexInList(selectedItem, this.source) == -1) { this.source?.push(this.target?.splice(findIndexInList(selectedItem, this.target), 1)[0]); @@ -1391,13 +1394,14 @@ export class PickList extends BaseComponent implements AfterViewChecked, AfterCo } this.onMoveToSource.emit({ - items: this.selectedItemsTarget + items: itemsToMove }); if (this.keepSelection) { - this.selectedItemsSource = [...this.selectedItemsSource, ...this.selectedItemsTarget]; + this.selectedItemsSource = [...this.selectedItemsSource, itemsToMove]; } + itemsToMove = []; this.selectedItemsTarget = []; if (this.filterValueSource) {