Skip to content

Commit c602c69

Browse files
committed
fix Lookup index issue
1 parent 09f0ffb commit c602c69

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

components/SLDSLookup/Menu/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Menu extends React.Component {
3939
return this.props.items.filter(this.filter, this).map((c, i) => {
4040
//isActive means it is aria-activedescendant
4141
const isActive = this.props.focusIndex === i + 1 ? true : false;
42-
const id = 'item-'+i;
42+
const id = c.id;
4343
return <Item
4444
key={id}
4545
id={id}

components/SLDSLookup/index.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class SLDSLookup extends React.Component {
2626

2727
//Dynamically assign ids to list items to reference for focusing and selecting items
2828
// this.props.items.map((item, index) => { return item.id = 'item-' + index; })
29+
this.modifyItems();
2930

3031
this.state = {
3132
searchTerm: '',
@@ -238,6 +239,14 @@ class SLDSLookup extends React.Component {
238239
);
239240
}
240241

242+
modifyItems () {
243+
this.props.items.map((item, index) => { return item.id = 'item-' + index; })
244+
}
245+
246+
componentWillReceiveProps (newProps) {
247+
this.modifyItems();
248+
}
249+
241250
render(){
242251
let inputClasses = this.state.selectedIndex === null ? 'slds-input':'slds-input slds-hide';
243252
let componentClasses = this.state.selectedIndex === null ? "slds-lookup ignore-react-onclickoutside":"slds-lookup ignore-react-onclickoutside slds-has-selection";

demo/pages/HomePage/LookupBaseDynamicSection.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ module.exports = React.createClass( {
4545
alert('Search Records Clicked');
4646
},
4747

48+
handleItemSelect(item){
49+
console.log(item);
50+
},
51+
4852
render() {
4953
return (
5054

@@ -56,6 +60,7 @@ module.exports = React.createClass( {
5660
label="Accounts"
5761
type="account"
5862
onNewItem={this.newItem}
63+
onItemSelect={this.handleItemSelect}
5964
onSearchRecords={this.searchRecords}
6065
/>
6166
</div>

0 commit comments

Comments
 (0)