diff --git a/components/SLDSLookup/Menu/ActionItem/index.jsx b/components/SLDSLookup/Menu/ActionItem/index.jsx deleted file mode 100644 index 3c7a825ed1..0000000000 --- a/components/SLDSLookup/Menu/ActionItem/index.jsx +++ /dev/null @@ -1,53 +0,0 @@ -/* -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 ActionItem extends React.Component { - constructor(props) { - super(props); - } - - componentWillReceiveProps(nextProps){ - if(nextProps.isActive !== this.props.isActive && nextProps.isActive === true) this.props.setFocus(this.props.id); - } - - render(){ - let content, id, icon; - if(this.props.item === 'search'){ - content = (this.props.searchTerm ? '"' + this.props.searchTerm + '"' : "") + ' in ' + this.props.type + 's'; - id = 'searchRecords'; - icon = 'search'; - } - else if(this.props.item === 'newItem'){ - content = 'New ' + this.props.type; - id = 'addNewItem'; - icon = 'add'; - } - - let className = 'slds-button'; - if(this.props.isActive) className += ' slds-theme--shade' - - return ( - - ) - } -} - -ActionItem.propTypes = { -}; - -ActionItem.defaultProps = { -}; - -module.exports = ActionItem; diff --git a/components/SLDSLookup/Menu/DefaultFooter/index.jsx b/components/SLDSLookup/Menu/DefaultFooter/index.jsx new file mode 100644 index 0000000000..d9fc42ac9a --- /dev/null +++ b/components/SLDSLookup/Menu/DefaultFooter/index.jsx @@ -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 ( +
+ +
+ ) + } +} + +DefaultFooter.propTypes = { +}; + +DefaultFooter.defaultProps = { +}; + +module.exports = DefaultFooter; diff --git a/components/SLDSLookup/Menu/DefaultHeader/index.jsx b/components/SLDSLookup/Menu/DefaultHeader/index.jsx new file mode 100644 index 0000000000..5155a7ac14 --- /dev/null +++ b/components/SLDSLookup/Menu/DefaultHeader/index.jsx @@ -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 ( +
+ +
+ ) + } +} + +DefaultHeader.propTypes = { +}; + +DefaultHeader.defaultProps = { +}; + +module.exports = DefaultHeader; diff --git a/demo/pages/HomePage/LookupBaseSection.jsx b/demo/pages/HomePage/LookupBaseSection.jsx index 88a9cb7c10..84930f0603 100644 --- a/demo/pages/HomePage/LookupBaseSection.jsx +++ b/demo/pages/HomePage/LookupBaseSection.jsx @@ -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'}, @@ -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 ( -
- -
- ) + return ; }, getFooter(){ - return ( -
- -
- ) + return ; }, render() { diff --git a/tests/SLDSLookup/lookup.test.jsx b/tests/SLDSLookup/lookup.test.jsx index 8bf152c8db..b8b03bcb1d 100644 --- a/tests/SLDSLookup/lookup.test.jsx +++ b/tests/SLDSLookup/lookup.test.jsx @@ -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(){ @@ -89,17 +88,44 @@ describe('SLDSLookup: ', function(){ }); it('selects correct item', function() { + let lookup = generateLookup(); + 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(); + 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(); + 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(); + 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'); }); - }); });