Skip to content

Commit 3e8ef57

Browse files
committed
OnSelect for click works for filtered and nonfiltered lists. Bug in
keyboard interaction.
1 parent 3fb3391 commit 3e8ef57

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

components/SLDSLookup/Menu/Item/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Item extends React.Component {
3131
e.nativeEvent.preventDefault();
3232
e.nativeEvent.stopImmediatePropagation();
3333
}
34-
return this.props.onSelect(this.props.index);
34+
return this.props.onSelect(this.props.id);
3535
}
3636

3737
render(){
@@ -57,7 +57,7 @@ class Item extends React.Component {
5757
onClick={this.handleClick.bind(this)}
5858
onMouseDown={this.handleClick.bind(this)}>
5959
<Icon name="account" />
60-
{ this.boldSearchText(this.props.children) }
60+
{ this.boldSearchText(this.props.children.label) }
6161
</a>
6262
</li>
6363
)

components/SLDSLookup/Menu/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Menu extends React.Component {
2626
return this.props.items.filter(this.filter, this).map((c, i) => {
2727
//isActive means it is aria-activedescendant
2828
const isActive = this.props.activeIndex === i ? true : false;
29-
return <Item key={i} id={'item-' + i} index={i} isActive={isActive} onSelect={this.props.onSelect} searchTerm={this.props.searchTerm}>{c}</Item>
29+
return <Item key={c.id} id={c.id} index={i} isActive={isActive} onSelect={this.props.onSelect} searchTerm={this.props.searchTerm}>{c}</Item>
3030
});
3131
}
3232

components/SLDSLookup/index.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const defaultFilter = (term, item) => {
2222
class SLDSLookup extends React.Component {
2323
constructor(props) {
2424
super(props);
25+
this.props.items.map((item, index) => {
26+
return item.id = 'item-' + index;
27+
})
28+
2529
this.state = {
2630
searchTerm: '',
2731
isOpen:false,
@@ -50,8 +54,9 @@ class SLDSLookup extends React.Component {
5054

5155
//=================================================
5256
// Select menu item (onClick or on key enter/space)
53-
selectItem(index){
57+
selectItem(itemId){
5458
//console.log('selectItem fired');
59+
let index = itemId.replace('item-', '');
5560
this.setState({
5661
selectedIndex: index,
5762
searchTerm: null
@@ -177,7 +182,7 @@ class SLDSLookup extends React.Component {
177182
role="combobox"
178183
onChange={this.handleChange.bind(this)}
179184
onFocus={this.handleFocus.bind(this)}
180-
onBlur={this.handleBlur.bind(this)}
185+
//onBlur={this.handleBlur.bind(this)}
181186
onClick={this.handleClick.bind(this)}
182187
onKeyDown={this.handleKeyDown.bind(this)}
183188
value={this.state.searchTerm} />

0 commit comments

Comments
 (0)