Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Collapse / Expand not working #58

Closed
mnboos opened this issue Mar 2, 2017 · 12 comments
Closed

Collapse / Expand not working #58

mnboos opened this issue Mar 2, 2017 · 12 comments
Assignees
Labels
🐛 bug Something isn't working

Comments

@mnboos
Copy link

mnboos commented Mar 2, 2017

Hi alexcurtis
I've the the same problem as in issue #27
The tree is shown correctly on initial render but clicking nodes does nothing - can't expand/collapse, active node not highlighted.

@sonuj
Copy link

sonuj commented Mar 2, 2017

expand and collapse of parent node is not working

@emilyfeder
Copy link

emilyfeder commented Mar 10, 2017

I think it's because React is not registering it as a state change and is not calling render() again.
Also, I think ideally onToggle should switch the node toggled state internally inside the Treebeard Component instead of you having to manually do it each time.
Try the following instead (I haven't actually tested this, as a fair warning):

class TreeExample extends React.Component {
	constructor(props){
		super(props);
		this.state = {
			data: props.data
		};
		this.onToggle = this.onToggle.bind(this);
	}
	onToggle(node, toggled){
		if(this.state.cursor){this.state.cursor.active = false;}
		node.active = true;
		let new_data = this.state.data;
		if(node.children){
			node.toggled = toggled;
			new_data = Object.assign({}, this.state.data);
		}
		this.setState({ cursor: node, data: new_data });
	}
	render(){
		return (
			<Treebeard
				data={this.state.data}
				onToggle={this.onToggle}
			/>
		);
	}
}

@skohub
Copy link

skohub commented Sep 4, 2017

Possibly you have put

const data = {
    name: 'root',
    ...
}

inside render method, so the data is being rewritten from scratch on every click.

@Waize
Copy link

Waize commented Jun 13, 2018

There is an issue with the animations.
If you turn them off:
<Treebeard data={data} onToggle={this.onToggle} animation={false}/>
It works fine.
Maybe @MichaelDeBoey needs to double check the animation conditions in renderDrawer from node.js

@Waize
Copy link

Waize commented Jun 25, 2018

#111

@Waize
Copy link

Waize commented May 2, 2019

@maximilianoforlenza with #174 this issue is worse than before:
with this workaround here (animation == false) it will not toggle at all, although working fine before
removing animations-flag will still not bring animations back.

@Waize
Copy link

Waize commented May 10, 2019

@maximilianoforlenza any news on this?

@maximilianoforlenza maximilianoforlenza added the 🐛 bug Something isn't working label May 10, 2019
@maximilianoforlenza maximilianoforlenza self-assigned this May 10, 2019
@maximilianoforlenza
Copy link
Collaborator

No yet. I'll working on this today.

@maximilianoforlenza
Copy link
Collaborator

maximilianoforlenza commented May 10, 2019

@Waize please try this https://codesandbox.io/s/7jkkj5vkn1 (#209)

@Waize
Copy link

Waize commented May 10, 2019 via email

@maximilianoforlenza
Copy link
Collaborator

maximilianoforlenza commented May 10, 2019

No, you should fork the project, back to version 2.1.1 fix it and use the forked version.

@maximilianoforlenza
Copy link
Collaborator

If it's working https://codesandbox.io/s/7jkkj5vkn1 I close this issue @Waize

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛 bug Something isn't working
Development

No branches or pull requests

6 participants