Skip to content

Commit

Permalink
fix(Tree): node open state class condition error (#2611)
Browse files Browse the repository at this point in the history
* fix(tree): node open state class condition error

* feat(tree): unit test `node-open` class render logic
  • Loading branch information
NWYLZW authored Nov 27, 2023
1 parent e4cda54 commit 2c033c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tree/TreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ const TreeItem = forwardRef(
data-value={node.value}
data-level={level}
className={classNames(treeClassNames.treeNode, {
[treeClassNames.treeNodeOpen]: node.expanded,
[treeClassNames.treeNodeOpen]:
node.expanded &&
(typeof node.data.children === 'boolean' ? node.data.children : node.data.children !== undefined),
[treeClassNames.actived]: node.isActivable() ? node.actived : false,
[treeClassNames.disabled]: node.isDisabled(),
[treeClassNames.treeNodeDraggable]: node.isDraggable(),
Expand Down
14 changes: 14 additions & 0 deletions src/tree/__tests__/tree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ describe('Tree test', () => {
expect(onChangeFn1).not.toHaveBeenCalled();
});

it('should calculate right class of tree item.', async () => {
const { container } = await renderTreeWithProps({
expanded: [1, '1-2', '1-2', 2],
});

await mockDelay(300);
const allItems = container.querySelectorAll('.t-tree__item');
expect(allItems.length).toBe(4);
const nodeOpenItems = container.querySelectorAll('.t-tree__item--open');
// only set expanded when node has children
// or children is `true` when the tree is lazy
expect(nodeOpenItems.length).toBe(1);
});

test('props.line', async () => {
const data = [
{
Expand Down

0 comments on commit 2c033c4

Please sign in to comment.