From d4b457a83c27d944c4329411bf4c778f3db0d2c8 Mon Sep 17 00:00:00 2001 From: Donielle Berg Date: Thu, 22 Oct 2015 13:35:51 -0700 Subject: [PATCH] Add onChange to lookup --- components/SLDSLookup/Menu/Item/index.jsx | 1 - components/SLDSLookup/index.jsx | 14 +++++++------- demo/code-snippets/SLDSLookupPage.txt | 10 +++++++++- demo/pages/HomePage/LookupBaseDynamicSection.jsx | 12 +++++++++++- demo/pages/HomePage/LookupBaseSection.jsx | 12 +++++++++++- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/components/SLDSLookup/Menu/Item/index.jsx b/components/SLDSLookup/Menu/Item/index.jsx index e8e1004342..9e7e84f5e9 100644 --- a/components/SLDSLookup/Menu/Item/index.jsx +++ b/components/SLDSLookup/Menu/Item/index.jsx @@ -34,7 +34,6 @@ class Item extends React.Component { handleClick(e){ EventUtil.trapImmediate(e); - console.log('>>> this.props.id: ',this.props.id); return this.props.onSelect(this.props.id); } diff --git a/components/SLDSLookup/index.jsx b/components/SLDSLookup/index.jsx index d727d50cb2..535b63079f 100644 --- a/components/SLDSLookup/index.jsx +++ b/components/SLDSLookup/index.jsx @@ -25,7 +25,8 @@ class SLDSLookup extends React.Component { super(props); //Dynamically assign ids to list items to reference for focusing and selecting items -// this.props.items.map((item, index) => { return item.id = 'item-' + index; }) + //this.props.items.map((item, index) => { return item.id = 'item-' + index; }) + this.state = { searchTerm: '', @@ -77,7 +78,7 @@ class SLDSLookup extends React.Component { selectedIndex: index, searchTerm: null }); - if(this.props.onItemSelect) this.props.onItemSelect(); + if(this.props.onItemSelect) this.props.onItemSelect(itemId); } handleDeleteSelected() { @@ -130,6 +131,7 @@ class SLDSLookup extends React.Component { handleChange(event) { const target = event.target || event.currentTarget; this.setState({searchTerm: target.value}); + if(this.props.onChange) this.props.onChange(target.value); } handleKeyDown(event) { @@ -227,7 +229,7 @@ class SLDSLookup extends React.Component { + + diff --git a/demo/pages/HomePage/LookupBaseDynamicSection.jsx b/demo/pages/HomePage/LookupBaseDynamicSection.jsx index 04bbaa16a2..23e8a7d125 100644 --- a/demo/pages/HomePage/LookupBaseDynamicSection.jsx +++ b/demo/pages/HomePage/LookupBaseDynamicSection.jsx @@ -45,16 +45,26 @@ module.exports = React.createClass( { alert('Search Records Clicked'); }, + onChange(newValue){ + console.log('New search term: ', newValue); + }, + + selectItem(item){ + console.log(item + ' Selected'); + }, + render() { return (
Dynamic list
- diff --git a/demo/pages/HomePage/LookupBaseSection.jsx b/demo/pages/HomePage/LookupBaseSection.jsx index d208025dd7..1947c44ece 100644 --- a/demo/pages/HomePage/LookupBaseSection.jsx +++ b/demo/pages/HomePage/LookupBaseSection.jsx @@ -44,6 +44,14 @@ module.exports = React.createClass( { alert('Search Records Clicked'); }, + onChange(newValue){ + console.log('New search term: ', newValue); + }, + + selectItem(item){ + console.log(item + ' Selected'); + }, + render() { return ( @@ -60,10 +68,12 @@ module.exports = React.createClass( {
-