Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tree): custom icons cannot be clicked without child nodes #3354

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading