pull/5161/head
Cagatay Civici 2024-01-24 10:15:43 +03:00
commit c9758ae4f8
9 changed files with 58 additions and 26 deletions

View File

@ -28,7 +28,11 @@ export default {
}, },
autoOptionFocus: { autoOptionFocus: {
type: Boolean, type: Boolean,
default: false default: true
},
focusOnHover: {
type: Boolean,
default: true
}, },
responsive: { responsive: {
type: Boolean, type: Boolean,

View File

@ -227,9 +227,14 @@ export interface OrderListProps {
metaKeySelection?: boolean | undefined; metaKeySelection?: boolean | undefined;
/** /**
* Whether to focus on the first visible or selected element. * Whether to focus on the first visible or selected element.
* @defaultValue false * @defaultValue true
*/ */
autoOptionFocus?: boolean | undefined; autoOptionFocus?: boolean | undefined;
/**
* When enabled, the focus is placed on the hovered option.
* @defaultValue true
*/
focusOnHover?: boolean | undefined;
/** /**
* Inline style of the the list element. * Inline style of the the list element.
*/ */

View File

@ -62,8 +62,9 @@
:class="cx('item', { item, id: `${id}_${i}` })" :class="cx('item', { item, id: `${id}_${i}` })"
@click="onItemClick($event, item, i)" @click="onItemClick($event, item, i)"
@touchend="onItemTouchEnd" @touchend="onItemTouchEnd"
:aria-selected="isSelected(item)"
@mousedown="onOptionMouseDown(i)" @mousedown="onOptionMouseDown(i)"
@mousemove="onOptionMouseMove(i)"
:aria-selected="isSelected(item)"
v-bind="getPTOptions(item, 'item', i)" v-bind="getPTOptions(item, 'item', i)"
:data-p-highlight="isSelected(item)" :data-p-highlight="isSelected(item)"
:data-p-focused="`${id}_${i}` === focusedOptionId" :data-p-focused="`${id}_${i}` === focusedOptionId"
@ -191,6 +192,11 @@ export default {
this.focused = true; this.focused = true;
this.focusedOptionIndex = index; this.focusedOptionIndex = index;
}, },
onOptionMouseMove(index) {
if (this.focusOnHover && this.focused) {
this.changeFocusedOptionIndex(index);
}
},
onArrowDownKey(event) { onArrowDownKey(event) {
const optionIndex = this.focusedOptionIndex !== -1 ? this.findNextOptionIndex() : this.findFirstSelectedOptionIndex(); const optionIndex = this.focusedOptionIndex !== -1 ? this.findNextOptionIndex() : this.findFirstSelectedOptionIndex();

View File

@ -50,12 +50,7 @@ const classes = {
} }
], ],
controls: 'p-orderlist-controls', controls: 'p-orderlist-controls',
container: ({ instance }) => [ container: 'p-orderlist-list-container',
'p-orderlist-list-container',
{
'p-focus': instance.focused
}
],
header: 'p-orderlist-header', header: 'p-orderlist-header',
list: 'p-orderlist-list', list: 'p-orderlist-list',
item: ({ instance, item, id }) => [ item: ({ instance, item, id }) => [

View File

@ -28,7 +28,11 @@ export default {
}, },
autoOptionFocus: { autoOptionFocus: {
type: Boolean, type: Boolean,
default: false default: true
},
focusOnHover: {
type: Boolean,
default: true
}, },
responsive: { responsive: {
type: Boolean, type: Boolean,

View File

@ -337,9 +337,14 @@ export interface PickListProps {
metaKeySelection?: boolean | undefined; metaKeySelection?: boolean | undefined;
/** /**
* Whether to focus on the first visible or selected element. * Whether to focus on the first visible or selected element.
* @defaultValue false * @defaultValue true
*/ */
autoOptionFocus?: boolean | undefined; autoOptionFocus?: boolean | undefined;
/**
* When enabled, the focus is placed on the hovered option.
* @defaultValue true
*/
focusOnHover?: boolean | undefined;
/** /**
* Inline style of the the list element. * Inline style of the the list element.
*/ */

View File

@ -71,6 +71,7 @@
@dblclick="onItemDblClick($event, item, 0)" @dblclick="onItemDblClick($event, item, 0)"
@touchend="onItemTouchEnd" @touchend="onItemTouchEnd"
@mousedown="onOptionMouseDown(i, 'sourceList')" @mousedown="onOptionMouseDown(i, 'sourceList')"
@mousemove="onOptionMouseMove(i, 'sourceList')"
role="option" role="option"
:aria-selected="isSelected(item, 0)" :aria-selected="isSelected(item, 0)"
v-bind="getPTOptions(item, 'item', `${idSource}_${i}`, 0)" v-bind="getPTOptions(item, 'item', `${idSource}_${i}`, 0)"
@ -162,6 +163,7 @@
@dblclick="onItemDblClick($event, item, 1)" @dblclick="onItemDblClick($event, item, 1)"
@keydown="onItemKeyDown($event, 'targetList')" @keydown="onItemKeyDown($event, 'targetList')"
@mousedown="onOptionMouseDown(i, 'targetList')" @mousedown="onOptionMouseDown(i, 'targetList')"
@mousemove="onOptionMouseMove(i, 'targetList')"
@touchend="onItemTouchEnd" @touchend="onItemTouchEnd"
role="option" role="option"
:aria-selected="isSelected(item, 1)" :aria-selected="isSelected(item, 1)"
@ -313,6 +315,11 @@ export default {
this.focused[listType] = true; this.focused[listType] = true;
this.focusedOptionIndex = index; this.focusedOptionIndex = index;
}, },
onOptionMouseMove(index, listType) {
if (this.focusOnHover && this.focused[listType]) {
this.changeFocusedOptionIndex(index, listType);
}
},
moveUp(event, listIndex) { moveUp(event, listIndex) {
if (this.d_selection && this.d_selection[listIndex]) { if (this.d_selection && this.d_selection[listIndex]) {
let valueList = [...this.modelValue[listIndex]]; let valueList = [...this.modelValue[listIndex]];
@ -902,7 +909,7 @@ export default {
return ObjectUtils.isEmpty(this[list]); return ObjectUtils.isEmpty(this[list]);
}, },
hasSelectedOption(listType) { hasSelectedOption(listType) {
return listType === 'sourceList' ? ObjectUtils.isNotEmpty(this.d_selection[0]) : ObjectUtils.isNotEmpty(this.d_selection[0]); return listType === 'sourceList' ? ObjectUtils.isNotEmpty(this.d_selection[0]) : ObjectUtils.isNotEmpty(this.d_selection[1]);
} }
}, },
computed: { computed: {

View File

@ -46,21 +46,11 @@ const classes = {
} }
], ],
sourceControls: 'p-picklist-buttons p-picklist-source-controls', sourceControls: 'p-picklist-buttons p-picklist-source-controls',
sourceWrapper: ({ instance }) => [ sourceWrapper: 'p-picklist-list-wrapper p-picklist-source-wrapper',
'p-picklist-list-wrapper p-picklist-source-wrapper',
{
'p-focus': instance.focused.sourceList
}
],
sourceHeader: 'p-picklist-header', sourceHeader: 'p-picklist-header',
sourceList: 'p-picklist-list p-picklist-source-list', sourceList: 'p-picklist-list p-picklist-source-list',
buttons: 'p-picklist-buttons p-picklist-transfer-buttons', buttons: 'p-picklist-buttons p-picklist-transfer-buttons',
targetWrapper: ({ instance }) => [ targetWrapper: 'p-picklist-list-wrapper p-picklist-target-wrapper',
'p-picklist-list-wrapper p-picklist-target-wrapper',
{
'p-focus': instance.focused.targetList
}
],
targetHeader: 'p-picklist-header', targetHeader: 'p-picklist-header',
targetList: 'p-picklist-list p-picklist-target', targetList: 'p-picklist-list p-picklist-target',
item: ({ instance, item, id, listIndex }) => [ item: ({ instance, item, id, listIndex }) => [

View File

@ -37551,9 +37551,17 @@
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "boolean", "type": "boolean",
"default": "false", "default": "true",
"description": "Whether to focus on the first visible or selected element." "description": "Whether to focus on the first visible or selected element."
}, },
{
"name": "focusOnHover",
"optional": true,
"readonly": false,
"type": "boolean",
"default": "true",
"description": "When enabled, the focus is placed on the hovered option."
},
{ {
"name": "listStyle", "name": "listStyle",
"optional": true, "optional": true,
@ -42050,9 +42058,17 @@
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "boolean", "type": "boolean",
"default": "false", "default": "true",
"description": "Whether to focus on the first visible or selected element." "description": "Whether to focus on the first visible or selected element."
}, },
{
"name": "focusOnHover",
"optional": true,
"readonly": false,
"type": "boolean",
"default": "true",
"description": "When enabled, the focus is placed on the hovered option."
},
{ {
"name": "listStyle", "name": "listStyle",
"optional": true, "optional": true,