fortunar / react-sidemenu

React sidemenu component
57 stars 14 forks source link

"activeItem" does'nt change display of the true selected item #13

Closed fcollignon closed 6 years ago

fcollignon commented 6 years ago

If "activeItem" property is set by an external action after rendering of SideMenu, the display of new "Item" is not updated.

  1. "activeItem" property is used to intialize component.
  2. After, active Item is set by clicking on each Item of SideMenu
  3. But, if an external button change value of "activeItem" property, the SideMenu is not render and the look&feel of new active Item is not updated.

Basic example :

`import React, {Component} from 'react'; import {SideMenu, Item} from 'react-sidemenu';

export default class PortalSideMenu extends Component { constructor(props) { super(props); this.changeItem = this.changeItem.bind(this); this.state = { activeItem:'/dashboard/requests' } }

changeItem(item) {
    this.setState({activeItem: item});
}

render() {
    return (
        <div>
            <button onClick={() => this.changeItem('/dashboard/tasks')}>Change</button>
            <h4>{this.state.activeItem}</h4>
            <SideMenu activeItem={this.state.activeItem}>
                <Item label="Dashboard" icon="fa-tachometer">
                    <Item label="Tasks" value="/dashboard/tasks" icon="fa-folder-open"/>
                    <Item label="Requests" value="/dashboard/requests" icon="fa-folder-open"/>
                </Item>
            </SideMenu>
        </div>
    );
}

}`

fortunar commented 6 years ago

Implemented in 0.0.14.