@@ -45,20 +45,25 @@ class SLDSLookup extends React.Component {
4545 }
4646
4747 getActiveDescendant ( ) {
48- console . log ( "aria-activedescendant is " , 'item-' + this . state . activeIndex ) ;
4948 return this . state . activeIndex !== null ? 'item-' + this . state . activeIndex : "" ;
5049 }
5150
5251 //=================================================
5352 // Select menu item (onClick or on key enter/space)
5453 selectItem ( index ) {
54+ //console.log('selectItem fired');
5555 this . setState ( {
5656 selectedIndex : index ,
5757 searchTerm : null
5858 } ) ;
59- console . log ( "Selected Item is " , this . props . items [ index ] ) ;
6059 }
6160
61+ handleDeleteSelected ( ) {
62+ this . setState ( {
63+ selectedIndex : null ,
64+ isOpen : false
65+ } ) ;
66+ }
6267
6368 //=================================================
6469 // Basic Event Listeners on Input
@@ -126,18 +131,38 @@ class SLDSLookup extends React.Component {
126131 }
127132 }
128133
134+ renderSelectedItem ( ) {
135+ return (
136+ < div className = "slds-pill" >
137+ < a href = "#" className = "slds-pill__label" >
138+ < span >
139+ < Icon name = "account" />
140+ { this . props . items [ this . state . selectedIndex ] . label }
141+ </ span >
142+ </ a >
143+ < button className = "slds-button slds-button--icon-bare" onClick = { this . handleDeleteSelected . bind ( this ) } ref = "clearSelectedItemButton" >
144+ < ButtonIcon name = "close" />
145+ < span className = "slds-assistive-text" > Remove</ span >
146+ </ button >
147+ </ div >
148+ ) ;
149+ }
150+
129151 render ( ) {
152+ let inputClasses = this . state . selectedIndex === null ? 'slds-input' :'slds-input slds-hide' ;
153+ let compClasses = this . state . selectedIndex === null ? "slds-lookup ignore-react-onclickoutside" :"slds-lookup ignore-react-onclickoutside slds-has-selection" ;
154+
130155 return (
131- < div className = "slds-lookup ignore-react-onclickoutside" data-select = "multi " data-scope = "single" data-typeahead = "true" >
156+ < div className = { compClasses } data-select = "single " data-scope = "single" data-typeahead = "true" >
132157 < section className = "slds-form-element" >
133158 < label className = "slds-form-element__label" forHTML = "lookup" > { this . props . label } </ label >
134159
135160 < div className = "slds-lookup__control slds-input-has-icon slds-input-has-icon--right" >
136- { this . state . currentSelectedItem ? this . state . currentSelectedItem : null }
161+ { this . state . selectedIndex ? this . renderSelectedItem ( ) : null }
137162 < InputIcon name = "search" />
138163 < input
139164 id = "lookup"
140- className = { 'slds-input' }
165+ className = { inputClasses }
141166 type = "text"
142167 aria-label = "lookup"
143168 aria-haspopup = "true"
@@ -147,6 +172,7 @@ class SLDSLookup extends React.Component {
147172 role = "combobox"
148173 onChange = { this . handleChange . bind ( this ) }
149174 onFocus = { this . handleFocus . bind ( this ) }
175+ onBlur = { this . handleBlur . bind ( this ) }
150176 onClick = { this . handleClick . bind ( this ) }
151177 onKeyDown = { this . handleKeyDown . bind ( this ) }
152178 value = { this . state . searchTerm } />
0 commit comments