2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-05-10 11:33:27 +00:00
|
|
|
<ul :ref="containerRef" :class="cx('list')" v-bind="level === 0 ? ptm('list') : ptm('optionList')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-for="(processedOption, index) of options" :key="getOptionLabelToRender(processedOption)">
|
|
|
|
<li
|
|
|
|
:id="getOptionId(processedOption)"
|
2024-05-10 11:33:27 +00:00
|
|
|
:class="cx('option', { 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"
|
2024-05-10 11:33:27 +00:00
|
|
|
v-bind="getPTOptions(processedOption, index, 'option')"
|
|
|
|
:data-p-option-group="isOptionGroup(processedOption)"
|
2024-05-24 11:07:49 +00:00
|
|
|
:data-p-active="isOptionActive(processedOption)"
|
2023-05-26 14:33:50 +00:00
|
|
|
:data-p-focus="isOptionFocused(processedOption)"
|
|
|
|
:data-p-disabled="isOptionDisabled(processedOption)"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2024-05-10 11:33:27 +00:00
|
|
|
<div v-ripple :class="cx('optionContent')" @click="onOptionClick($event, processedOption)" @mousemove="onOptionMouseMove($event, processedOption)" v-bind="getPTOptions(processedOption, index, 'optionContent')">
|
2024-05-30 10:50:51 +00:00
|
|
|
<component v-if="templates['option']" :is="templates['option']" :option="processedOption.option" :selected="isOptionGroup(processedOption) ? false : isOptionSelected(processedOption)" />
|
2024-05-10 11:33:27 +00:00
|
|
|
<span v-else :class="cx('optionText')" v-bind="getPTOptions(processedOption, index, 'optionText')">{{ getOptionLabelToRender(processedOption) }}</span>
|
2023-05-26 14:33:50 +00:00
|
|
|
<template v-if="isOptionGroup(processedOption)">
|
|
|
|
<component v-if="templates['optiongroupicon']" :is="templates['optiongroupicon']" aria-hidden="true" />
|
2023-12-26 11:34:10 +00:00
|
|
|
<span v-else-if="optionGroupIcon" :class="[cx('groupIcon'), optionGroupIcon]" aria-hidden="true" v-bind="getPTOptions(processedOption, index, 'groupIcon')" />
|
|
|
|
<AngleRightIcon v-else :class="cx('groupIcon')" aria-hidden="true" v-bind="getPTOptions(processedOption, index, 'groupIcon')" />
|
2023-05-26 14:33:50 +00:00
|
|
|
</template>
|
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"
|
2024-05-10 11:33:27 +00:00
|
|
|
:class="cx('optionList')"
|
2022-09-14 11:26:01 +00:00
|
|
|
: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"
|
2024-01-23 13:08:06 +00:00
|
|
|
@option-focus-change="onOptionFocusChange"
|
2023-05-05 08:45:08 +00:00
|
|
|
:pt="pt"
|
2023-07-24 08:25:19 +00:00
|
|
|
:unstyled="unstyled"
|
2023-11-09 14:18:51 +00:00
|
|
|
:isParentMount="mounted"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-30 09:59:17 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2023-04-18 12:53:43 +00:00
|
|
|
import AngleRightIcon from 'primevue/icons/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',
|
2023-07-04 06:29:36 +00:00
|
|
|
hostName: 'CascadeSelect',
|
2023-05-30 09:59:17 +00:00
|
|
|
extends: BaseComponent,
|
2024-01-23 13:08:06 +00:00
|
|
|
emits: ['option-change', 'option-focus-change'],
|
2023-11-09 14:18:51 +00:00
|
|
|
container: null,
|
2022-09-06 12:03:37 +00:00
|
|
|
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,
|
2023-12-08 09:30:23 +00:00
|
|
|
optionGroupChildren: {
|
|
|
|
type: [String, Array],
|
|
|
|
default: null
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
activeOptionPath: Array,
|
|
|
|
level: Number,
|
2023-11-09 14:18:51 +00:00
|
|
|
templates: null,
|
|
|
|
isParentMount: Boolean
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-11-09 14:18:51 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
mounted: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
isParentMount: {
|
|
|
|
handler(newValue) {
|
|
|
|
newValue && DomHandler.nestedPosition(this.container, this.level);
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2023-11-09 14:18:51 +00:00
|
|
|
mounted() {
|
2024-05-10 11:33:27 +00:00
|
|
|
// entering order correction when an option is selected
|
2023-11-09 14:18:51 +00:00
|
|
|
(this.isParentMount || this.level === 0) && DomHandler.nestedPosition(this.container, this.level);
|
|
|
|
this.mounted = true;
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
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;
|
|
|
|
},
|
2023-12-26 11:34:10 +00:00
|
|
|
getPTOptions(processedOption, index, key) {
|
|
|
|
return this.ptm(key, {
|
|
|
|
context: {
|
2024-05-10 11:33:27 +00:00
|
|
|
option: processedOption,
|
2023-12-26 11:34:10 +00:00
|
|
|
index,
|
|
|
|
level: this.level,
|
2024-05-10 11:33:27 +00:00
|
|
|
optionGroup: this.isOptionGroup(processedOption),
|
2023-12-26 11:34:10 +00:00
|
|
|
active: this.isOptionActive(processedOption),
|
|
|
|
focused: this.isOptionFocused(processedOption),
|
|
|
|
disabled: this.isOptionDisabled(processedOption)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
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 });
|
|
|
|
},
|
2024-01-23 13:08:06 +00:00
|
|
|
onOptionMouseMove(event, processedOption) {
|
|
|
|
this.$emit('option-focus-change', { originalEvent: event, processedOption });
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
onOptionChange(event) {
|
|
|
|
this.$emit('option-change', event);
|
|
|
|
},
|
2024-01-23 13:08:06 +00:00
|
|
|
onOptionFocusChange(event) {
|
|
|
|
this.$emit('option-focus-change', event);
|
|
|
|
},
|
2023-11-09 14:18:51 +00:00
|
|
|
containerRef(el) {
|
|
|
|
this.container = el;
|
2024-04-24 06:03:12 +00:00
|
|
|
},
|
|
|
|
listAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.listLabel : undefined;
|
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>
|