@@ -25,16 +25,22 @@ class SLDSLookup extends React.Component {
2525 super ( props ) ;
2626
2727 //Dynamically assign ids to list items to reference for focusing and selecting items
28- this . modifyItems ( ) ;
2928
3029 this . state = {
3130 searchTerm : '' ,
3231 isOpen :false ,
3332 currentFocus :null ,
3433 focusIndex :null ,
3534 selectedIndex : null ,
36- listLength :this . props . items . length
35+ listLength :this . props . items . length ,
36+ items :[ ]
3737 } ;
38+
39+
40+ }
41+
42+ componentDidMount ( ) {
43+ this . modifyItems ( ) ;
3844 }
3945
4046 componentDidUpdate ( prevProps , prevState ) {
@@ -71,13 +77,13 @@ class SLDSLookup extends React.Component {
7177
7278 //=================================================
7379 // Select menu item (onClick or on key enter/space)
74- selectItem ( itemId ) {
75- let index = itemId . replace ( 'item-' , '' ) ;
80+ selectItem ( itemId , data ) {
81+ const index = itemId . replace ( 'item-' , '' ) ;
7682 this . setState ( {
7783 selectedIndex : index ,
7884 searchTerm : null
7985 } ) ;
80- if ( this . props . onItemSelect ) this . props . onItemSelect ( itemId ) ;
86+ if ( this . props . onItemSelect ) this . props . onItemSelect ( data ) ;
8187 }
8288
8389 handleDeleteSelected ( ) {
@@ -186,7 +192,7 @@ class SLDSLookup extends React.Component {
186192 type = { this . props . type }
187193 focusIndex = { this . state . focusIndex }
188194 listLength = { this . state . listLength }
189- items = { this . props . items }
195+ items = { this . state . items }
190196 filterWith = { this . props . filterWith }
191197 getListLength = { this . getListLength . bind ( this ) }
192198 setFocus = { this . setFocus . bind ( this ) }
@@ -240,7 +246,15 @@ class SLDSLookup extends React.Component {
240246 }
241247
242248 modifyItems ( ) {
243- this . props . items . map ( ( item , index ) => { return item . id = 'item-' + index ; } )
249+ const items = this . props . items . map ( ( item , index ) => {
250+ return {
251+ id : 'item-' + index ,
252+ label : item . label ,
253+ data : item
254+ }
255+ } ) ;
256+
257+ this . setState ( { items :items } ) ;
244258 }
245259
246260 componentWillReceiveProps ( newProps ) {
0 commit comments