0

Im trying to use a Selectable list of items in my Drawer Component. Im using the sample code define in the Material-ui documentation (Material-UI List Documentation), but things are not working as expected. Can anyone here helps me with a basic sample code using Selectable list or point me any good documentation or tutorial.

import React from 'react';
import Component from 'react';
import PropTypes from 'react';
import MobileTearSheet from '../../../MobileTearSheet';
import {List, ListItem, MakeSelectable} from 'material-ui/List';
import Avatar from 'material-ui/Avatar';
import Subheader from 'material-ui/Subheader';

let SelectableList = MakeSelectable(List);

function wrapState(ComposedComponent) {
    return class SelectableList extends Component {
        static propTypes = {
            children: PropTypes.node.isRequired,
            defaultValue: PropTypes.number.isRequired,
        };

        componentWillMount() {
            this.setState({
                selectedIndex: this.props.defaultValue,
            });
        }

        handleRequestChange = (event, index) => {
            this.setState({
                selectedIndex: index,
            });
        };

        render() {
            return (
                <ComposedComponent value={this.state.selectedIndex} onChange={this.handleRequestChange}>
                    {this.props.children}
                </ComposedComponent>
            );
        }
    };
}

SelectableList = wrapState(SelectableList);

const ListExampleSelectable = () => (
    <MobileTearSheet>
        <SelectableList defaultValue={3}>
            <Subheader>Selectable Contacts</Subheader>
            <ListItem
                value={1}
                primaryText="Brendan Lim"
                leftAvatar={<Avatar src="/images/obenbasic.png" />}
                nestedItems={[
          <ListItem
            value={2}
            primaryText="Grace Ng"
            leftAvatar={<Avatar src="/images/obenbasic.png" />}
          />,
        ]}
            />
            <ListItem
                value={3}
                primaryText="Kerem Suer"
                leftAvatar={<Avatar src="/images/obenbasic.png" />}
            />
            <ListItem
                value={4}
                primaryText="Eric Hoffman"
                leftAvatar={<Avatar src="/images/obenbasic.png" />}
            />
            <ListItem
                value={5}
                primaryText="Raquel Parrado"
                leftAvatar={<Avatar src="/images/obenbasic.png" />}
            />
        </SelectableList>
    </MobileTearSheet>
);

export default ListExampleSelectable;

and I use the Selectable List like this:

<Drawer open={false} width="180px" >
   <MenuItem primaryText="MENU ITEM" />
   <ListExampleSelectable />
</Drawer>

I hope this will give you an idea of what i'm doing...

kprim
  • 233
  • 1
  • 5
  • 9
  • Can you provide details of what you mean by "not working as expected"? Or if you're only looking for a resource to help you learn then I think that's outside of the scope of Stack Overflow. – Ben Hare Sep 05 '16 at 20:53
  • Well, im not allowed, to provide my source here, if that's the point of your comment. – kprim Sep 05 '16 at 20:57
  • Can you provide even the error message or what's happening if you can't provide the source code? No one will be able to help you without at least a bit of specificity. – Ben Hare Sep 05 '16 at 21:02
  • Let's assume i have the entire [sample code of selectable list](http://www.material-ui.com/#/components/list) in a jsx file, when i do an import of the 'ListExampleSelectable' component in my Drawer i have the following error in the jsx file (Module build failed: SyntaxError: Unexpected token (13:25)). – kprim Sep 05 '16 at 21:24
  • Im just trying to figure out how to use the selectable list component from material-ui, because obviously im doing something wrong. – kprim Sep 05 '16 at 21:28
  • See your error? it says SyntaxError. There is something wrong with your syntax. If you don't show us your code, even partially, we won't be able to find the mistake on your syntax. – JFAP Sep 05 '16 at 23:39
  • I just added some snippet, like i said, im just trying to use the sample code of selectable list from material-ui documentation. I will edit my own selectable list as soon as i will figure out how the component works and how to use it. thank you guys. – kprim Sep 06 '16 at 05:03

1 Answers1

0

I finally realised why it was not working. More details on this post : SelectableList does not display Selected item when selection change

Community
  • 1
  • 1
kprim
  • 233
  • 1
  • 5
  • 9