Skip to content

Commit 94fcc93

Browse files
committed
Merge pull request #35 from salesforce-ux/lookups-refactor
Lookups refactor
2 parents c602c69 + dd19de6 commit 94fcc93

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

components/SLDSLookup/Menu/Item/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class Item extends React.Component {
3434

3535
handleClick(e){
3636
EventUtil.trapImmediate(e);
37-
console.log('>>> this.props.id: ',this.props.id);
3837
return this.props.onSelect(this.props.id);
3938
}
4039

components/SLDSLookup/index.jsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class SLDSLookup extends React.Component {
2525
super(props);
2626

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

3130
this.state = {
@@ -78,7 +77,7 @@ class SLDSLookup extends React.Component {
7877
selectedIndex: index,
7978
searchTerm: null
8079
});
81-
if(this.props.onItemSelect) this.props.onItemSelect();
80+
if(this.props.onItemSelect) this.props.onItemSelect(itemId);
8281
}
8382

8483
handleDeleteSelected() {
@@ -131,6 +130,7 @@ class SLDSLookup extends React.Component {
131130
handleChange(event) {
132131
const target = event.target || event.currentTarget;
133132
this.setState({searchTerm: target.value});
133+
if(this.props.onChange) this.props.onChange(target.value);
134134
}
135135

136136
handleKeyDown(event) {
@@ -228,7 +228,7 @@ class SLDSLookup extends React.Component {
228228
</span>
229229
<SLDSButton
230230
label='Press delete to remove'
231-
tabindex="-1"
231+
tabIndex="-1"
232232
variant='icon'
233233
iconName='close'
234234
iconSize='medium'
@@ -295,6 +295,7 @@ SLDSLookup.propTypes = {
295295
type: React.PropTypes.string,
296296
filterWith: React.PropTypes.func,
297297
onItemSelect: React.PropTypes.func,
298+
onChange: React.PropTypes.func,
298299
onNewItem: React.PropTypes.func,
299300
onSearchRecords: React.PropTypes.func,
300301
modal: React.PropTypes["bool"],
@@ -304,10 +305,7 @@ SLDSLookup.propTypes = {
304305
SLDSLookup.defaultProps = {
305306
filterWith: defaultFilter,
306307
modal: false,
307-
disabled: false,
308-
onItemSelect: function(item){
309-
//console.log('onItemSelect should be defined');
310-
}
308+
disabled: false
311309
};
312310

313311
module.exports = SLDSLookup;

demo/code-snippets/SLDSLookupPage.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,13 @@ const items = [
88
{label:'Acme Construction'}
99
];
1010

11-
<SLDSLookup items={items} label="Accounts" type="account" onNewItem={this.newItem} onSearchRecords={this.searchRecords} />
11+
<SLDSLookup
12+
items={items}
13+
label="Accounts"
14+
type="account"
15+
onChange={this.onChange}
16+
onItemSelect={this.onItemSelect}
17+
onNewItem={this.newItem}
18+
onSearchRecords={this.searchRecords} />
19+
1220

demo/pages/HomePage/LookupBaseDynamicSection.jsx

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

48+
onChange(newValue){
49+
console.log('New search term: ', newValue);
50+
},
51+
4852
handleItemSelect(item){
4953
console.log(item);
5054
},
@@ -55,10 +59,12 @@ module.exports = React.createClass( {
5559
<div className="slds-p-around--medium">
5660
Dynamic list
5761
<div className="slds-p-vertical--large">
58-
<SLDSLookup
62+
<SLDSLookup
5963
items={this.state.items}
6064
label="Accounts"
6165
type="account"
66+
onChange={this.onChange}
67+
onItemSelect={this.selectItem}
6268
onNewItem={this.newItem}
6369
onItemSelect={this.handleItemSelect}
6470
onSearchRecords={this.searchRecords}

demo/pages/HomePage/LookupBaseSection.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ module.exports = React.createClass( {
4444
alert('Search Records Clicked');
4545
},
4646

47+
onChange(newValue){
48+
console.log('New search term: ', newValue);
49+
},
50+
51+
selectItem(item){
52+
console.log(item + ' Selected');
53+
},
54+
4755
render() {
4856
return (
4957

@@ -60,10 +68,12 @@ module.exports = React.createClass( {
6068
</PrismCode>
6169

6270
<div className="slds-p-vertical--large">
63-
<SLDSLookup
71+
<SLDSLookup
6472
items={items}
6573
label="Accounts"
6674
type="account"
75+
onChange={this.onChange}
76+
onItemSelect={this.selectItem}
6777
onNewItem={this.newItem}
6878
onSearchRecords={this.searchRecords}
6979
/>

0 commit comments

Comments
 (0)