@@ -49,7 +49,7 @@ class SLDSLookup extends React.Component {
49
49
//=================================================
50
50
// Using down/up keys, set Focus on list item and assign it to aria-activedescendant attribute in input.
51
51
// Need to keep track of filtered list length to be able to increment/decrement the focus index so it's contained to the number of available list items.
52
- // Adding/subtracting 1 from focusIndex to account for fixed action items (searchDetails and addNewItem buttons)
52
+ // Adding/subtracting 1 from focusIndex to account for fixed action items (searchRecords and addNewItem buttons)
53
53
increaseIndex ( ) {
54
54
let items = this . state . listLength ;
55
55
this . setState ( { focusIndex : this . state . focusIndex <= items ? this . state . focusIndex + 1 : 0 } )
@@ -86,8 +86,14 @@ class SLDSLookup extends React.Component {
86
86
} ) ;
87
87
}
88
88
89
- addItem ( ) {
90
- if ( this . props . onAddItem ) this . props . onAddItem ( ) ;
89
+ newItem ( ) {
90
+ this . handleClose ( ) ;
91
+ if ( this . props . onNewItem ) this . props . onNewItem ( ) ;
92
+ }
93
+
94
+ searchRecords ( ) {
95
+ this . handleClose ( ) ;
96
+ if ( this . props . onSearchRecords ) this . props . onSearchRecords ( ) ;
91
97
}
92
98
93
99
//=================================================
@@ -135,9 +141,18 @@ class SLDSLookup extends React.Component {
135
141
//If user hits enter/space key, select current activedescendant item
136
142
else if ( ( event . keyCode === KEYS . ENTER || event . keyCode === KEYS . SPACE ) && this . state . focusIndex !== null ) {
137
143
EventUtil . trapImmediate ( event ) ;
138
- //If the focus is on the first or last item in the menu (search details or add item buttons), then close.
144
+ //If the focus is on the first fixed Action Item in Menu
145
+ if ( this . state . focusIndex === 0 ) {
146
+ this . searchRecords ( ) ;
147
+ }
148
+ //If the focus is on the last fixed Action Item in Menu
149
+ else if ( this . state . focusIndex === ( this . state . listLength + 1 ) ) {
150
+ this . newItem ( ) ;
151
+ }
139
152
//If not, then select menu item
140
- ( this . state . focusIndex === 0 || this . state . focusIndex === ( this . state . listLength + 1 ) ) ? this . handleClose ( ) : this . selectItem ( this . state . currentFocus ) ;
153
+ else {
154
+ this . selectItem ( this . state . currentFocus ) ;
155
+ }
141
156
}
142
157
}
143
158
}
@@ -166,15 +181,16 @@ class SLDSLookup extends React.Component {
166
181
getListLength = { this . getListLength . bind ( this ) }
167
182
setFocus = { this . setFocus . bind ( this ) }
168
183
onSelect = { this . selectItem . bind ( this ) }
169
- addItem = { this . addItem }
184
+ onSearchRecords = { this . searchRecords . bind ( this ) }
185
+ onNewItem = { this . newItem . bind ( this ) }
170
186
/> ;
171
187
}
172
188
}
173
189
174
190
renderSelectedItem ( ) {
175
191
let selectedItem = this . props . items [ this . state . selectedIndex ] . label ;
176
192
return (
177
- < a href = "# " className = "slds-pill" ref = { 'pill-' + this . state . selectedIndex } onKeyDown = { this . handlePillKeyDown . bind ( this ) } >
193
+ < span tabIndex = "0 " className = "slds-pill" ref = { 'pill-' + this . state . selectedIndex } onKeyDown = { this . handlePillKeyDown . bind ( this ) } >
178
194
< span className = "slds-pill__label" >
179
195
< Icon name = { this . props . type } />
180
196
{ selectedItem }
@@ -184,11 +200,10 @@ class SLDSLookup extends React.Component {
184
200
variant = 'icon'
185
201
iconName = 'close'
186
202
iconSize = 'medium'
187
- disabled = { true }
188
203
onClick = { this . handleDeleteSelected . bind ( this ) }
189
204
ref = "clearSelectedItemButton"
190
205
/>
191
- </ a >
206
+ </ span >
192
207
) ;
193
208
}
194
209
@@ -240,17 +255,15 @@ SLDSLookup.propTypes = {
240
255
type : React . PropTypes . string ,
241
256
filterWith : React . PropTypes . func ,
242
257
onItemSelect : React . PropTypes . func ,
243
- onAddItem : React . PropTypes . func ,
258
+ onNewItem : React . PropTypes . func ,
259
+ onSearchRecords : React . PropTypes . func ,
244
260
} ;
245
261
246
262
SLDSLookup . defaultProps = {
247
263
filterWith : defaultFilter ,
248
264
onItemSelect : function ( item ) {
249
265
//console.log('onItemSelect should be defined');
250
- } ,
251
- onAddItem : function ( event ) {
252
- //console.log('onItemSelect should be defined');
253
- } ,
266
+ }
254
267
} ;
255
268
256
269
module . exports = SLDSLookup ;
0 commit comments