Skip to content

Commit 0226c17

Browse files
committed
more lookup refactoring
1 parent a4fdad1 commit 0226c17

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

components/SLDSLookup/Menu/DefaultHeader/index.jsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import React, { Component } from 'react';
1111
import {Icon} from "../../../SLDSIcons";
12+
import { EventUtil } from '../../../utils';
1213

1314
class DefaultHeader extends React.Component {
1415
constructor(props) {
@@ -19,22 +20,29 @@ class DefaultHeader extends React.Component {
1920
if(nextProps.isActive !== this.props.isActive && nextProps.isActive === true) this.props.setFocus(this.props.id);
2021
}
2122

22-
headerClick(){
23+
handleClick(){
2324
console.log('=====> Lookup Header Clicked');
25+
if(this.props.onClose){
26+
this.props.onClose();
27+
}
28+
}
29+
30+
handleMouseDown(event) {
31+
EventUtil.trapImmediate(event);
2432
}
2533

2634
render(){
2735
let className = 'slds-button';
28-
if(this.props.isActive) className += ' slds-theme--shade'
29-
30-
return (
31-
<div className="slds-lookup__item" onClick={this.headerClick}>
32-
<button id='searchRecords' tabIndex="-1" className={className}>
33-
<Icon name='search' category="utility" size="x-small" className="slds-icon-text-default" />
34-
{this.props.searchTerm ? '"' + this.props.searchTerm + '"' + ' in ' + this.props.type + 's': ' in ' + this.props.type + 's'}
35-
</button>
36-
</div>
37-
)
36+
if(this.props.isActive) className += ' slds-theme--shade aaa'
37+
38+
return (
39+
<div className="slds-lookup__item" onMouseDown={this.handleMouseDown} onClick={this.handleClick.bind(this)}>
40+
<button id='searchRecords' tabIndex="-1" className={className}>
41+
<Icon name='search' category="utility" size="x-small" className="slds-icon-text-default" />
42+
{this.props.searchTerm ? '"' + this.props.searchTerm + '"' + ' in ' + this.props.type + 's': ' in ' + this.props.type + 's'}
43+
</button>
44+
</div>
45+
)
3846
}
3947
}
4048

components/SLDSLookup/Menu/index.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,7 @@ class Menu extends React.Component {
3535
}
3636

3737
renderHeader(){
38-
if(this.props.header){
39-
let headerActive = false;
40-
let isActiveClass = null;
41-
if(this.props.focusIndex === 0){
42-
headerActive = true;
43-
isActiveClass = 'slds-theme--shade';
44-
}else{
45-
headerActive = false;
46-
isActiveClass = '';
47-
}
48-
49-
return <div className={isActiveClass}>{this.props.header}</div>;
50-
}
38+
return this.props.header;
5139
}
5240

5341
renderFooter(){

components/SLDSLookup/index.jsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ class SLDSLookup extends React.Component {
155155
EventUtil.trapImmediate(event);
156156
//If the focus is on the first fixed Action Item in Menu, click it
157157
if(this.props.header && this.state.focusIndex === 0){
158-
document.getElementById('menuContainer').firstChild.children[0].click();
158+
// document.getElementById('menuContainer').firstChild.children[0].click();
159+
if(this.refs.header){
160+
React.findDOMNode(this.refs.header).click();
161+
}
159162
}
160163
//If the focus is on the last fixed Action Item in Menu, click it
161164
else if(this.props.footer && this.state.focusIndex === (this.state.listLength + 1)){
@@ -178,6 +181,29 @@ class SLDSLookup extends React.Component {
178181
}
179182
}
180183

184+
getHeader(){
185+
if(this.props.header){
186+
let headerActive = false;
187+
let isActiveClass = null;
188+
if(this.state.focusIndex === 0){
189+
headerActive = true;
190+
isActiveClass = 'slds-theme--shade';
191+
}else{
192+
headerActive = false;
193+
isActiveClass = '';
194+
}
195+
const Header = this.props.header;
196+
return <div className={isActiveClass}>
197+
<Header ref='header' {... this.props}
198+
searchTerm={this.state.searchTerm}
199+
focusIndex={this.state.focusIndex}
200+
listLength={this.state.listLength}
201+
onClose={this.handleClose.bind(this)}
202+
/>
203+
</div>;
204+
}
205+
}
206+
181207
//=================================================
182208
// Rendering Things
183209
renderMenuContent(){
@@ -193,7 +219,8 @@ class SLDSLookup extends React.Component {
193219
getListLength={this.getListLength.bind(this)}
194220
setFocus={this.setFocus.bind(this)}
195221
onSelect={this.selectItem.bind(this)}
196-
header={this.props.header}
222+
header={this.getHeader()}
223+
headerProps={this.props.headerProps}
197224
footer={this.props.footer}
198225
/>;
199226
}

demo/pages/HomePage/LookupBaseSection.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = React.createClass( {
4747

4848

4949
getHeader(){
50-
return <SLDSLookup.DefaultHeader searchTerm={this.state.searchVal} type='account' />;
50+
return SLDSLookup.DefaultHeader;
5151
},
5252

5353
getFooter(){

0 commit comments

Comments
 (0)