Skip to content

Exposing react-virtualized row props #770

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions src/node-renderer-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class NodeRendererDefault extends Component {
isOver, // Not needed, but preserved for other renderers
parentNode, // Needed for dndManager
rowDirection,

// virtualized row props
isScrolling,
isVisible,
parent,

...otherProps
} = this.props;
const nodeTitle = title || node.title;
Expand Down Expand Up @@ -194,6 +200,9 @@ NodeRendererDefault.defaultProps = {
title: null,
subtitle: null,
rowDirection: 'ltr',
isScrolling: false,
isVisible: true,
parent: {},
};

NodeRendererDefault.propTypes = {
Expand Down Expand Up @@ -228,6 +237,11 @@ NodeRendererDefault.propTypes = {

// rtl support
rowDirection: PropTypes.string,

// virtualized row props
isScrolling: PropTypes.bool,
isVisible: PropTypes.bool,
parent: PropTypes.shape({}),
};

export default NodeRendererDefault;
6 changes: 4 additions & 2 deletions src/react-sortable-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class ReactSortableTree extends Component {

renderRow(
row,
{ listIndex, style, getPrevRow, matchKeys, swapFrom, swapDepth, swapLength }
{ listIndex, style, getPrevRow, matchKeys, swapFrom, swapDepth, swapLength, ...rowProps }
) {
const { node, parentNode, path, lowerSiblingCounts, treeIndex } = row;

Expand Down Expand Up @@ -603,6 +603,7 @@ class ReactSortableTree extends Component {
toggleChildrenVisibility={this.toggleChildrenVisibility}
{...sharedProps}
{...nodeProps}
{...rowProps}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about passing rowProps (or specific attributes such as rowProps.isScrolling) to generateNodeProps in line 573? Then, one could use these props from within generateNodeProps without having to define an own nodeContentRenderer.

/>
</TreeNodeRenderer>
);
Expand Down Expand Up @@ -718,7 +719,7 @@ class ReactSortableTree extends Component {
path: rows[index].path,
})
}
rowRenderer={({ index, style: rowStyle }) =>
rowRenderer={({ index, style: rowStyle, ...rowProps }) =>
this.renderRow(rows[index], {
listIndex: index,
style: rowStyle,
Expand All @@ -727,6 +728,7 @@ class ReactSortableTree extends Component {
swapFrom,
swapDepth: draggedDepth,
swapLength,
...rowProps,
})
}
{...reactVirtualizedListProps}
Expand Down