Skip to content

Commit d4b457a

Browse files
committed
Add onChange to lookup
1 parent 0aa24a5 commit d4b457a

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ 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; })
28+
//this.props.items.map((item, index) => { return item.id = 'item-' + index; })
29+
2930

3031
this.state = {
3132
searchTerm: '',
@@ -77,7 +78,7 @@ class SLDSLookup extends React.Component {
7778
selectedIndex: index,
7879
searchTerm: null
7980
});
80-
if(this.props.onItemSelect) this.props.onItemSelect();
81+
if(this.props.onItemSelect) this.props.onItemSelect(itemId);
8182
}
8283

8384
handleDeleteSelected() {
@@ -130,6 +131,7 @@ class SLDSLookup extends React.Component {
130131
handleChange(event) {
131132
const target = event.target || event.currentTarget;
132133
this.setState({searchTerm: target.value});
134+
if(this.props.onChange) this.props.onChange(target.value);
133135
}
134136

135137
handleKeyDown(event) {
@@ -227,7 +229,7 @@ class SLDSLookup extends React.Component {
227229
</span>
228230
<SLDSButton
229231
label='Press delete to remove'
230-
tabindex="-1"
232+
tabIndex="-1"
231233
variant='icon'
232234
iconName='close'
233235
iconSize='medium'
@@ -286,6 +288,7 @@ SLDSLookup.propTypes = {
286288
type: React.PropTypes.string,
287289
filterWith: React.PropTypes.func,
288290
onItemSelect: React.PropTypes.func,
291+
onChange: React.PropTypes.func,
289292
onNewItem: React.PropTypes.func,
290293
onSearchRecords: React.PropTypes.func,
291294
modal: React.PropTypes["bool"],
@@ -295,10 +298,7 @@ SLDSLookup.propTypes = {
295298
SLDSLookup.defaultProps = {
296299
filterWith: defaultFilter,
297300
modal: false,
298-
disabled: false,
299-
onItemSelect: function(item){
300-
//console.log('onItemSelect should be defined');
301-
}
301+
disabled: false
302302
};
303303

304304
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,26 @@ module.exports = React.createClass( {
4545
alert('Search Records Clicked');
4646
},
4747

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

5159
<div className="slds-p-around--medium">
5260
Dynamic list
5361
<div className="slds-p-vertical--large">
54-
<SLDSLookup
62+
<SLDSLookup
5563
items={this.state.items}
5664
label="Accounts"
5765
type="account"
66+
onChange={this.onChange}
67+
onItemSelect={this.selectItem}
5868
onNewItem={this.newItem}
5969
onSearchRecords={this.searchRecords}
6070
/>

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)