From 4f246b64e4d750bae95d1b14b1f6a65d808db679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Mon, 15 Nov 2021 15:17:53 +0300 Subject: [PATCH] Fixed #1755 - New selectionMode for PickList --- api-generator/components/picklist.js | 6 ++++++ src/components/picklist/PickList.d.ts | 1 + src/components/picklist/PickList.vue | 27 +++++++++++++++++++-------- src/views/picklist/PickListDoc.vue | 6 ++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/api-generator/components/picklist.js b/api-generator/components/picklist.js index f79483820..ab2eca722 100644 --- a/api-generator/components/picklist.js +++ b/api-generator/components/picklist.js @@ -11,6 +11,12 @@ const PickListProps = [ default: "null", description: "Selected items in the list as a multidimensional array." }, + { + name: "selectionMode", + type: "string", + default: "null", + description: 'Defines selection mode, options are "single" and "multiple".' + }, { name: "metaKeySelection", type: "boolean", diff --git a/src/components/picklist/PickList.d.ts b/src/components/picklist/PickList.d.ts index b2051e152..ccfd8269e 100755 --- a/src/components/picklist/PickList.d.ts +++ b/src/components/picklist/PickList.d.ts @@ -3,6 +3,7 @@ import { VNode } from 'vue'; interface PickListProps { modelValue?: any[][]; selection?: any[][]; + selectionMode?: string; dataKey?: string; metaKeySelection?: boolean; listStyle?: any; diff --git a/src/components/picklist/PickList.vue b/src/components/picklist/PickList.vue index 83846c235..71ea9540e 100755 --- a/src/components/picklist/PickList.vue +++ b/src/components/picklist/PickList.vue @@ -66,6 +66,10 @@ export default { type: Array, default: () => [[],[]] }, + selectionMode: { + type: String, + default: null + }, dataKey: { type: String, default: null @@ -381,18 +385,19 @@ export default { _selection = selectionList.filter((val, index) => index !== selectedIndex); } else { - _selection = (metaKey) ? selectionList ? [...selectionList] : [] : []; + if (metaKey) { + _selection = this.isMultipleSelectionMode() ? selectionList ? [...selectionList] : [] : []; + } + else { + _selection = []; + } + _selection.push(item); } } else { - if (selected) { - _selection = selectionList.filter((val, index) => index !== selectedIndex); - } - else { - _selection = selectionList ? [...selectionList] : []; - _selection.push(item); - } + _selection = this.isMultipleSelectionMode() ? selectionList ? [...selectionList] : [] : []; + _selection.push(item); } let newSelection = [...this.d_selection]; @@ -543,6 +548,12 @@ export default { document.head.removeChild(this.styleElement); this.styleElement = null; } + }, + isSingleSelectionMode() { + return this.selectionMode === 'single'; + }, + isMultipleSelectionMode() { + return this.selectionMode === 'multiple'; } }, computed: { diff --git a/src/views/picklist/PickListDoc.vue b/src/views/picklist/PickListDoc.vue index 8182a307b..9e475bb79 100755 --- a/src/views/picklist/PickListDoc.vue +++ b/src/views/picklist/PickListDoc.vue @@ -102,6 +102,12 @@ import PickList from 'primevue/picklist'; null Selected items in the list as a multidimensional array. + + selectionMode + string + null + Defines selection mode, options are "single" and "multiple". + metaKeySelection boolean