From b870e00ae112ca6e411925ae2b04d17c27552c9a Mon Sep 17 00:00:00 2001 From: elian Date: Mon, 18 Mar 2024 00:40:54 +0100 Subject: [PATCH 1/2] fixed bug where unselecting a selected item would remove it from the list completely --- src/app/components/picklist/picklist.ts | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/app/components/picklist/picklist.ts b/src/app/components/picklist/picklist.ts index b4e24350d34..0af74f75951 100755 --- a/src/app/components/picklist/picklist.ts +++ b/src/app/components/picklist/picklist.ts @@ -168,7 +168,7 @@ import { [ngClass]="itemClass(item, idSource + '_' + i, selectedItemsSource)" [cdkDragData]="item" [cdkDragDisabled]="!dragdrop" - (click)="onItemClick($event, item, selectedItemsSource, onSourceSelect, idSource + '_' + i)" + (click)="onItemClick($event, item, selectedItemsSource, SOURCE_LIST, onSourceSelect, idSource + '_' + i)" (mousedown)="onOptionMouseDown(i, SOURCE_LIST)" (dblclick)="onSourceItemDblClick()" (touchend)="onItemTouchEnd()" @@ -276,7 +276,7 @@ import { [ngClass]="itemClass(item, idTarget + '_' + i, selectedItemsTarget)" [cdkDragData]="item" [cdkDragDisabled]="!dragdrop" - (click)="onItemClick($event, item, selectedItemsTarget, onTargetSelect, idTarget + '_' + i)" + (click)="onItemClick($event, item, selectedItemsTarget, TARGET_LIST, onTargetSelect, idTarget + '_' + i)" (mousedown)="onOptionMouseDown(i, TARGET_LIST)" (dblclick)="onTargetItemDblClick()" (touchend)="onItemTouchEnd()" @@ -915,7 +915,7 @@ export class PickList implements AfterViewChecked, AfterContentInit { } } - onItemClick(event: Event | any, item: any, selectedItems: any[], callback: EventEmitter, itemId?: string) { + onItemClick(event: Event | any, item: any, selectedItems: any[], listType: number, callback: EventEmitter, itemId?: string) { if (this.disabled) { return; } @@ -929,18 +929,21 @@ export class PickList implements AfterViewChecked, AfterContentInit { let metaKey = (event).metaKey || (event).ctrlKey || (event).shiftKey; if (selected && metaKey) { - selectedItems.splice(index, 1); + selectedItems = selectedItems.filter((_, i) => i !== index); } else { if (!metaKey) { - selectedItems.length = 0; + selectedItems = []; } selectedItems.push(item); } } else { - if (selected) selectedItems.splice(index, 1); - else selectedItems.push(item); + if (selected) { + selectedItems = selectedItems.filter((_, i) => i !== index); // Creating a new array without the selected item + } else { + selectedItems.push(item); + } } - + this.setSelectionList(listType, selectedItems); callback.emit({ originalEvent: event, items: selectedItems }); this.itemTouched = false; @@ -1399,7 +1402,7 @@ export class PickList implements AfterViewChecked, AfterContentInit { break; case 'Enter': - this.onEnterKey(event, selectedItems, callback); + this.onEnterKey(event, selectedItems, callback, listType); break; case 'Space': @@ -1453,7 +1456,7 @@ export class PickList implements AfterViewChecked, AfterContentInit { this.changeFocusedOptionIndex(optionIndex, listType); if (event.shiftKey) { - this.onEnterKey(event, selectedItems, callback); + this.onEnterKey(event, selectedItems, callback, listType); } event.preventDefault(); @@ -1465,14 +1468,14 @@ export class PickList implements AfterViewChecked, AfterContentInit { this.changeFocusedOptionIndex(optionIndex, listType); if (event.shiftKey) { - this.onEnterKey(event, selectedItems, callback); + this.onEnterKey(event, selectedItems, callback, listType); } event.preventDefault(); } - onEnterKey(event: Event | any, selectedItems: any[], callback: EventEmitter) { - this.onItemClick(event, this.focusedOption, selectedItems, callback); + onEnterKey(event: Event | any, selectedItems: any[], callback: EventEmitter, listType: number) { + this.onItemClick(event, this.focusedOption, selectedItems, listType, callback); event.preventDefault(); } @@ -1494,7 +1497,7 @@ export class PickList implements AfterViewChecked, AfterContentInit { } } - this.onEnterKey(event, selectedItems, callback); + this.onEnterKey(event, selectedItems, callback, listType); } onHomeKey(event: Event | any, selectedItems: any[], callback: EventEmitter, listType: number) { From df6897932c22e83ef4dcf93d06ca4975649eacd5 Mon Sep 17 00:00:00 2001 From: elian Date: Mon, 18 Mar 2024 00:41:29 +0100 Subject: [PATCH 2/2] removed deprecated method --- src/app/components/picklist/picklist.ts | 31 ------------------------- 1 file changed, 31 deletions(-) diff --git a/src/app/components/picklist/picklist.ts b/src/app/components/picklist/picklist.ts index 0af74f75951..e1fb088fe2f 100755 --- a/src/app/components/picklist/picklist.ts +++ b/src/app/components/picklist/picklist.ts @@ -1574,37 +1574,6 @@ export class PickList implements AfterViewChecked, AfterContentInit { this.resetTargetFilter(); } - onItemKeydown(event: KeyboardEvent, item: any, selectedItems: any[], callback: EventEmitter) { - let listItem = event.currentTarget; - - switch (event.which) { - //down - case 40: - var nextItem = this.findNextItem(listItem); - if (nextItem) { - nextItem.focus(); - } - - event.preventDefault(); - break; - - //up - case 38: - var prevItem = this.findPrevItem(listItem); - if (prevItem) { - prevItem.focus(); - } - - event.preventDefault(); - break; - - //enter - case 13: - this.onItemClick(event, item, selectedItems, callback); - event.preventDefault(); - break; - } - } findNextItem(item: any): HTMLElement | null { let nextItem = item.nextElementSibling;