Skip to content
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
53 changes: 0 additions & 53 deletions components/SLDSLookup/Menu/ActionItem/index.jsx

This file was deleted.

47 changes: 47 additions & 0 deletions components/SLDSLookup/Menu/DefaultFooter/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import React, { Component } from 'react';
import {Icon} from "../../../SLDSIcons";

class DefaultFooter extends React.Component {
constructor(props) {
super(props);
}

componentWillReceiveProps(nextProps){
if(nextProps.isActive !== this.props.isActive && nextProps.isActive === true) this.props.setFocus(this.props.id);
}

footerClick(){
console.log('=====> Lookup Footer Clicked');
}

render(){
let className = 'slds-button';
if(this.props.isActive) className += ' slds-theme--shade'

return (
<div className="slds-lookup__item" onClick={this.footerClick}>
<button id='newItem' tabIndex="-1" className={className}>
<Icon name='add' category="utility" size="x-small" className="slds-icon-text-default" />
{'New ' + this.props.type}
</button>
</div>
)
}
}

DefaultFooter.propTypes = {
};

DefaultFooter.defaultProps = {
};

module.exports = DefaultFooter;
47 changes: 47 additions & 0 deletions components/SLDSLookup/Menu/DefaultHeader/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import React, { Component } from 'react';
import {Icon} from "../../../SLDSIcons";

class DefaultHeader extends React.Component {
constructor(props) {
super(props);
}

componentWillReceiveProps(nextProps){
if(nextProps.isActive !== this.props.isActive && nextProps.isActive === true) this.props.setFocus(this.props.id);
}

headerClick(){
console.log('=====> Lookup Header Clicked');
}

render(){
let className = 'slds-button';
if(this.props.isActive) className += ' slds-theme--shade'

return (
<div className="slds-lookup__item" onClick={this.headerClick}>
<button id='searchRecords' tabIndex="-1" className={className}>
<Icon name='search' category="utility" size="x-small" className="slds-icon-text-default" />
{this.props.searchTerm ? '"' + this.props.searchTerm + '"' + ' in ' + this.props.type + 's': ' in ' + this.props.type + 's'}
</button>
</div>
)
}
}

DefaultHeader.propTypes = {
};

DefaultHeader.defaultProps = {
};

module.exports = DefaultHeader;
22 changes: 4 additions & 18 deletions demo/pages/HomePage/LookupBaseSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
import React from 'react';
import SLDSLookup from '../../../components/SLDSLookup';
import {default as PrismCode} from 'react-prism/lib/PrismCode';
import ActionItem from '../../../components/SLDSLookup/Menu/ActionItem';
import DefaultHeader from '../../../components/SLDSLookup/Menu/DefaultHeader';
import DefaultFooter from '../../../components/SLDSLookup/Menu/DefaultFooter';

const items = [
{label:'Paddy\'s Pub'},
Expand Down Expand Up @@ -44,28 +45,13 @@ module.exports = React.createClass( {
console.log(item , ' Selected');
},

headerClick(){
console.log('=====> Lookup Header Clicked');
},

footerClick(){
console.log('=====> Lookup Footer Clicked');
},

getHeader(){
return (
<div className="slds-lookup__item" onClick={this.headerClick} onMouseDown={this.headerClick}>
<ActionItem item='search' type='account' searchTerm={this.state.searchVal} />
</div>
)
return <DefaultHeader searchTerm={this.state.searchVal} type='account' />;
},

getFooter(){
return (
<div className="slds-lookup__item" onClick={this.footerClick} onMouseDown={this.footerClick}>
<ActionItem item='newItem' type='account' />
</div>
)
return <DefaultFooter type='account' />;
},

render() {
Expand Down
34 changes: 30 additions & 4 deletions tests/SLDSLookup/lookup.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -89,17 +88,44 @@ describe('SLDSLookup: ', function(){
});

it('selects 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});
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
TestUtils.Simulate.keyDown(input, {key: "Enter", keyCode: 13, which: 13});
let selected = lookup.getElementsByTagName("span")[0].getElementsByTagName('span')[0].innerText;
expect(selected).to.equal('Paper St. Soap Company');
});

it('closes lookup menu', function() {
it('closes lookup menu on esc', 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: "Esc", keyCode: 27, which: 27});
let ariaExpanded = input.getAttribute("aria-expanded");
expect(ariaExpanded).to.equal('false');
});

it('aria-expanded is false after selecting 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: "Enter", keyCode: 13, which: 13});
expect(input.className).to.have.string('slds-hide');
});

it('focuses on selected item', function() {
it('aria-expanded is false after selecting 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});
let focusedItem = lookup.getElementsByTagName("ul")[0].getElementsByTagName('li')[0];
expect(focusedItem.className).to.have.string('slds-theme--shade');
});

});

});