Skip to content

Commit

Permalink
Merge pull request #5339 from ig-onoffice-de/add-icon-slot-to-tree
Browse files Browse the repository at this point in the history
feat(Tree): Add slot for nodeIcon
  • Loading branch information
tugcekucukoglu committed Mar 13, 2024
2 parents 1833800 + d6d5855 commit dc724ea
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions components/lib/tree/Tree.d.ts
Expand Up @@ -352,6 +352,16 @@ export interface TreeSlots {
*/
expanded: boolean;
}): VNode[];
/**
* Custom node icon template.
* @param {Object} scope - togglericon slot's params.
*/
nodeIcon(scope: {
/**
* Tree node instance
*/
node: TreeNode;
}): VNode[];
/**
* Custom checkbox icon
* @param {Object} scope - checkboxicon slot's params.
Expand Down
27 changes: 27 additions & 0 deletions components/lib/tree/Tree.spec.js
Expand Up @@ -54,4 +54,31 @@ describe('Tree.vue', () => {

expect(wrapper.emitted('filter')).toBeTruthy();
});

it('should render icon', ({expect})=>{
expect(wrapper.find('span.pi-inbox').exists()).toBeTruthy();
expect(wrapper.find('span.pi-inbox').classes('p-treenode-icon')).toBeTruthy()
})

it('should render icon slot', ({expect})=>{
let wrapper = mount(Tree, {
slots: {
nodeIcon: `<i data-node-icon/>`
},
props: {
value: [
{
key: '0',
label: 'Documents',
data: 'Documents Folder',
children: []
}
]
}
});

const nodeIcon = wrapper.find('i[data-node-icon]');

expect(nodeIcon.exists()).toBeTruthy();
})
});
7 changes: 6 additions & 1 deletion components/lib/tree/TreeNode.vue
Expand Up @@ -32,7 +32,12 @@
<component v-else :is="checked ? 'CheckIcon' : partialChecked ? 'MinusIcon' : null" :class="slotProps.class" v-bind="getPTOptions('nodeCheckbox.icon')" />
</template>
</Checkbox>
<span :class="[cx('nodeIcon'), node.icon]" v-bind="getPTOptions('nodeIcon')"></span>
<template v-if="templates['nodeIcon']">
<component :is="templates['nodeIcon']" v-bind="getPTOptions('nodeIcon')" :class="cx('nodeIcon')" :node="node"></component>
</template>
<template v-else>
<span :class="[cx('nodeIcon'), node.icon]" v-bind="getPTOptions('nodeIcon')"></span>
</template>
<span :class="cx('label')" v-bind="getPTOptions('label')" @keydown.stop>
<component v-if="templates[node.type] || templates['default']" :is="templates[node.type] || templates['default']" :node="node" />
<template v-else>{{ label(node) }}</template>
Expand Down

0 comments on commit dc724ea

Please sign in to comment.