Skip to content

Commit 4bb25c3

Browse files
committed
Merge pull request #21 from salesforce-ux/lookups-refactor
Lookups refactor
2 parents 8c6834e + a63f2be commit 4bb25c3

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

components/SLDSLookup/Menu/index.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88
*/
99

1010
import React, { Component } from 'react';
11-
import {Icon} from "../../SLDSIcons";
12-
import {KEYS} from '../../utils';
1311
import Item from './Item';
12+
import {Icon} from "../../SLDSIcons";
1413

1514
class Menu extends React.Component {
1615
constructor(props){
1716
super(props);
1817
this.state = {};
1918
}
2019

21-
componentDidUpdate(){
20+
componentDidUpdate(prevProps, prevState){
2221
let list = React.findDOMNode(this.refs.list).children.length;
2322
this.props.getListLength(list);
2423
}
@@ -49,6 +48,26 @@ class Menu extends React.Component {
4948
});
5049
}
5150

51+
renderEmptyState(){
52+
let className = 'slds-lookup__item';
53+
return (
54+
<li
55+
className={className}
56+
role="presentaion">
57+
<a
58+
href='#'
59+
id='add-item'
60+
tabIndex="-1"
61+
role="option"
62+
onClick={this.props.addItem}
63+
onMouseDown={this.props.addItem}>
64+
<Icon name="add" category="utility" size="x-small" className="slds-icon-text-default" />
65+
New {this.props.type}
66+
</a>
67+
</li>
68+
);
69+
}
70+
5271
render(){
5372
return (
5473
<div
@@ -59,6 +78,7 @@ class Menu extends React.Component {
5978
role="presentation"
6079
ref="list">
6180
{this.renderItems()}
81+
{this.renderEmptyState()}
6282
</ul>
6383
</div>
6484
)

components/SLDSLookup/index.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
99

1010
import React, { Component } from 'react';
1111
import Menu from './Menu';
12-
import {InputIcon, ButtonIcon} from "./../SLDSIcons";
13-
import {Icon} from "../SLDSIcons";
12+
import {Icon, InputIcon, ButtonIcon} from "./../SLDSIcons";
1413
import {KEYS,EventUtil} from '../utils';
1514
import escapeRegExp from 'lodash.escaperegexp';
1615

@@ -36,6 +35,12 @@ class SLDSLookup extends React.Component {
3635
};
3736
}
3837

38+
componentDidUpdate(prevProps, prevState){
39+
if(prevState.selectedIndex && !this.state.selectIndex){
40+
if(this.refs.lookup) React.findDOMNode(this.refs.lookup).focus();
41+
}
42+
}
43+
3944
//=================================================
4045
// Using down/up keys, set Focus on list item and assign it to aria-activedescendant attribute in input.
4146
// 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.
@@ -72,7 +77,7 @@ class SLDSLookup extends React.Component {
7277
handleDeleteSelected() {
7378
this.setState({
7479
selectedIndex: null,
75-
isOpen: false
80+
isOpen: true,
7681
});
7782
}
7883

@@ -144,7 +149,10 @@ class SLDSLookup extends React.Component {
144149
setFocus={this.setFocus.bind(this)}
145150
getListLength={this.getListLength.bind(this)}
146151
listLength={this.state.listLength}
147-
focusIndex={this.state.focusIndex}/>;
152+
focusIndex={this.state.focusIndex}
153+
addItem={this.props.addItem}
154+
type={this.props.type}
155+
/>;
148156
}else{
149157
return null;
150158
}
@@ -181,6 +189,7 @@ class SLDSLookup extends React.Component {
181189
<InputIcon name="search"/>
182190
<input
183191
id="lookup"
192+
ref="lookup"
184193
className={inputClasses}
185194
type="text"
186195
aria-label="lookup"

demo/pages/HomePage/LookupBaseSection.jsx

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

39+
addItem(){
40+
alert('Add item clicked');
41+
},
42+
3943

4044
render() {
4145
return (
@@ -53,7 +57,7 @@ module.exports = React.createClass( {
5357
</PrismCode>
5458

5559
<div className="slds-p-vertical--large">
56-
<SLDSLookup items={items} label="Contacts" />
60+
<SLDSLookup items={items} label="Accounts" type="account" addItem={this.addItem} />
5761
</div>
5862

5963
</div>

demo/pages/HomePage/ModalSection.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ Utilize our detailed guidelines to confidently design excellent apps that fit ri
9797
isOpen={this.state.modalIsOpen}
9898
title={<span>Lightning Design System: Style with Ease</span>}
9999
footer={[
100-
<SLDSButton label='Cancel' variant='neutral' onClick={this.closeModal} />,
101-
<SLDSButton label='Save' variant='brand' onClick={this.handleSubmitModal} />
100+
<SLDSButton key='cancelBtn' label='Cancel' variant='neutral' onClick={this.closeModal} />,
101+
<SLDSButton key='saveBtn' label='Save' variant='brand' onClick={this.handleSubmitModal} />
102102
]}
103103
onRequestClose={this.closeModal}>
104104
{this.getModalContent()}

demo/pages/HomePage/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ module.exports = React.createClass( {
5959
</div>
6060
<main className='stage-main slds-grid slds-wrap slds-grow' role='main'>
6161
<div className='region region--main slds-grow slds-size--1-of-1 slds-medium-size--1-of-2 slds-large-size--8-of-12 slds-col-rule--right slds-p-around--large'>
62+
<LookupBaseSection />
6263

6364
<ButtonSection />
6465

6566
<PicklistBaseSection />
6667

6768
<ModalSection />
6869

69-
<LookupBaseSection />
7070

7171
<DatePickerSingleSelectSection />
7272

tests/SLDSButton/button.test.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ describe('SLDSButton: ', function(){
3434
let brand = TestUtils.findRenderedDOMComponentWithClass(button, 'slds-button--brand');
3535
expect(brand).to.not.equal(undefined);
3636
});
37-
38-
})
39-
37+
});
4038

4139
describe('component icon props render', function() {
4240
it('renders icon svg', function() {

0 commit comments

Comments
 (0)