+
@@ -9,7 +10,8 @@
+ :expandedKeys="expandedKeys" @node-toggle="onChildNodeToggle" @node-click="onChildNodeClick"
+ :selectionMode="selectionMode" :selectionKeys="selectionKeys">
@@ -27,17 +29,41 @@ export default {
expandedKeys: {
type: null,
default: null
+ },
+ selectionKeys: {
+ type: null,
+ default: null
+ },
+ selectionMode: {
+ type: String,
+ default: null
}
},
+ nodeTouched: false,
methods: {
toggle() {
- this.$emit('toggle', this.node);
+ this.$emit('node-toggle', this.node);
},
onChildNodeToggle(node) {
- this.$emit('toggle', node);
+ this.$emit('node-toggle', node);
},
- onClick() {
+ onClick(event) {
+ if (DomHandler.hasClass(event.target, 'p-tree-toggler') || DomHandler.hasClass(event.target, 'p-tree-toggler-icon')) {
+ return;
+ }
+ this.$emit('node-click', {
+ originalEvent: event,
+ nodeTouched: this.nodeTouched,
+ node: this.node
+ });
+ this.nodeTouched = false;
+ },
+ onChildNodeClick(event) {
+ this.$emit('node-click', event);
+ },
+ onTouchEnd() {
+ this.nodeTouched = true;
},
onKeyDown(event) {
const nodeElement = event.target.parentElement;
@@ -141,9 +167,21 @@ export default {
leaf() {
return this.node.leaf === false ? false : !(this.node.children && this.node.children.length);
},
+ selectable() {
+ return this.node.selectable === false ? false : this.selectionMode != null;
+ },
+ selected() {
+ return (this.selectionMode && this.selectionKeys) ? this.selectionKeys[this.node.key] === true : false;
+ },
containerClass() {
return ['p-treenode', {'p-treenode-leaf': this.leaf}];
},
+ contentClass() {
+ return ['p-treenode-content', {
+ 'p-treenode-selectable': this.selectable,
+ 'p-highlight': this.selected
+ }];
+ },
icon() {
return ['p-treenode-icon', this.node.icon];
},
diff --git a/src/router.js b/src/router.js
index fa8680d94..15c709813 100644
--- a/src/router.js
+++ b/src/router.js
@@ -360,6 +360,11 @@ export default new Router({
path: '/tree',
name: 'tree',
component: () => import('./views/tree/TreeDemo.vue')
+ },
+ {
+ path: '/tree/selection',
+ name: 'treeselectiın',
+ component: () => import('./views/tree/TreeSelectionDemo.vue')
},
{
path: '/tristatecheckbox',
diff --git a/src/views/tree/TreeSelectionDemo.vue b/src/views/tree/TreeSelectionDemo.vue
new file mode 100644
index 000000000..65926ffae
--- /dev/null
+++ b/src/views/tree/TreeSelectionDemo.vue
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
Tree - Selection
+
Tree supports single, multiple and checkbox as selection modes.
+
+
+
+
+
Single Selection
+
+ {{selectedKey}}
+
+ Multiple Selection with MetaKey
+
+ {{selectedKeys1}}
+
+ Multiple Selection without MetaKey
+
+ {{selectedKeys2}}
+
+
+
+
+
+
+
+
\ No newline at end of file