trendmicro-frontend / react-sidenav

React SideNav component

Home Page:https://trendmicro-frontend.github.io/react-sidenav/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to collapse the side navigation bar on purpose?

andreydung opened this issue · 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.

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.