Skip to content

Commit 08ddeaa

Browse files
authored
fix: treat node with empty children as leaf (#408)
1 parent fdaaacd commit 08ddeaa

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Node/index.test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,27 @@ describe('<Node />', () => {
7171
).toBe(data.__rd3t.id);
7272
});
7373

74-
it('applies correct base className if `data.children` is defined', () => {
74+
it('applies correct base className if `data.children` is defined and not empty', () => {
7575
const leafNodeComponent = shallow(<Node {...mockProps} />);
76-
const nodeComponent = shallow(<Node {...mockProps} data={{ ...data, children: [] }} />);
76+
const leafNodeComponentWithEmptyChildren = shallow(
77+
<Node {...mockProps} data={{ ...data, children: [] }} />
78+
);
79+
const nodeComponent = shallow(
80+
<Node {...mockProps} data={{ ...data, children: [{ name: 'leaf' }] }} />
81+
);
7782

7883
expect(
7984
leafNodeComponent
8085
.find('g')
8186
.first()
8287
.prop('className')
8388
).toBe('rd3t-leaf-node');
89+
expect(
90+
leafNodeComponentWithEmptyChildren
91+
.find('g')
92+
.first()
93+
.prop('className')
94+
).toBe('rd3t-leaf-node');
8495
expect(
8596
nodeComponent
8697
.find('g')

src/Node/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ export default class Node extends React.Component<NodeProps, NodeState> {
173173
this.nodeRef = n;
174174
}}
175175
style={this.state.initialStyle}
176-
className={[data.children ? 'rd3t-node' : 'rd3t-leaf-node', nodeClassName].join(' ').trim()}
176+
className={[
177+
data.children && data.children.length > 0 ? 'rd3t-node' : 'rd3t-leaf-node',
178+
nodeClassName,
179+
]
180+
.join(' ')
181+
.trim()}
177182
transform={this.state.transform}
178183
>
179184
{this.renderNodeElement()}

0 commit comments

Comments
 (0)