Skip to content

Commit d1440c9

Browse files
authored
Tree: add iconClass attribute (#13337)
1 parent eb41032 commit d1440c9

File tree

7 files changed

+16
-8
lines changed

7 files changed

+16
-8
lines changed

examples/docs/en-US/tree.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,7 @@ You can drag and drop Tree nodes by adding a `draggable` attribute.
11841184
| filter-node-method | this function will be executed on each node when use filter method. if return `false`, tree node will be hidden. | Function(value, data, node) |||
11851185
| accordion | whether only one node among the same level can be expanded at one time | boolean || false |
11861186
| indent | horizontal indentation of nodes in adjacent levels in pixels | number || 16 |
1187+
| icon-class | custome tree node icon | string | - | - |
11871188
| lazy | whether to lazy load leaf node, used with `load` attribute | boolean || false |
11881189
| draggable | whether enable tree nodes drag and drop | boolean || false |
11891190
| allow-drag | this function will be executed before dragging a node. If `false` is returned, the node can not be dragged | Function(node) |||

examples/docs/es/tree.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,8 @@ Puede arrastrar y soltar nodos de Tree añadiendo un atributo `draggable` .
11841184
| filter-node-method | Esta función se ejecutará en cada nodo cuando se use el método filtrtar, si devuelve `false` el nodo se oculta | Function(value, data, node) |||
11851185
| accordion | Si solo un nodo de cada nivel puede expandirse a la vez | boolean || false |
11861186
| indent | Indentación horizontal de los nodos en niveles adyacentes, en pixeles | number || 16 |
1187+
| icon-class | Custome tree node icon | string | - | - |
1188+
| lazy | whether to lazy load leaf node, used with `load` attribute | boolean || false |
11871189
| draggable | si se habilita la función de drag and drop en los nodos | boolean || false |
11881190
| allow-drag | esta función se ejecutará antes de arrastrar un nodo. si devuelve `false`, el nodo no puede ser arrastrado. | Function(nodo) |||
11891191
| allow-drop | esta función se ejecutará al arrastrar y soltar un nodo. si devuelve false, el nodo arrastrando no se puede soltar en el nodo destino. `type` tiene tres valores posibles: 'prev' (insertar el nodo de arrastre antes del nodo de destino), 'inner' (insertar el nodo de arrastre en el nodo de destino) y 'next' (insertar el nodo de arrastre después del nodo de destino) | Function(Nodoquesearrastra, Nododestino, type) |||

examples/docs/zh-CN/tree.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@
12031203
| filter-node-method | 对树节点进行筛选时执行的方法,返回 true 表示这个节点可以显示,返回 false 则表示这个节点会被隐藏 | Function(value, data, node) |||
12041204
| accordion | 是否每次只打开一个同级树节点展开 | boolean || false |
12051205
| indent | 相邻级节点间的水平缩进,单位为像素 | number || 16 |
1206+
| icon-class | 自定义树节点的图标 | string | - | - |
12061207
| lazy | 是否懒加载子节点,需与 load 方法结合使用 | boolean || false |
12071208
| draggable | 是否开启拖拽节点功能 | boolean || false |
12081209
| allow-drag | 判断节点能否被拖拽 | Function(node) |||

packages/tree/src/model/node.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ export default class Node {
156156
return getPropertyFromData(this, 'label');
157157
}
158158

159-
get icon() {
160-
return getPropertyFromData(this, 'icon');
161-
}
162-
163159
get key() {
164160
const nodeKey = this.store.key;
165161
if (this.data) return this.data[nodeKey];

packages/tree/src/tree-node.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@
2626
<div class="el-tree-node__content"
2727
:style="{ 'padding-left': (node.level - 1) * tree.indent + 'px' }">
2828
<span
29-
class="el-tree-node__expand-icon el-icon-caret-right"
3029
@click.stop="handleExpandIconClick"
31-
:class="{ 'is-leaf': node.isLeaf, expanded: !node.isLeaf && expanded }">
30+
:class="[
31+
{ 'is-leaf': node.isLeaf, expanded: !node.isLeaf && expanded },
32+
'el-tree-node__expand-icon',
33+
tree.iconClass ? tree.iconClass : 'el-icon-caret-right'
34+
]"
35+
>
3236
</span>
3337
<el-checkbox
3438
v-if="showCheckbox"

packages/tree/src/tree.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
return {
111111
children: 'children',
112112
label: 'label',
113-
icon: 'icon',
114113
disabled: 'disabled'
115114
};
116115
}
@@ -126,7 +125,8 @@
126125
indent: {
127126
type: Number,
128127
default: 18
129-
}
128+
},
129+
iconClass: String
130130
},
131131
132132
computed: {

types/tree.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,8 @@ export declare class ElTree<K = any, D = TreeData> extends ElementUIComponent {
257257
* @param ref key or node data or node instance of the reference node
258258
*/
259259
insertAfter(data: D, ref: D | K): void;
260+
261+
/** Custom tree node icon */
262+
iconClass?: string;
263+
260264
}

0 commit comments

Comments
 (0)