Skip to content

Lookups refacotr #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions components/SLDSLookup/Menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ Menu.propTypes = {
filterWith: React.PropTypes.func,
getListLength: React.PropTypes.func,
setFocus: React.PropTypes.func,
header: React.PropTypes.element,
footer: React.PropTypes.element,
};

Menu.defaultProps = {
Expand Down
8 changes: 5 additions & 3 deletions components/SLDSLookup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class SLDSLookup extends React.Component {
}

componentDidUpdate(prevProps, prevState){
let lookup = this.props.type + 'Lookup';
if(prevState.selectedIndex && !this.state.selectIndex){
if(this.refs.lookup) React.findDOMNode(this.refs.lookup).focus();
if(this.refs[lookup]) React.findDOMNode(this.refs[lookup]).focus();
}
else if(!prevState.selectedIndex && this.state.selectedIndex){
let selectedItem = 'pill-' + this.state.selectedIndex;
Expand Down Expand Up @@ -202,10 +203,11 @@ class SLDSLookup extends React.Component {
}

renderModalMenu () {
let targetElem = this.props.type + 'Lookup';
if(this.state.isOpen){
return <SLDSPopover
className='slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu'
targetElement={this.refs.lookup}
targetElement={this.refs[targetElem]}
closeOnTabKey={true}
onClose={this.handleCancel.bind(this)}>
{this.renderMenuContent()}
Expand Down Expand Up @@ -267,7 +269,7 @@ class SLDSLookup extends React.Component {
<InputIcon name="search"/>
<input
id={this.props.type + "Lookup"}
ref="lookup"
ref={this.props.type + "Lookup"}
className={inputClasses}
type="text"
aria-haspopup="true"
Expand Down
5 changes: 3 additions & 2 deletions demo/pages/HomePage/LookupBaseSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ module.exports = React.createClass( {
},

getInitialState () {
return {};
return {searchVal:null};
},

onChange(newValue){
console.log('New search term: ', newValue);
this.setState({searchVal: newValue});
},

selectItem(item){
Expand All @@ -54,7 +55,7 @@ module.exports = React.createClass( {
getHeader(){
return (
<div className="slds-lookup__item" onClick={this.headerClick} onMouseDown={this.headerClick}>
<ActionItem item='search' type='account' />
<ActionItem item='search' type='account' searchTerm={this.state.searchVal} />
</div>
)
},
Expand Down
13 changes: 12 additions & 1 deletion tests/SLDSLookup/lookup.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const React = require('react/addons');
const TestUtils = React.addons.TestUtils;
import {SLDSLookup} from '../../components';
import ActionItem from '../../components/SLDSLookup/Menu/ActionItem';

describe('SLDSLookup: ', function(){

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

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

it('focuses correct item', function() {
it('no fixed header: focuses correct item', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let input = lookup.getElementsByTagName("input")[0];
TestUtils.Simulate.click(input);
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
let ariaActiveDescendant = lookup.getElementsByTagName("input")[0].getAttribute("aria-activedescendant");
expect(ariaActiveDescendant).to.equal('item-1');
});

it('with fixed header: focuses correct item', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" header={<div>header</div>}/>);
let input = lookup.getElementsByTagName("input")[0];
TestUtils.Simulate.click(input);
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
let ariaActiveDescendant = lookup.getElementsByTagName("input")[0].getAttribute("aria-activedescendant");
expect(ariaActiveDescendant).to.equal('item-0');
});

Expand Down