Skip to content

Commit bd13b2b

Browse files
committed
Handle case when rowHeight prop value is a callback
1 parent 1c072ad commit bd13b2b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/react-sortable-tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class ReactSortableTree extends Component {
357357
height={height}
358358
style={innerStyle}
359359
rowCount={rows.length}
360-
estimatedRowSize={rowHeight}
360+
estimatedRowSize={typeof rowHeight !== 'function' ? rowHeight : undefined}
361361
rowHeight={rowHeight}
362362
rowRenderer={({ index, key, style: rowStyle }) => this.renderRow(
363363
rows[index],
@@ -381,7 +381,7 @@ class ReactSortableTree extends Component {
381381
node: row.node,
382382
treeIndex: row.treeIndex,
383383
}),
384-
{ height: rowHeight },
384+
{ height: typeof rowHeight !== 'function' ? rowHeight : rowHeight({ index }) },
385385
() => (rows[index - 1] || null),
386386
matchKeys
387387
));

src/react-sortable-tree.test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,19 @@ describe('<SortableTree />', () => {
158158
it('should change height according to rowHeight prop', () => {
159159
const wrapper = mount(
160160
<SortableTree
161-
treeData={[{ title: 'a' }]}
161+
treeData={[{ title: 'a' }, { title: 'b' }]}
162162
onChange={() => {}}
163163
rowHeight={12}
164164
/>
165165
);
166166

167-
expect(wrapper.find(TreeNode)).toHaveStyle('height', 12);
167+
// Works with static value
168+
expect(wrapper.find(TreeNode).first()).toHaveStyle('height', 12);
169+
170+
// Works with function callback
171+
wrapper.setProps({ rowHeight: ({ index }) => 42 + index });
172+
expect(wrapper.find(TreeNode).first()).toHaveStyle('height', 42);
173+
expect(wrapper.find(TreeNode).last()).toHaveStyle('height', 43);
168174
});
169175

170176
it('should change scaffold width according to scaffoldBlockPxWidth prop', () => {

0 commit comments

Comments
 (0)