Refactor #3965 - For Tree
parent
6db25a8f93
commit
4597ac5cab
|
@ -102,29 +102,29 @@ const classes = {
|
||||||
searchIcon: 'p-tree-filter-icon',
|
searchIcon: 'p-tree-filter-icon',
|
||||||
wrapper: 'p-tree-wrapper',
|
wrapper: 'p-tree-wrapper',
|
||||||
container: 'p-tree-container',
|
container: 'p-tree-container',
|
||||||
node: ({ context }) => ['p-context', { 'p-context-leaf': context.leaf }],
|
node: ({ instance }) => ['p-treenode', { 'p-treenode-leaf': instance.leaf }],
|
||||||
content: ({ context }) => [
|
content: ({ instance }) => [
|
||||||
'p-context-content',
|
'p-treenode-content',
|
||||||
context.node.styleClass,
|
instance.node.styleClass,
|
||||||
{
|
{
|
||||||
'p-context-selectable': context.selectable,
|
'p-treenode-selectable': instance.selectable,
|
||||||
'p-highlight': context.checkboxMode ? context.checked : context.selected
|
'p-highlight': instance.checkboxMode ? instance.checked : instance.selected
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
toggler: 'p-tree-toggler p-link',
|
toggler: 'p-tree-toggler p-link',
|
||||||
togglerIcon: 'p-tree-toggler-icon',
|
togglerIcon: 'p-tree-toggler-icon',
|
||||||
checkboxContainer: 'p-checkbox p-component',
|
checkboxContainer: 'p-checkbox p-component',
|
||||||
checkbox: ({ context }) => [
|
checkbox: ({ instance }) => [
|
||||||
'p-checkbox-box',
|
'p-checkbox-box',
|
||||||
{
|
{
|
||||||
'p-highlight': context.checked,
|
'p-highlight': instance.checked,
|
||||||
'p-indeterminate': context.partialChecked
|
'p-indeterminate': instance.partialChecked
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
checkboxIcon: 'p-checkbox-icon',
|
checkboxIcon: 'p-checkbox-icon',
|
||||||
nodeIcon: ({ context }) => ['p-context-icon', context.node.icon],
|
nodeIcon: ({ instance }) => ['p-treenode-icon', instance.node.icon],
|
||||||
label: 'p-context-label',
|
label: 'p-treenode-label',
|
||||||
subgroup: 'p-context-children'
|
subgroup: 'p-treenode-children'
|
||||||
};
|
};
|
||||||
|
|
||||||
const { load: loadStyle } = useStyle(styles, { id: 'primevue_tree_style', manual: true });
|
const { load: loadStyle } = useStyle(styles, { id: 'primevue_tree_style', manual: true });
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<li
|
<li
|
||||||
ref="currentNode"
|
ref="currentNode"
|
||||||
:class="getCXOptions('node')"
|
:class="cx('node')"
|
||||||
role="treeitem"
|
role="treeitem"
|
||||||
:aria-label="label(node)"
|
:aria-label="label(node)"
|
||||||
:aria-selected="ariaSelected"
|
:aria-selected="ariaSelected"
|
||||||
|
@ -15,19 +15,19 @@
|
||||||
v-bind="level === 1 ? getPTOptions('node') : ptm('subgroup')"
|
v-bind="level === 1 ? getPTOptions('node') : ptm('subgroup')"
|
||||||
data-pc-section="treeitem"
|
data-pc-section="treeitem"
|
||||||
>
|
>
|
||||||
<div :class="getCXOptions('content')" @click="onClick" @touchend="onTouchEnd" :style="node.style" v-bind="getPTOptions('content')" :data-p-highlight="checkboxMode ? checked : selected" :data-p-selectable="selectable">
|
<div :class="cx('content')" @click="onClick" @touchend="onTouchEnd" :style="node.style" v-bind="getPTOptions('content')" :data-p-highlight="checkboxMode ? checked : selected" :data-p-selectable="selectable">
|
||||||
<button v-ripple type="button" :class="cx('toggler')" @click="toggle" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('toggler')">
|
<button v-ripple type="button" :class="cx('toggler')" @click="toggle" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('toggler')">
|
||||||
<component v-if="templates['togglericon']" :is="templates['togglericon']" :node="node" :expanded="expanded" :class="cx('togglerIcon')" />
|
<component v-if="templates['togglericon']" :is="templates['togglericon']" :node="node" :expanded="expanded" :class="cx('togglerIcon')" />
|
||||||
<component v-else-if="expanded" :is="node.expandedIcon ? 'span' : 'ChevronDownIcon'" :class="cx('togglerIcon')" v-bind="getPTOptions('togglerIcon')" />
|
<component v-else-if="expanded" :is="node.expandedIcon ? 'span' : 'ChevronDownIcon'" :class="cx('togglerIcon')" v-bind="getPTOptions('togglerIcon')" />
|
||||||
<component v-else :is="node.collapsedIcon ? 'span' : 'ChevronRightIcon'" :class="cx('togglerIcon')" v-bind="getPTOptions('togglerIcon')" />
|
<component v-else :is="node.collapsedIcon ? 'span' : 'ChevronRightIcon'" :class="cx('togglerIcon')" v-bind="getPTOptions('togglerIcon')" />
|
||||||
</button>
|
</button>
|
||||||
<div v-if="checkboxMode" :class="cx('checkboxContainer')" aria-hidden="true" v-bind="getPTOptions('checkboxContainer')">
|
<div v-if="checkboxMode" :class="cx('checkboxContainer')" aria-hidden="true" v-bind="getPTOptions('checkboxContainer')">
|
||||||
<div :class="getCXOptions('checkbox')" role="checkbox" v-bind="getPTOptions('checkbox')" :data-p-checked="checked" :data-p-partialchecked="partialchecked">
|
<div :class="cx('checkbox')" role="checkbox" v-bind="getPTOptions('checkbox')" :data-p-checked="checked" :data-p-partialchecked="partialchecked">
|
||||||
<component v-if="templates['checkboxicon']" :is="templates['checkboxicon']" :checked="checked" :partialChecked="partialChecked" :class="cx('checkboxIcon')" />
|
<component v-if="templates['checkboxicon']" :is="templates['checkboxicon']" :checked="checked" :partialChecked="partialChecked" :class="cx('checkboxIcon')" />
|
||||||
<component v-else :is="checked ? 'CheckIcon' : partialChecked ? 'MinusIcon' : null" :class="cx('checkboxIcon')" v-bind="getPTOptions('checkboxIcon')" />
|
<component v-else :is="checked ? 'CheckIcon' : partialChecked ? 'MinusIcon' : null" :class="cx('checkboxIcon')" v-bind="getPTOptions('checkboxIcon')" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span :class="getCXOptions('nodeIcon')" v-bind="getPTOptions('nodeIcon')"></span>
|
<span :class="cx('nodeIcon')" v-bind="getPTOptions('nodeIcon')"></span>
|
||||||
<span :class="cx('label')" v-bind="getPTOptions('label')">
|
<span :class="cx('label')" v-bind="getPTOptions('label')">
|
||||||
<component v-if="templates[node.type] || templates['default']" :is="templates[node.type] || templates['default']" :node="node" />
|
<component v-if="templates[node.type] || templates['default']" :is="templates[node.type] || templates['default']" :node="node" />
|
||||||
<template v-else>{{ label(node) }}</template>
|
<template v-else>{{ label(node) }}</template>
|
||||||
|
@ -120,11 +120,6 @@ export default {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getCXOptions(key) {
|
|
||||||
return this.cx(key, {
|
|
||||||
context: this
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onClick(event) {
|
onClick(event) {
|
||||||
if (this.toggleClicked || DomHandler.getAttribute(event.target, '[data-pc-section="toggler"]') || DomHandler.getAttribute(event.target.parentElement, '[data-pc-section="toggler"]')) {
|
if (this.toggleClicked || DomHandler.getAttribute(event.target, '[data-pc-section="toggler"]') || DomHandler.getAttribute(event.target.parentElement, '[data-pc-section="toggler"]')) {
|
||||||
this.toggleClicked = false;
|
this.toggleClicked = false;
|
||||||
|
@ -390,7 +385,7 @@ export default {
|
||||||
getParentNodeElement(nodeElement) {
|
getParentNodeElement(nodeElement) {
|
||||||
const parentNodeElement = nodeElement.parentElement.parentElement;
|
const parentNodeElement = nodeElement.parentElement.parentElement;
|
||||||
|
|
||||||
return DomHandler.getAttribute(parentNodeElement, '[data-pc-section="treeitem"]') ? parentNodeElement : null;
|
return DomHandler.getAttribute(parentNodeElement, 'data-pc-section') === 'treeitem' ? parentNodeElement : null;
|
||||||
},
|
},
|
||||||
focusNode(element) {
|
focusNode(element) {
|
||||||
element.focus();
|
element.focus();
|
||||||
|
|
Loading…
Reference in New Issue