react-sidenav icon indicating copy to clipboard operation
react-sidenav copied to clipboard

How to collapse the side navigation bar on purpose?

Open andreydung opened this issue 5 years ago • 1 comments

How could I collapse the navigation bar on purpose? I want it to collapse after each selection, i.e. if you choose Home the sidebar should minimize right away.

I tried the following:

                            onSelect={(selected) => {
                                const to = '/' + selected;
                                if (location.pathname !== to) {
                                    history.push(to);
                                }
                                this.setState({ expanded: false });

But it does not work yet.

andreydung avatar Apr 22 '20 18:04 andreydung

From what I can tell, the state inside the sidebar gets updated on click of the toggle; but does not update on componentDidUpdate from props changing. It would be great if that were added. You can achieve what you are looking for by putting app.js inside of your router so that whenever a new url is pushed to props.history the whole page re-renders which clears the state of the sidebar. Not the best solution but this could achieve what you are looking to do.

dscarlin avatar May 03 '20 15:05 dscarlin