Skip to content

Commit ff80ca9

Browse files
committed
lookup sections progress
1 parent dcb042e commit ff80ca9

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

components/SLDSLookup/Menu/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Menu extends React.Component {
7070
}
7171

7272
getFilteredItemForIndex(i){
73-
if(i && this.state.filteredItems && i< this.state.filteredItems.length){
73+
if(i>-1 && this.state.filteredItems && i< this.state.filteredItems.length){
7474
return this.state.filteredItems[i];
7575
}
7676
}

components/SLDSLookup/index.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ class SLDSLookup extends React.Component {
162162
this.setState({items: items});
163163
}
164164

165+
setFirstIndex(){
166+
let numFocusable = this.getNumFocusableItems();
167+
let nextFocusIndex = 0;
168+
let filteredItem = this.state.items[0];
169+
if(this.refs.menu && this.refs.menu.getFilteredItemForIndex){
170+
filteredItem = this.refs.menu.getFilteredItemForIndex(nextFocusIndex);
171+
}
172+
if(filteredItem && filteredItem.data.type === 'section'){
173+
nextFocusIndex++;
174+
}
175+
this.setState({ focusIndex: nextFocusIndex });
176+
}
165177
//=================================================
166178
// Using down/up keys, set Focus on list item and assign it to aria-activedescendant attribute in input.
167179
// 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.
@@ -295,7 +307,7 @@ class SLDSLookup extends React.Component {
295307
//If user hits down key, advance aria activedescendant to next item
296308
if(event.keyCode === KEYS.DOWN){
297309
EventUtil.trapImmediate(event);
298-
this.state.focusIndex === null ? this.setState({ focusIndex: 0 }) : this.increaseIndex();
310+
this.state.focusIndex === null ? this.setFirstIndex() : this.increaseIndex();
299311
}
300312
//If user hits up key, advance aria activedescendant to previous item
301313
else if(event.keyCode === KEYS.UP){

0 commit comments

Comments
 (0)