Skip to content

Commit 18bae9a

Browse files
committed
Merge pull request #45 from salesforce-ux/gpinto_lookup_modifications
Gpinto lookup modifications
2 parents 1e6e571 + 38f6a71 commit 18bae9a

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

components/SLDSLookup/Menu/Item/index.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1010
import React, { Component } from 'react';
1111
import {Icon} from "../../../SLDSIcons";
1212
import {EventUtil} from '../../../utils';
13+
import escapeRegExp from 'lodash.escaperegexp';
1314

1415
class Item extends React.Component {
1516
constructor(props) {
1617
super(props);
1718
}
1819

1920
componentWillReceiveProps(nextProps){
20-
if(nextProps.isActive !== this.props.isActive && nextProps.isActive === true){
21+
if (nextProps.isActive !== this.props.isActive && nextProps.isActive === true) {
2122
this.scrollFocus();
2223
this.props.setFocus(this.props.id);
2324
}
2425
}
2526

2627
boldSearchText(children) {
27-
const term = this.props.searchTerm;
28-
if(!children || !term) return children;
29-
const regex = new RegExp('(' + term + ')', 'gi');
28+
let regex = this.props.boldRegex
29+
if (!regex) {
30+
const term = this.props.searchTerm;
31+
if(!children || !term) return children;
32+
regex = new RegExp('(' + escapeRegExp(term) + ')', 'gi');
33+
}
3034
return React.Children.map(children, c => {
3135
return (typeof c === 'string') ? <span dangerouslySetInnerHTML={{ __html: c.replace(regex, '<mark>$1</mark>')}}></span> : c;
3236
});
@@ -83,7 +87,8 @@ Item.propTypes = {
8387
setFocus: React.PropTypes.func,
8488
handleItemFocus: React.PropTypes.func,
8589
onSelect: React.PropTypes.func,
86-
data: React.PropTypes.object
90+
data: React.PropTypes.object,
91+
boldRegex: React.PropTypes.instanceOf(RegExp)
8792
};
8893

8994
Item.defaultProps = {

components/SLDSLookup/Menu/index.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,22 @@ class Menu extends React.Component {
7171
const id = c.id;
7272
let isActive = false;
7373
if(this.props.header){
74-
isActive = this.props.focusIndex === i + 1? true : false;
74+
isActive = this.props.focusIndex === i + 1 ? true : false;
7575
}else{
7676
isActive = this.props.focusIndex === i ? true : false;
7777
}
7878
return <Item
79-
key={id}
80-
id={id}
81-
type={this.props.type}
82-
searchTerm={this.props.searchTerm}
83-
index={i}
84-
isActive={isActive}
85-
setFocus={this.props.setFocus}
86-
handleItemFocus={this.handleItemFocus.bind(this)}
87-
onSelect={this.props.onSelect}
88-
data={c.data}
79+
key={id}
80+
id={id}
81+
type={this.props.type}
82+
searchTerm={this.props.searchTerm}
83+
index={i}
84+
isActive={isActive}
85+
setFocus={this.props.setFocus}
86+
handleItemFocus={this.handleItemFocus.bind(this)}
87+
onSelect={this.props.onSelect}
88+
data={c.data}
89+
boldRegex={this.props.boldRegex}
8990
>
9091
{c}
9192
</Item>
@@ -132,6 +133,7 @@ Menu.propTypes = {
132133
filterWith: React.PropTypes.func,
133134
getListLength: React.PropTypes.func,
134135
setFocus: React.PropTypes.func,
136+
boldRegex: React.PropTypes.instanceOf(RegExp),
135137
};
136138

137139
Menu.defaultProps = {

components/SLDSLookup/index.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class SLDSLookup extends React.Component {
4141
errors:[],
4242
messages:[],
4343
};
44-
45-
4644
}
4745

4846
componentDidMount(){
@@ -99,6 +97,7 @@ class SLDSLookup extends React.Component {
9997
selectedIndex: null,
10098
isOpen: true,
10199
});
100+
if(this.props.onItemUnselect) this.props.onItemUnselect();
102101
}
103102

104103
//=================================================
@@ -236,6 +235,7 @@ class SLDSLookup extends React.Component {
236235
onSelect={this.selectItem.bind(this)}
237236
header={this.getHeader()}
238237
footer={this.getFooter()}
238+
boldRegex={this.props.boldRegex}
239239
/>;
240240
}
241241
}
@@ -259,7 +259,7 @@ class SLDSLookup extends React.Component {
259259
{this.renderMenuContent()}
260260
</SLDSPopover>;
261261
}
262-
};
262+
}
263263

264264
renderSelectedItem(){
265265
let selectedItem = this.props.items[this.state.selectedIndex].label;
@@ -357,9 +357,11 @@ SLDSLookup.propTypes = {
357357
type: React.PropTypes.string,
358358
filterWith: React.PropTypes.func,
359359
onItemSelect: React.PropTypes.func,
360+
onItemUnselect: React.PropTypes.func,
360361
onChange: React.PropTypes.func,
361362
modal: React.PropTypes.bool,
362363
disabled: React.PropTypes.bool,
364+
boldRegex: React.PropTypes.instanceOf(RegExp),
363365
};
364366

365367
SLDSLookup.defaultProps = {

0 commit comments

Comments
 (0)