Skip to content

Commit

Permalink
fix(tree): custom icons cannot be clicked without child nodes (#3354)
Browse files Browse the repository at this point in the history
  • Loading branch information
RSS1102 authored Oct 11, 2024
1 parent ecfd2f8 commit 9945cbe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/tree/__tests__/expand.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from '@vue/test-utils';
import Tree from '@/src/tree/index.ts';
import Icon from '@/src/icon/index.ts';
import { delay } from './kit';
import { ref } from './adapt';

Expand Down Expand Up @@ -376,6 +377,37 @@ describe('Tree:expand', () => {
expect(wrapper.find('[data-value="t1.1"]').exists()).toBe(true);
});

it('自定义图标-点击父节点图标可触发展开子节点', async () => {
const data = [
{
value: 't1',
children: [
{
value: 't1.1',
},
],
},
];
const wrapper = mount({
render() {
return <Tree transition={false} data={data} icon={() => <Icon name="folder" />}></Tree>;
},
});
// 测试: 点击一级 一级展开 二级存在
wrapper.find('[data-value="t1"] .t-tree__icon').trigger('click');
await delay(10);
const t1d1 = wrapper.find('[data-value="t1.1"]');
expect(t1d1.attributes('class')).toContain('t-tree__item--visible');
const t1 = wrapper.find('[data-value="t1"]');
expect(t1.attributes('class')).toContain('t-tree__item--open');

// 测试:点击二级 二级状态不展开
wrapper.find('[data-value="t1.1"] .t-tree__icon').trigger('click');
await delay(10);
const t1d1_two = wrapper.find('[data-value="t1.1"]');
expect(t1d1_two.attributes('class')).not.toContain('t-tree__item--open');
});

it('点击已展开的父节点图标,可触发收起子节点', async () => {
const data = [
{
Expand Down
3 changes: 3 additions & 0 deletions src/tree/hooks/useTreeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export default function useTreeAction(state: TypeTreeState) {

const toggleExpanded = (item: TypeTargetNode): TreeNodeValue[] => {
const node = getNode(store, item);

if (!node.children) return;

return setExpanded(node, !node.isExpanded());
};

Expand Down

0 comments on commit 9945cbe

Please sign in to comment.