diff --git a/components/lib/picklist/BasePickList.vue b/components/lib/picklist/BasePickList.vue
index 468f4bdbd..9a5f22317 100644
--- a/components/lib/picklist/BasePickList.vue
+++ b/components/lib/picklist/BasePickList.vue
@@ -54,44 +54,8 @@ export default {
type: Boolean,
default: true
},
- targetListProps: {
- type: null,
- default: null
- },
- sourceListProps: {
- type: null,
- default: null
- },
- moveUpButtonProps: {
- type: null,
- default: null
- },
- moveTopButtonProps: {
- type: null,
- default: null
- },
- moveDownButtonProps: {
- type: null,
- default: null
- },
- moveBottomButtonProps: {
- type: null,
- default: null
- },
- moveToTargetProps: {
- type: null,
- default: null
- },
- moveAllToTargetProps: {
- type: null,
- default: null
- },
- moveToSourceProps: {
- type: null,
- default: null
- },
- moveAllToSourceProps: {
- type: null,
+ severity: {
+ type: String,
default: null
},
tabindex: {
diff --git a/components/lib/picklist/PickList.vue b/components/lib/picklist/PickList.vue
index 3bcd65978..5f2376e43 100755
--- a/components/lib/picklist/PickList.vue
+++ b/components/lib/picklist/PickList.vue
@@ -2,183 +2,160 @@
-
+
-
+
+
-
+
+
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
-
+
+
+
+
-
+
-
+
+
-
+
+
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
-
+
+
+
+
-
+
-
+
+
-
+
+
-
+
+
+
@@ -194,6 +171,7 @@ import AngleDownIcon from 'primevue/icons/angledown';
import AngleLeftIcon from 'primevue/icons/angleleft';
import AngleRightIcon from 'primevue/icons/angleright';
import AngleUpIcon from 'primevue/icons/angleup';
+import Listbox from 'primevue/listbox';
import Ripple from 'primevue/ripple';
import { DomHandler, ObjectUtils, UniqueComponentId } from 'primevue/utils';
import BasePickList from './BasePickList.vue';
@@ -212,11 +190,6 @@ export default {
return {
id: this.$attrs.id,
d_selection: this.selection,
- focused: {
- sourceList: false,
- targetList: false
- },
- focusedOptionIndex: -1,
viewChanged: false
};
},
@@ -252,39 +225,35 @@ export default {
}
},
methods: {
- getItemKey(item, index) {
- return this.dataKey ? ObjectUtils.resolveFieldData(item, this.dataKey) : index;
- },
- getPTOptions(item, key, id, listIndex) {
- return this.ptm(key, {
- context: {
- active: this.isSelected(item, listIndex),
- focused: id === this.focusedOptionId
- }
+ updateSelection(event) {
+ this.$emit('update:selection', this.d_selection);
+ this.$emit('selection-change', {
+ originalEvent: event,
+ value: this.d_selection
});
},
- isSelected(item, listIndex) {
- return ObjectUtils.findIndexInList(item, this.d_selection[listIndex]) != -1;
+ onChangeSelection(params, listIndex) {
+ this.d_selection[listIndex] = params.value;
+ this.updateSelection(params.event);
},
onListFocus(event, listType) {
- this.focused[listType] = true;
- this.findCurrentFocusedIndex(listType);
- this.scrollInView(this.focusedOptionIndex, listType);
- this.$emit('focus', event);
+ this.$emit('focus', event, listType);
},
onListBlur(event, listType) {
- this.focused[listType] = false;
- this.focusedOptionIndex = -1;
- this.$emit('blur', event);
+ this.$emit('blur', event, listType);
},
- onOptionMouseDown(event, index, listType) {
- this.focused[listType] = true;
- this.focusedOptionIndex = index;
+ onReorderUpdate(event, value, listIndex) {
+ this.$emit('update:modelValue', value);
+ this.$emit('reorder', {
+ originalEvent: event,
+ value: value,
+ direction: this.reorderDirection,
+ listIndex
+ });
},
- onOptionMouseMove(index, listType) {
- if (this.focusOnHover && this.focused[listType]) {
- this.changeFocusedOptionIndex(index, listType);
- }
+ onItemDblClick(event, listIndex) {
+ if (listIndex === 0) this.moveToTarget({ event: event.originalEvent });
+ else if (listIndex === 1) this.moveToSource({ event: event.originalEvent });
},
moveUp(event, listIndex) {
if (this.d_selection && this.d_selection[listIndex]) {
@@ -311,13 +280,7 @@ export default {
value[listIndex] = valueList;
this.reorderDirection = 'up';
- this.$emit('update:modelValue', value);
- this.$emit('reorder', {
- originalEvent: event,
- value: value,
- direction: this.reorderDirection,
- listIndex: listIndex
- });
+ this.onReorderUpdate(event, value, listIndex);
}
},
moveTop(event, listIndex) {
@@ -343,13 +306,7 @@ export default {
value[listIndex] = valueList;
this.reorderDirection = 'top';
- this.$emit('update:modelValue', value);
- this.$emit('reorder', {
- originalEvent: event,
- value: value,
- direction: this.reorderDirection,
- listIndex: listIndex
- });
+ this.onReorderUpdate(event, value, listIndex);
}
},
moveDown(event, listIndex) {
@@ -377,13 +334,7 @@ export default {
value[listIndex] = valueList;
this.reorderDirection = 'down';
- this.$emit('update:modelValue', value);
- this.$emit('reorder', {
- originalEvent: event,
- value: value,
- direction: this.reorderDirection,
- listIndex: listIndex
- });
+ this.onReorderUpdate(event, value, listIndex);
}
},
moveBottom(event, listIndex) {
@@ -409,13 +360,7 @@ export default {
value[listIndex] = valueList;
this.reorderDirection = 'bottom';
- this.$emit('update:modelValue', value);
- this.$emit('reorder', {
- originalEvent: event,
- value: value,
- direction: this.reorderDirection,
- listIndex: listIndex
- });
+ this.onReorderUpdate(event, value, listIndex);
}
},
moveToTarget(event) {
@@ -444,11 +389,7 @@ export default {
});
this.d_selection[0] = [];
- this.$emit('update:selection', this.d_selection);
- this.$emit('selection-change', {
- originalEvent: event,
- value: this.d_selection
- });
+ this.updateSelection(event);
}
},
moveAllToTarget(event) {
@@ -470,12 +411,8 @@ export default {
value[1] = targetList;
this.$emit('update:modelValue', value);
- this.d_selection[0] = [];
- this.$emit('update:selection', this.d_selection);
- this.$emit('selection-change', {
- originalEvent: event,
- value: this.d_selection
- });
+ this.d_selection = [[], []];
+ this.updateSelection(event);
}
},
moveToSource(event) {
@@ -504,11 +441,7 @@ export default {
});
this.d_selection[1] = [];
- this.$emit('update:selection', this.d_selection);
- this.$emit('selection-change', {
- originalEvent: event,
- value: this.d_selection
- });
+ this.updateSelection(event);
}
},
moveAllToSource(event) {
@@ -530,12 +463,8 @@ export default {
value[1] = targetList;
this.$emit('update:modelValue', value);
- this.d_selection[1] = [];
- this.$emit('update:selection', this.d_selection);
- this.$emit('selection-change', {
- originalEvent: event,
- value: this.d_selection
- });
+ this.d_selection = [[], []];
+ this.updateSelection(event);
}
},
onItemClick(event, item, index, listIndex) {
@@ -574,209 +503,7 @@ export default {
newSelection[listIndex] = _selection;
this.d_selection = newSelection;
- this.$emit('update:selection', this.d_selection);
- this.$emit('selection-change', {
- originalEvent: event,
- value: this.d_selection
- });
- },
- onItemDblClick(event, item, listIndex) {
- if (listIndex === 0) this.moveToTarget(event);
- else if (listIndex === 1) this.moveToSource(event);
- },
- onItemTouchEnd() {
- this.itemTouched = true;
- },
- onItemKeyDown(event, listType) {
- switch (event.code) {
- case 'ArrowDown':
- this.onArrowDownKey(event, listType);
- break;
-
- case 'ArrowUp':
- this.onArrowUpKey(event, listType);
- break;
-
- case 'Home':
- this.onHomeKey(event, listType);
- break;
-
- case 'End':
- this.onEndKey(event, listType);
- break;
-
- case 'Enter':
- case 'NumpadEnter':
- this.onEnterKey(event, listType);
- break;
-
- case 'Space':
- this.onSpaceKey(event, listType);
- break;
-
- case 'KeyA':
- if (event.ctrlKey) {
- this.d_selection = [...this.modelValue];
- this.$emit('update:selection', this.d_selection);
-
- event.preventDefault();
- }
-
- default:
- break;
- }
- },
- onArrowDownKey(event, listType) {
- const optionIndex = this.focusedOptionIndex !== -1 ? this.findNextOptionIndex(listType) : this.findFirstSelectedOptionIndex(listType);
-
- this.changeFocusedOptionIndex(optionIndex, listType);
-
- if (event.shiftKey) {
- this.onEnterKey(event, listType);
- }
-
- event.preventDefault();
- },
- onArrowUpKey(event, listType) {
- const optionIndex = this.focusedOptionIndex !== -1 ? this.findPrevOptionIndex(listType) : this.findLastSelectedOptionIndex(listType);
-
- this.changeFocusedOptionIndex(optionIndex, listType);
-
- if (event.shiftKey) {
- this.onEnterKey(event, listType);
- }
-
- event.preventDefault();
- },
- onEnterKey(event, listType) {
- const listId = listType === 'sourceList' ? 0 : 1;
- const matchedOptionIndex = this.findMatchedOptionIndex(listType);
-
- this.onItemClick(event, this.modelValue[listId][matchedOptionIndex], matchedOptionIndex, listId);
-
- event.preventDefault();
- },
- onSpaceKey(event, listType) {
- event.preventDefault();
-
- if (event.shiftKey && this.d_selection && this.d_selection.length > 0) {
- const listId = listType === 'sourceList' ? 0 : 1;
- const selectedItemIndex = ObjectUtils.findIndexInList(this.d_selection[listId][0], [...this.modelValue[listId]]);
- const matchedOptionIndex = this.findMatchedOptionIndex(listType);
-
- this.d_selection[listId] = [...this.modelValue[listId]].slice(Math.min(selectedItemIndex, matchedOptionIndex), Math.max(selectedItemIndex, matchedOptionIndex) + 1);
- this.$emit('update:selection', this.d_selection);
- this.$emit('selection-change', {
- originalEvent: event,
- value: this.d_selection
- });
- } else {
- this.onEnterKey(event, listType);
- }
- },
- onHomeKey(event, listType) {
- if (event.ctrlKey && event.shiftKey) {
- const listId = listType === 'sourceList' ? 0 : 1;
- const matchedOptionIndex = this.findMatchedOptionIndex(listType);
-
- this.d_selection[listId] = [...this.modelValue[listId]].slice(0, matchedOptionIndex + 1);
- this.$emit('update:selection', this.d_selection);
- this.$emit('selection-change', {
- originalEvent: event,
- value: this.d_selection
- });
- } else {
- this.changeFocusedOptionIndex(0, listType);
- }
-
- event.preventDefault();
- },
- onEndKey(event, listType) {
- const items = this.findAllItems(listType);
-
- if (event.ctrlKey && event.shiftKey) {
- const listId = listType === 'sourceList' ? 0 : 1;
- const matchedOptionIndex = this.findMatchedOptionIndex(listType);
-
- this.d_selection[listId] = [...this.modelValue[listId]].slice(matchedOptionIndex, items.length);
- this.$emit('update:selection', this.d_selection);
- this.$emit('selection-change', {
- originalEvent: event,
- value: this.d_selection
- });
- } else {
- this.changeFocusedOptionIndex(items.length - 1, listType);
- }
-
- event.preventDefault();
- },
- findAllItems(listType) {
- return DomHandler.find(this.$refs[listType].$el, '[data-pc-section="item"]');
- },
- findFocusedItem(listType) {
- return DomHandler.findSingle(this.$refs[listType].$el, `[data-pc-section="item"][id=${this.focusedOptionIndex}]`);
- },
- findCurrentFocusedIndex(listType) {
- if (this.focusedOptionIndex === -1) {
- this.focusedOptionIndex = this.findFirstSelectedOptionIndex(listType);
-
- if (this.autoOptionFocus && this.focusedOptionIndex === -1) {
- this.focusedOptionIndex = this.findFirstFocusedOptionIndex(listType);
- }
- }
- },
- findFirstFocusedOptionIndex(listType) {
- const firstFocusableItem = DomHandler.findSingle(this.$refs[listType].$el, '[data-pc-section="item"]');
-
- return DomHandler.getAttribute(firstFocusableItem, 'id');
- },
- findFirstSelectedOptionIndex(listType) {
- if (this.hasSelectedOption(listType)) {
- const selectedFirstItem = DomHandler.findSingle(this.$refs[listType].$el, '[data-p-highlight="true"]');
-
- return DomHandler.getAttribute(selectedFirstItem, 'id');
- }
-
- return -1;
- },
- findLastSelectedOptionIndex(listType) {
- if (this.hasSelectedOption(listType)) {
- const selectedItems = DomHandler.find(this.$refs[listType].$el, '[data-p-highlight="true"]');
-
- return ObjectUtils.findIndexInList(selectedItems[selectedItems.length - 1], this.list.children);
- }
-
- return -1;
- },
- findMatchedOptionIndex(listType, id = this.focusedOptionIndex) {
- const items = this.findAllItems(listType);
-
- return [...items].findIndex((link) => link.id === id);
- },
- findNextOptionIndex(listType) {
- const matchedOptionIndex = this.findMatchedOptionIndex(listType);
-
- return matchedOptionIndex > -1 ? matchedOptionIndex + 1 : 0;
- },
- findPrevOptionIndex(listType) {
- const matchedOptionIndex = this.findMatchedOptionIndex(listType);
-
- return matchedOptionIndex > -1 ? matchedOptionIndex - 1 : 0;
- },
- changeFocusedOptionIndex(index, listType) {
- const items = this.findAllItems(listType);
-
- let order = index >= items.length ? items.length - 1 : index < 0 ? 0 : index;
-
- this.focusedOptionIndex = items[order].getAttribute('id');
- this.scrollInView(items[order].getAttribute('id'), listType);
- },
- scrollInView(id, listType) {
- const element = DomHandler.findSingle(this.$refs[listType].$el, `[data-pc-section="item"][id="${id}"]`);
-
- if (element) {
- element.scrollIntoView && element.scrollIntoView({ block: 'nearest', inline: 'start', behavior: 'smooth' });
- }
+ this.updateSelection(event);
},
updateListScroll(listElement) {
const listItems = DomHandler.find(listElement, '[data-pc-section="item"][data-p-highlight="true"]');
@@ -867,15 +594,12 @@ export default {
}
},
moveDisabled(index) {
- if (!this.d_selection[index] || !this.d_selection[index].length) {
+ if (this.d_selection && (!this.d_selection[index] || !this.d_selection[index].length)) {
return true;
}
},
moveAllDisabled(list) {
return ObjectUtils.isEmpty(this[list]);
- },
- hasSelectedOption(listType) {
- return listType === 'sourceList' ? ObjectUtils.isNotEmpty(this.d_selection[0]) : ObjectUtils.isNotEmpty(this.d_selection[1]);
}
},
computed: {
@@ -885,9 +609,6 @@ export default {
idTarget() {
return `${this.id}_target`;
},
- focusedOptionId() {
- return this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : null;
- },
sourceList() {
return this.modelValue && this.modelValue[0] ? this.modelValue[0] : null;
},
@@ -923,15 +644,15 @@ export default {
}
},
components: {
- PLButton: Button,
- AngleRightIcon: AngleRightIcon,
- AngleLeftIcon: AngleLeftIcon,
- AngleDownIcon: AngleDownIcon,
- AngleUpIcon: AngleUpIcon,
- AngleDoubleRightIcon: AngleDoubleRightIcon,
- AngleDoubleLeftIcon: AngleDoubleLeftIcon,
- AngleDoubleDownIcon: AngleDoubleDownIcon,
- AngleDoubleUpIcon: AngleDoubleUpIcon
+ Listbox,
+ AngleRightIcon,
+ AngleLeftIcon,
+ AngleDownIcon,
+ AngleUpIcon,
+ AngleDoubleRightIcon,
+ AngleDoubleLeftIcon,
+ AngleDoubleDownIcon,
+ AngleDoubleUpIcon
},
directives: {
ripple: Ripple
diff --git a/components/lib/picklist/style/PickListStyle.js b/components/lib/picklist/style/PickListStyle.js
index 4220829c7..00bd7e112 100644
--- a/components/lib/picklist/style/PickListStyle.js
+++ b/components/lib/picklist/style/PickListStyle.js
@@ -15,13 +15,7 @@ const classes = {
targetWrapper: 'p-picklist-list-wrapper p-picklist-target-wrapper',
targetHeader: 'p-picklist-header',
targetList: 'p-picklist-list p-picklist-target',
- item: ({ instance, item, id, listIndex }) => [
- 'p-picklist-item',
- {
- 'p-highlight': instance.isSelected(item, listIndex),
- 'p-focus': id === instance.focusedOptionId
- }
- ],
+ item: 'p-picklist-item',
targetControls: 'p-picklist-buttons p-picklist-target-controls'
};