Skip to content

Commit 78aee4c

Browse files
committed
Merge pull request #39 from salesforce-ux/lookups-refacotr
Lookups refacotr
2 parents acef58b + 1e661fe commit 78aee4c

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

components/SLDSLookup/Menu/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ Menu.propTypes = {
118118
filterWith: React.PropTypes.func,
119119
getListLength: React.PropTypes.func,
120120
setFocus: React.PropTypes.func,
121-
header: React.PropTypes.element,
122-
footer: React.PropTypes.element,
123121
};
124122

125123
Menu.defaultProps = {

components/SLDSLookup/index.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ class SLDSLookup extends React.Component {
4444
}
4545

4646
componentDidUpdate(prevProps, prevState){
47+
let lookup = this.props.type + 'Lookup';
4748
if(prevState.selectedIndex && !this.state.selectIndex){
48-
if(this.refs.lookup) React.findDOMNode(this.refs.lookup).focus();
49+
if(this.refs[lookup]) React.findDOMNode(this.refs[lookup]).focus();
4950
}
5051
else if(!prevState.selectedIndex && this.state.selectedIndex){
5152
let selectedItem = 'pill-' + this.state.selectedIndex;
@@ -202,10 +203,11 @@ class SLDSLookup extends React.Component {
202203
}
203204

204205
renderModalMenu () {
206+
let targetElem = this.props.type + 'Lookup';
205207
if(this.state.isOpen){
206208
return <SLDSPopover
207209
className='slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu'
208-
targetElement={this.refs.lookup}
210+
targetElement={this.refs[targetElem]}
209211
closeOnTabKey={true}
210212
onClose={this.handleCancel.bind(this)}>
211213
{this.renderMenuContent()}
@@ -267,7 +269,7 @@ class SLDSLookup extends React.Component {
267269
<InputIcon name="search"/>
268270
<input
269271
id={this.props.type + "Lookup"}
270-
ref="lookup"
272+
ref={this.props.type + "Lookup"}
271273
className={inputClasses}
272274
type="text"
273275
aria-haspopup="true"

demo/pages/HomePage/LookupBaseSection.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ module.exports = React.createClass( {
3232
},
3333

3434
getInitialState () {
35-
return {};
35+
return {searchVal:null};
3636
},
3737

3838
onChange(newValue){
3939
console.log('New search term: ', newValue);
40+
this.setState({searchVal: newValue});
4041
},
4142

4243
selectItem(item){
@@ -54,7 +55,7 @@ module.exports = React.createClass( {
5455
getHeader(){
5556
return (
5657
<div className="slds-lookup__item" onClick={this.headerClick} onMouseDown={this.headerClick}>
57-
<ActionItem item='search' type='account' />
58+
<ActionItem item='search' type='account' searchTerm={this.state.searchVal} />
5859
</div>
5960
)
6061
},

tests/SLDSLookup/lookup.test.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const React = require('react/addons');
22
const TestUtils = React.addons.TestUtils;
33
import {SLDSLookup} from '../../components';
4+
import ActionItem from '../../components/SLDSLookup/Menu/ActionItem';
45

56
describe('SLDSLookup: ', function(){
67

@@ -67,13 +68,23 @@ describe('SLDSLookup: ', function(){
6768

6869
describe('selecting item works', function() {
6970

70-
it('focuses correct item', function() {
71+
it('no fixed header: focuses correct item', function() {
7172
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
7273
let input = lookup.getElementsByTagName("input")[0];
7374
TestUtils.Simulate.click(input);
7475
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
7576
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
7677
let ariaActiveDescendant = lookup.getElementsByTagName("input")[0].getAttribute("aria-activedescendant");
78+
expect(ariaActiveDescendant).to.equal('item-1');
79+
});
80+
81+
it('with fixed header: focuses correct item', function() {
82+
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" header={<div>header</div>}/>);
83+
let input = lookup.getElementsByTagName("input")[0];
84+
TestUtils.Simulate.click(input);
85+
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
86+
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
87+
let ariaActiveDescendant = lookup.getElementsByTagName("input")[0].getAttribute("aria-activedescendant");
7788
expect(ariaActiveDescendant).to.equal('item-0');
7889
});
7990

0 commit comments

Comments
 (0)