From a2cec68fcd146ad9959366d9a31e268afadc7d6d Mon Sep 17 00:00:00 2001 From: Donielle Berg Date: Tue, 27 Oct 2015 10:33:27 -0700 Subject: [PATCH 1/3] Make DefaultHeader and DefaultFooter components --- .../SLDSLookup/Menu/ActionItem/index.jsx | 53 ------------------- .../SLDSLookup/Menu/DefaultFooter/index.jsx | 41 ++++++++++++++ .../SLDSLookup/Menu/DefaultHeader/index.jsx | 41 ++++++++++++++ demo/pages/HomePage/LookupBaseSection.jsx | 7 +-- 4 files changed, 86 insertions(+), 56 deletions(-) delete mode 100644 components/SLDSLookup/Menu/ActionItem/index.jsx create mode 100644 components/SLDSLookup/Menu/DefaultFooter/index.jsx create mode 100644 components/SLDSLookup/Menu/DefaultHeader/index.jsx 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..47d043a998 --- /dev/null +++ b/components/SLDSLookup/Menu/DefaultFooter/index.jsx @@ -0,0 +1,41 @@ +/* + 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); + } + + 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..fb37de2135 --- /dev/null +++ b/components/SLDSLookup/Menu/DefaultHeader/index.jsx @@ -0,0 +1,41 @@ +/* + 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); + } + + 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..1b2b427a2e 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'}, @@ -55,7 +56,7 @@ module.exports = React.createClass( { getHeader(){ return (
- +
) }, @@ -63,7 +64,7 @@ module.exports = React.createClass( { getFooter(){ return (
- +
) }, From d834a3a90c48a568765b0e4ed8d9b090fe7d0947 Mon Sep 17 00:00:00 2001 From: Donielle Berg Date: Tue, 27 Oct 2015 11:02:47 -0700 Subject: [PATCH 2/3] A bit of cleanup in DefaultHeader and DefaultFooter --- .../SLDSLookup/Menu/DefaultFooter/index.jsx | 14 ++++++++++---- .../SLDSLookup/Menu/DefaultHeader/index.jsx | 14 ++++++++++---- demo/pages/HomePage/LookupBaseSection.jsx | 19 ++----------------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/components/SLDSLookup/Menu/DefaultFooter/index.jsx b/components/SLDSLookup/Menu/DefaultFooter/index.jsx index 47d043a998..d9fc42ac9a 100644 --- a/components/SLDSLookup/Menu/DefaultFooter/index.jsx +++ b/components/SLDSLookup/Menu/DefaultFooter/index.jsx @@ -19,15 +19,21 @@ class DefaultFooter extends React.Component { 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 ( - +
+ +
) } } diff --git a/components/SLDSLookup/Menu/DefaultHeader/index.jsx b/components/SLDSLookup/Menu/DefaultHeader/index.jsx index fb37de2135..5155a7ac14 100644 --- a/components/SLDSLookup/Menu/DefaultHeader/index.jsx +++ b/components/SLDSLookup/Menu/DefaultHeader/index.jsx @@ -19,15 +19,21 @@ class DefaultHeader extends React.Component { 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 ( - +
+ +
) } } diff --git a/demo/pages/HomePage/LookupBaseSection.jsx b/demo/pages/HomePage/LookupBaseSection.jsx index 1b2b427a2e..84930f0603 100644 --- a/demo/pages/HomePage/LookupBaseSection.jsx +++ b/demo/pages/HomePage/LookupBaseSection.jsx @@ -45,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() { From 02420cbd164f1fba44fe29b9bee628918460f848 Mon Sep 17 00:00:00 2001 From: Donielle Berg Date: Tue, 27 Oct 2015 14:11:39 -0700 Subject: [PATCH 3/3] Add more lookup tests --- tests/SLDSLookup/lookup.test.jsx | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) 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'); }); - }); });