react-sortable-tree icon indicating copy to clipboard operation
react-sortable-tree copied to clipboard

How to fill background color of a node

Open bfang711 opened this issue 7 years ago • 7 comments

I would like to fill node background with another color other than white, however seems like not able to. Here is what I did.

<SortableTree
            treeData={this.state.treeData}
            onChange={treeData => this.setState({ treeData })}
	    canDrag = {false}
	    getNodeKey = {({node})=> node.id}
            generateNodeProps={(({ node, path, treeIndex}) => {
		return ({
		    title: (
			<div style={{height:'100%', width:'100%', backgroundColor:'cyan'}} >
                        <Checkbox
			      label= {node.name}
			    />
                        </div>),})}}
/>

and this is how it looks. (I want color fill all the node background) image

Please let me know how to resolve it.

thank you so much.

bfang711 avatar May 16 '18 23:05 bfang711

you can generate a style prop. It isn't working right now because you are putting it in the title

ex:

return {
    title: //whatever u have here
    style: //whatever style u want
}

hope that helps!

wuweiweiwu avatar May 18 '18 06:05 wuweiweiwu

Can you provide an example for what that style prop might look like?

davidgolden avatar Jun 20 '18 20:06 davidgolden

@davidgolden the style prop would look something like this { backgroundColor: 'black' }. The standard react css in js -> https://reactjs.org/docs/faq-styling.html

Hope that helps!

wuweiweiwu avatar Jun 28 '18 09:06 wuweiweiwu

It does not seem to work with backgroundColor using generateNodeProps, is there any way to programatically set the background color of the entire node?

mtrsklnkvMM avatar Oct 10 '18 11:10 mtrsklnkvMM

Hi, I was having the same problem, and setting backgroundColor to black doesn't seem to work. Any suggestions, on how to style this react sortable trees?

ut2k avatar Aug 11 '20 19:08 ut2k

Hi, I am having the same issue, using background / backgroundColor doesn't have any effect.

Punith13 avatar Oct 12 '21 18:10 Punith13

Hi, the reason behind that is that props returned from generateNodeProps are applied to the whole node "row" container, and not the node contents. If you look closely, you may notice that the background color applied via the style prop is "shining through" at the rounded edges of the drag handle and the node contents rectangles (only).

You could work around this by either creating a custom nodeContentRenderer (see node-renderer-default.js for the default renderer), or by defining CSS classes which target the node content element.

Example for the latter:

JSX prop generateNodeProps={ () => ({ className: 'red-node' }) }

CSS class

.red-node .rst__rowContents {
  background-color: red;
}

asilberschneider avatar Oct 12 '21 19:10 asilberschneider