I have an issue with a SelectableList. When i display the list for the first time, the default defined item is selected in the list. But when i click on a different item of the list, the item does not appears as selected in the list, and the index is undefined
. any suggestions ?
This is the sample code of my SelectableList
:
import React from 'react';
import {List, ListItem, MakeSelectable} from 'material-ui/List';
import Avatar from 'material-ui/Avatar';
const SelectableList = MakeSelectable(List);
class ListExampleSelectable extends React.Component {
constructor() {
super();
}
componentWillMount() {
this.setState({
selectedIndex: this.props.defaultValue,
});
}
handleRequestChange(event, index) {
this.setState({
selectedIndex: index,
});
console.log(index);
};
render() {
return (
<SelectableList value = {this.state.selectedIndex}
onClick = {this.handleRequestChange.bind(this)} >
<ListItem value="1" primaryText="Menu1" leftAvatar={<Avatar src="img1.png" />}/>
<ListItem value="2" primaryText="Menu2" leftAvatar={<Avatar src="img2.png" />}/>
<ListItem value="3" primaryText="Menu3" leftAvatar={<Avatar src="img3.png" />}/>
</SelectableList>
);
}
}
export default ListExampleSelectable;
and i use my component like this:
import MyList from './ExampleSelectable.jsx';
and inside a drawer i have :
<MyList defaultValue="1"/>
The list is displayed with the first item selected, but when i click on a different item, the selection does not move on the clicked item.