Skip to content

Commit 0f054b5

Browse files
committed
Merge pull request #4 from ux/master
Merge master into gh-pages
2 parents 27a9661 + 86edfb1 commit 0f054b5

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

components/SLDSLookup/Menu/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ class Menu extends React.Component {
5757

5858
render(){
5959
let isNewItemBtnActive = false;
60-
let isSearchDetailsActive = false;
60+
let isSearchRecordsActive = false;
6161
this.props.focusIndex === this.props.listLength + 1 ? isNewItemBtnActive = true : isNewItemBtnActive = false;
62-
this.props.focusIndex === 0 ? isSearchDetailsActive = true: isSearchDetailsActive = false;
62+
this.props.focusIndex === 0 ? isSearchRecordsActive = true: isSearchRecordsActive = false;
6363

6464
return (
6565
<div className="ignore-react-onclickoutside slds-lookup__menu" role="listbox" ref="scroll">
6666
<div className="slds-lookup__item">
6767
<ActionItem
68-
id='searchDetails'
68+
id='searchRecords'
6969
icon='search'
7070
type={this.props.type}
71-
isActive={isSearchDetailsActive}
71+
isActive={isSearchRecordsActive}
7272
setFocus={this.props.setFocus}
73-
onSelect={this.props.addItem}
73+
onSelect={this.props.onSearchRecords}
7474
>
7575
{this.props.searchTerm ? '"' + this.props.searchTerm + '"' : ""} in {this.props.type + 's'}
7676
</ActionItem>
@@ -87,7 +87,7 @@ class Menu extends React.Component {
8787
type={this.props.type}
8888
isActive={isNewItemBtnActive}
8989
setFocus={this.props.setFocus}
90-
onSelect={this.props.addItem}
90+
onSelect={this.props.onNewItem}
9191
>
9292
New {this.props.type}
9393
</ActionItem>

components/SLDSLookup/index.jsx

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class SLDSLookup extends React.Component {
4949
//=================================================
5050
// Using down/up keys, set Focus on list item and assign it to aria-activedescendant attribute in input.
5151
// 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.
52-
// Adding/subtracting 1 from focusIndex to account for fixed action items (searchDetails and addNewItem buttons)
52+
// Adding/subtracting 1 from focusIndex to account for fixed action items (searchRecords and addNewItem buttons)
5353
increaseIndex(){
5454
let items = this.state.listLength;
5555
this.setState({ focusIndex: this.state.focusIndex <= items ? this.state.focusIndex + 1 : 0 })
@@ -86,8 +86,14 @@ class SLDSLookup extends React.Component {
8686
});
8787
}
8888

89-
addItem(){
90-
if(this.props.onAddItem) this.props.onAddItem();
89+
newItem(){
90+
this.handleClose();
91+
if(this.props.onNewItem) this.props.onNewItem();
92+
}
93+
94+
searchRecords(){
95+
this.handleClose();
96+
if(this.props.onSearchRecords) this.props.onSearchRecords();
9197
}
9298

9399
//=================================================
@@ -135,9 +141,18 @@ class SLDSLookup extends React.Component {
135141
//If user hits enter/space key, select current activedescendant item
136142
else if((event.keyCode === KEYS.ENTER || event.keyCode === KEYS.SPACE) && this.state.focusIndex !== null){
137143
EventUtil.trapImmediate(event);
138-
//If the focus is on the first or last item in the menu (search details or add item buttons), then close.
144+
//If the focus is on the first fixed Action Item in Menu
145+
if(this.state.focusIndex === 0){
146+
this.searchRecords();
147+
}
148+
//If the focus is on the last fixed Action Item in Menu
149+
else if(this.state.focusIndex === (this.state.listLength + 1)){
150+
this.newItem();
151+
}
139152
//If not, then select menu item
140-
(this.state.focusIndex === 0 || this.state.focusIndex === (this.state.listLength + 1)) ? this.handleClose() : this.selectItem(this.state.currentFocus);
153+
else{
154+
this.selectItem(this.state.currentFocus);
155+
}
141156
}
142157
}
143158
}
@@ -166,15 +181,16 @@ class SLDSLookup extends React.Component {
166181
getListLength={this.getListLength.bind(this)}
167182
setFocus={this.setFocus.bind(this)}
168183
onSelect={this.selectItem.bind(this)}
169-
addItem={this.addItem}
184+
onSearchRecords={this.searchRecords.bind(this)}
185+
onNewItem={this.newItem.bind(this)}
170186
/>;
171187
}
172188
}
173189

174190
renderSelectedItem(){
175191
let selectedItem = this.props.items[this.state.selectedIndex].label;
176192
return (
177-
<a href="#" className="slds-pill" ref={'pill-' + this.state.selectedIndex} onKeyDown={this.handlePillKeyDown.bind(this)}>
193+
<span tabIndex="0" className="slds-pill" ref={'pill-' + this.state.selectedIndex} onKeyDown={this.handlePillKeyDown.bind(this)}>
178194
<span className="slds-pill__label">
179195
<Icon name={this.props.type} />
180196
{selectedItem}
@@ -184,11 +200,10 @@ class SLDSLookup extends React.Component {
184200
variant='icon'
185201
iconName='close'
186202
iconSize='medium'
187-
disabled={true}
188203
onClick={this.handleDeleteSelected.bind(this)}
189204
ref="clearSelectedItemButton"
190205
/>
191-
</a>
206+
</span>
192207
);
193208
}
194209

@@ -240,17 +255,15 @@ SLDSLookup.propTypes = {
240255
type: React.PropTypes.string,
241256
filterWith: React.PropTypes.func,
242257
onItemSelect: React.PropTypes.func,
243-
onAddItem: React.PropTypes.func,
258+
onNewItem: React.PropTypes.func,
259+
onSearchRecords: React.PropTypes.func,
244260
};
245261

246262
SLDSLookup.defaultProps = {
247263
filterWith: defaultFilter,
248264
onItemSelect: function(item){
249265
//console.log('onItemSelect should be defined');
250-
},
251-
onAddItem: function(event){
252-
//console.log('onItemSelect should be defined');
253-
},
266+
}
254267
};
255268

256269
module.exports = SLDSLookup;

demo/code-snippets/SLDSLookupPage.txt

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

11-
<SLDSLookup items={items} label="Accounts" type="account" />
11+
<SLDSLookup items={items} label="Accounts" type="account" onNewItem={this.newItem} onSearchRecords={this.searchRecords} />
1212

demo/pages/HomePage/LookupBaseSection.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ module.exports = React.createClass( {
3636
return {};
3737
},
3838

39+
newItem(){
40+
alert('New Item Clicked');
41+
},
42+
43+
searchRecords(){
44+
alert('Search Records Clicked');
45+
},
46+
3947
render() {
4048
return (
4149

@@ -52,7 +60,7 @@ module.exports = React.createClass( {
5260
</PrismCode>
5361

5462
<div className="slds-p-vertical--large">
55-
<SLDSLookup items={items} label="Accounts" type="account" />
63+
<SLDSLookup items={items} label="Accounts" type="account" onNewItem={this.newItem} onSearchRecords={this.searchRecords} />
5664
</div>
5765

5866
</div>

0 commit comments

Comments
 (0)