2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
|
|
|
<ul class="p-cascadeselect-panel p-cascadeselect-items">
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-for="(processedOption, index) of options" :key="getOptionLabelToRender(processedOption)">
|
|
|
|
<li
|
|
|
|
:id="getOptionId(processedOption)"
|
2022-12-08 11:04:25 +00:00
|
|
|
:class="getOptionClass(processedOption)"
|
2022-09-14 11:26:01 +00:00
|
|
|
role="treeitem"
|
|
|
|
:aria-label="getOptionLabelToRender(processedOption)"
|
|
|
|
:aria-selected="isOptionGroup(processedOption) ? undefined : isOptionSelected(processedOption)"
|
|
|
|
:aria-expanded="isOptionGroup(processedOption) ? isOptionActive(processedOption) : undefined"
|
|
|
|
:aria-level="level + 1"
|
2022-12-08 11:04:25 +00:00
|
|
|
:aria-setsize="options.length"
|
|
|
|
:aria-posinset="index + 1"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
|
|
|
<div v-ripple class="p-cascadeselect-item-content" @click="onOptionClick($event, processedOption)">
|
2022-09-06 12:03:37 +00:00
|
|
|
<component v-if="templates['option']" :is="templates['option']" :option="processedOption.option" />
|
2022-09-14 11:26:01 +00:00
|
|
|
<span v-else class="p-cascadeselect-item-text">{{ getOptionLabelToRender(processedOption) }}</span>
|
2023-04-04 12:39:23 +00:00
|
|
|
<slot v-if="isOptionGroup(processedOption)" name="optiongroupicon">
|
|
|
|
<component :is="templates['optiongroupicon'] ? templates['optiongroupicon'] : optionGroupIcon ? 'span' : 'AngleRightIcon'" :class="['p-cascadeselect-group-icon', optionGroupIcon]" aria-hidden="true" />
|
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2022-09-14 11:26:01 +00:00
|
|
|
<CascadeSelectSub
|
|
|
|
v-if="isOptionGroup(processedOption) && isOptionActive(processedOption)"
|
|
|
|
role="group"
|
|
|
|
class="p-cascadeselect-sublist"
|
|
|
|
:selectId="selectId"
|
|
|
|
:focusedOptionId="focusedOptionId"
|
|
|
|
:options="getOptionGroupChildren(processedOption)"
|
|
|
|
:activeOptionPath="activeOptionPath"
|
|
|
|
:level="level + 1"
|
|
|
|
:templates="templates"
|
|
|
|
:optionLabel="optionLabel"
|
|
|
|
:optionValue="optionValue"
|
|
|
|
:optionDisabled="optionDisabled"
|
2022-12-08 11:04:25 +00:00
|
|
|
:optionGroupIcon="optionGroupIcon"
|
2022-09-14 11:26:01 +00:00
|
|
|
:optionGroupLabel="optionGroupLabel"
|
|
|
|
:optionGroupChildren="optionGroupChildren"
|
|
|
|
@option-change="onOptionChange"
|
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-04 12:39:23 +00:00
|
|
|
import AngleRightIcon from 'primevue/icon/angleright';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler, ObjectUtils } from 'primevue/utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'CascadeSelectSub',
|
|
|
|
emits: ['option-change'],
|
|
|
|
props: {
|
|
|
|
selectId: String,
|
|
|
|
focusedOptionId: String,
|
|
|
|
options: Array,
|
|
|
|
optionLabel: String,
|
|
|
|
optionValue: String,
|
|
|
|
optionDisabled: null,
|
2022-12-08 11:04:25 +00:00
|
|
|
optionGroupIcon: String,
|
2022-09-06 12:03:37 +00:00
|
|
|
optionGroupLabel: String,
|
|
|
|
optionGroupChildren: Array,
|
|
|
|
activeOptionPath: Array,
|
|
|
|
level: Number,
|
|
|
|
templates: null
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (ObjectUtils.isNotEmpty(this.parentKey)) {
|
|
|
|
this.position();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getOptionId(processedOption) {
|
|
|
|
return `${this.selectId}_${processedOption.key}`;
|
|
|
|
},
|
|
|
|
getOptionLabel(processedOption) {
|
|
|
|
return this.optionLabel ? ObjectUtils.resolveFieldData(processedOption.option, this.optionLabel) : processedOption.option;
|
|
|
|
},
|
|
|
|
getOptionValue(processedOption) {
|
|
|
|
return this.optionValue ? ObjectUtils.resolveFieldData(processedOption.option, this.optionValue) : processedOption.option;
|
|
|
|
},
|
|
|
|
isOptionDisabled(processedOption) {
|
|
|
|
return this.optionDisabled ? ObjectUtils.resolveFieldData(processedOption.option, this.optionDisabled) : false;
|
|
|
|
},
|
|
|
|
getOptionGroupLabel(processedOption) {
|
|
|
|
return this.optionGroupLabel ? ObjectUtils.resolveFieldData(processedOption.option, this.optionGroupLabel) : null;
|
|
|
|
},
|
|
|
|
getOptionGroupChildren(processedOption) {
|
|
|
|
return processedOption.children;
|
|
|
|
},
|
|
|
|
isOptionGroup(processedOption) {
|
|
|
|
return ObjectUtils.isNotEmpty(processedOption.children);
|
|
|
|
},
|
|
|
|
isOptionSelected(processedOption) {
|
|
|
|
return !this.isOptionGroup(processedOption) && this.isOptionActive(processedOption);
|
|
|
|
},
|
|
|
|
isOptionActive(processedOption) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.activeOptionPath.some((path) => path.key === processedOption.key);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
isOptionFocused(processedOption) {
|
|
|
|
return this.focusedOptionId === this.getOptionId(processedOption);
|
|
|
|
},
|
|
|
|
getOptionLabelToRender(processedOption) {
|
|
|
|
return this.isOptionGroup(processedOption) ? this.getOptionGroupLabel(processedOption) : this.getOptionLabel(processedOption);
|
|
|
|
},
|
|
|
|
onOptionClick(event, processedOption) {
|
|
|
|
this.$emit('option-change', { originalEvent: event, processedOption, isFocus: true });
|
|
|
|
},
|
|
|
|
onOptionChange(event) {
|
|
|
|
this.$emit('option-change', event);
|
|
|
|
},
|
|
|
|
position() {
|
|
|
|
const parentItem = this.$el.parentElement;
|
|
|
|
const containerOffset = DomHandler.getOffset(parentItem);
|
|
|
|
const viewport = DomHandler.getViewport();
|
|
|
|
const sublistWidth = this.$el.offsetParent ? this.$el.offsetWidth : DomHandler.getHiddenElementOuterWidth(this.$el);
|
|
|
|
const itemOuterWidth = DomHandler.getOuterWidth(parentItem.children[0]);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (parseInt(containerOffset.left, 10) + itemOuterWidth + sublistWidth > viewport.width - DomHandler.calculateScrollbarWidth()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$el.style.left = '-100%';
|
|
|
|
}
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
getOptionClass(processedOption) {
|
|
|
|
return [
|
|
|
|
'p-cascadeselect-item',
|
|
|
|
{
|
|
|
|
'p-cascadeselect-item-group': this.isOptionGroup(processedOption),
|
|
|
|
'p-cascadeselect-item-active p-highlight': this.isOptionActive(processedOption),
|
|
|
|
'p-focus': this.isOptionFocused(processedOption),
|
|
|
|
'p-disabled': this.isOptionDisabled(processedOption)
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
directives: {
|
2022-09-14 11:26:01 +00:00
|
|
|
ripple: Ripple
|
2023-04-04 12:39:23 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
AngleRightIcon: AngleRightIcon
|
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>
|