2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-02-11 23:48:42 +00:00
|
|
|
<nav :id="id" :class="cx('root')" v-bind="ptmi('root')">
|
2024-04-30 13:03:20 +00:00
|
|
|
<ol ref="list" :class="cx('list')" v-bind="ptm('list')">
|
2023-11-08 12:52:43 +00:00
|
|
|
<template v-for="(item, index) of model" :key="label(item) + '_' + index.toString()">
|
|
|
|
<li
|
|
|
|
v-if="visible(item)"
|
2024-04-30 13:03:20 +00:00
|
|
|
:class="[cx('item', { item, index }), item.class]"
|
2023-11-08 12:52:43 +00:00
|
|
|
:style="item.style"
|
2023-12-28 08:05:37 +00:00
|
|
|
:aria-current="isActive(index) ? 'step' : undefined"
|
2023-11-08 12:52:43 +00:00
|
|
|
@click="onItemClick($event, item, index)"
|
|
|
|
@keydown="onItemKeydown($event, item, index)"
|
2024-04-30 13:03:20 +00:00
|
|
|
v-bind="getPTOptions('item', item, index)"
|
2024-05-24 11:07:49 +00:00
|
|
|
:data-p-active="isActive(index)"
|
2023-11-08 12:52:43 +00:00
|
|
|
:data-p-disabled="isItemDisabled(item, index)"
|
|
|
|
>
|
2022-09-06 12:03:37 +00:00
|
|
|
<template v-if="!$slots.item">
|
2024-04-30 13:03:20 +00:00
|
|
|
<span :class="cx('itemLink')" v-bind="getPTOptions('itemLink', item, index)">
|
|
|
|
<span :class="cx('itemNumber')" v-bind="getPTOptions('itemNumber', item, index)">{{ index + 1 }}</span>
|
|
|
|
<span :class="cx('itemLabel')" v-bind="getPTOptions('itemLabel', item, index)">{{ label(item) }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</span>
|
|
|
|
</template>
|
2023-11-09 08:44:31 +00:00
|
|
|
<component v-else :is="$slots.item" :item="item" :index="index" :active="index === d_activeStep" :label="label(item)" :props="getMenuItemProps(item, index)"></component>
|
2022-09-06 12:03:37 +00:00
|
|
|
</li>
|
|
|
|
</template>
|
2022-12-08 11:04:25 +00:00
|
|
|
</ol>
|
|
|
|
</nav>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-30 11:58:41 +00:00
|
|
|
import { DomHandler } from 'primevue/utils';
|
2023-08-30 14:29:26 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2023-05-30 11:58:41 +00:00
|
|
|
import BaseSteps from './BaseSteps.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Steps',
|
2023-05-30 11:58:41 +00:00
|
|
|
extends: BaseSteps,
|
2024-02-11 23:48:42 +00:00
|
|
|
inheritAttrs: false,
|
2023-11-08 12:52:43 +00:00
|
|
|
emits: ['update:activeStep', 'step-change'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
d_activeStep: this.activeStep
|
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
activeStep(newValue) {
|
|
|
|
this.d_activeStep = newValue;
|
2023-08-30 14:29:26 +00:00
|
|
|
}
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
mounted() {
|
|
|
|
const firstItem = this.findFirstItem();
|
|
|
|
|
2023-12-28 09:09:51 +00:00
|
|
|
firstItem && (firstItem.tabIndex = '0');
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
methods: {
|
2023-07-24 10:57:49 +00:00
|
|
|
getPTOptions(key, item, index) {
|
|
|
|
return this.ptm(key, {
|
|
|
|
context: {
|
2023-07-25 09:11:49 +00:00
|
|
|
item,
|
2023-07-24 10:57:49 +00:00
|
|
|
index,
|
2023-11-08 12:52:43 +00:00
|
|
|
active: this.isActive(index),
|
|
|
|
disabled: this.isItemDisabled(item, index)
|
2023-07-24 10:57:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2023-11-08 12:52:43 +00:00
|
|
|
onItemClick(event, item, index) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.disabled(item) || this.readonly) {
|
|
|
|
event.preventDefault();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.command) {
|
|
|
|
item.command({
|
|
|
|
originalEvent: event,
|
|
|
|
item: item
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-08 12:52:43 +00:00
|
|
|
if (index !== this.d_activeStep) {
|
|
|
|
this.d_activeStep = index;
|
|
|
|
this.$emit('update:activeStep', this.d_activeStep);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2023-11-08 12:52:43 +00:00
|
|
|
|
|
|
|
this.$emit('step-change', {
|
|
|
|
originalEvent: event,
|
|
|
|
index: index
|
|
|
|
});
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-11-08 12:52:43 +00:00
|
|
|
onItemKeydown(event, item) {
|
2022-12-08 11:04:25 +00:00
|
|
|
switch (event.code) {
|
|
|
|
case 'ArrowRight': {
|
|
|
|
this.navigateToNextItem(event.target);
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'ArrowLeft': {
|
|
|
|
this.navigateToPrevItem(event.target);
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Home': {
|
|
|
|
this.navigateToFirstItem(event.target);
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'End': {
|
|
|
|
this.navigateToLastItem(event.target);
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Tab':
|
|
|
|
//no op
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Enter':
|
2023-12-20 10:45:43 +00:00
|
|
|
case 'NumpadEnter':
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
case 'Space': {
|
2023-11-08 12:52:43 +00:00
|
|
|
this.onItemClick(event, item);
|
2022-12-08 11:04:25 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
navigateToNextItem(target) {
|
|
|
|
const nextItem = this.findNextItem(target);
|
|
|
|
|
|
|
|
nextItem && this.setFocusToMenuitem(target, nextItem);
|
|
|
|
},
|
|
|
|
navigateToPrevItem(target) {
|
|
|
|
const prevItem = this.findPrevItem(target);
|
|
|
|
|
|
|
|
prevItem && this.setFocusToMenuitem(target, prevItem);
|
|
|
|
},
|
|
|
|
navigateToFirstItem(target) {
|
|
|
|
const firstItem = this.findFirstItem(target);
|
|
|
|
|
|
|
|
firstItem && this.setFocusToMenuitem(target, firstItem);
|
|
|
|
},
|
|
|
|
navigateToLastItem(target) {
|
|
|
|
const lastItem = this.findLastItem(target);
|
|
|
|
|
|
|
|
lastItem && this.setFocusToMenuitem(target, lastItem);
|
|
|
|
},
|
|
|
|
findNextItem(item) {
|
|
|
|
const nextItem = item.parentElement.nextElementSibling;
|
|
|
|
|
|
|
|
return nextItem ? nextItem.children[0] : null;
|
|
|
|
},
|
|
|
|
findPrevItem(item) {
|
|
|
|
const prevItem = item.parentElement.previousElementSibling;
|
|
|
|
|
|
|
|
return prevItem ? prevItem.children[0] : null;
|
|
|
|
},
|
|
|
|
findFirstItem() {
|
2024-04-30 13:03:20 +00:00
|
|
|
const firstSibling = DomHandler.findSingle(this.$refs.list, '[data-pc-section="item"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
return firstSibling ? firstSibling.children[0] : null;
|
|
|
|
},
|
|
|
|
findLastItem() {
|
2024-04-30 13:03:20 +00:00
|
|
|
const siblings = DomHandler.find(this.$refs.list, '[data-pc-section="item"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
return siblings ? siblings[siblings.length - 1].children[0] : null;
|
|
|
|
},
|
|
|
|
setFocusToMenuitem(target, focusableItem) {
|
|
|
|
target.tabIndex = '-1';
|
|
|
|
focusableItem.tabIndex = '0';
|
|
|
|
focusableItem.focus();
|
|
|
|
},
|
2023-11-08 12:52:43 +00:00
|
|
|
isActive(index) {
|
|
|
|
return index === this.d_activeStep;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-11-08 12:52:43 +00:00
|
|
|
isItemDisabled(item, index) {
|
|
|
|
return this.disabled(item) || (this.readonly && !this.isActive(index));
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
visible(item) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return typeof item.visible === 'function' ? item.visible() : item.visible !== false;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
disabled(item) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return typeof item.disabled === 'function' ? item.disabled() : item.disabled;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
label(item) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return typeof item.label === 'function' ? item.label() : item.label;
|
2023-08-30 14:29:26 +00:00
|
|
|
},
|
|
|
|
getMenuItemProps(item, index) {
|
|
|
|
return {
|
|
|
|
action: mergeProps(
|
|
|
|
{
|
2024-04-30 13:03:20 +00:00
|
|
|
class: this.cx('itemLink'),
|
2023-08-30 14:29:26 +00:00
|
|
|
onClick: ($event) => this.onItemClick($event, item),
|
|
|
|
onKeyDown: ($event) => this.onItemKeydown($event, item)
|
|
|
|
},
|
2024-04-30 13:03:20 +00:00
|
|
|
this.getPTOptions('itemLink', item, index)
|
2023-08-30 14:29:26 +00:00
|
|
|
),
|
|
|
|
step: mergeProps(
|
|
|
|
{
|
2024-04-30 13:03:20 +00:00
|
|
|
class: this.cx('itemNumber')
|
2023-08-30 14:29:26 +00:00
|
|
|
},
|
2024-04-30 13:03:20 +00:00
|
|
|
this.getPTOptions('itemNumber', item, index)
|
2023-08-30 14:29:26 +00:00
|
|
|
),
|
|
|
|
label: mergeProps(
|
|
|
|
{
|
2024-04-30 13:03:20 +00:00
|
|
|
class: this.cx('itemLabel')
|
2023-08-30 14:29:26 +00:00
|
|
|
},
|
2024-04-30 13:03:20 +00:00
|
|
|
this.getPTOptions('itemLabel', item, index)
|
2023-08-30 14:29:26 +00:00
|
|
|
)
|
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|