Skip to content

Commit 31183d3

Browse files
committed
Add styling for single select lookup based on SLDS
1 parent a2e8dbb commit 31183d3

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

components/SLDSLookup/Menu/Item/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Item extends React.Component {
2121
if(!children || !term) return children;
2222
const regex = new RegExp('(' + term + ')', 'gi');
2323
return React.Children.map(children, c => {
24-
return (typeof c === 'string') ? <span dangerouslySetInnerHTML={{ __html: c.replace(regex, '<mark>$1</mark>')}}></span> : c;
24+
return (typeof c.label === 'string') ? <span dangerouslySetInnerHTML={{ __html: c.replace(regex, '<mark>$1</mark>')}}></span> : c;
2525
});
2626
}
2727

@@ -53,7 +53,8 @@ class Item extends React.Component {
5353
tabIndex="-1"
5454
aria-disabled={this.props.disabled}
5555
role="option"
56-
onClick={this.handleClick.bind(this)}>
56+
onClick={this.handleClick.bind(this)}
57+
onMouseDown={this.handleClick.bind(this)}>
5758
<Icon name="account" />
5859
{ this.boldSearchText(this.props.children) }
5960
</a>

components/SLDSLookup/index.jsx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,25 @@ class SLDSLookup extends React.Component {
4545
}
4646

4747
getActiveDescendant(){
48-
console.log("aria-activedescendant is ", 'item-' + this.state.activeIndex);
4948
return this.state.activeIndex !== null ? 'item-' + this.state.activeIndex: "";
5049
}
5150

5251
//=================================================
5352
// Select menu item (onClick or on key enter/space)
5453
selectItem(index){
54+
//console.log('selectItem fired');
5555
this.setState({
5656
selectedIndex: index,
5757
searchTerm: null
5858
});
59-
console.log("Selected Item is ", this.props.items[index]);
6059
}
6160

61+
handleDeleteSelected() {
62+
this.setState({
63+
selectedIndex: null,
64+
isOpen: false
65+
});
66+
}
6267

6368
//=================================================
6469
// Basic Event Listeners on Input
@@ -126,18 +131,38 @@ class SLDSLookup extends React.Component {
126131
}
127132
}
128133

134+
renderSelectedItem(){
135+
return (
136+
<div className="slds-pill">
137+
<a href="#" className="slds-pill__label">
138+
<span>
139+
<Icon name="account" />
140+
{this.props.items[this.state.selectedIndex].label}
141+
</span>
142+
</a>
143+
<button className="slds-button slds-button--icon-bare" onClick={this.handleDeleteSelected.bind(this)} ref="clearSelectedItemButton">
144+
<ButtonIcon name="close" />
145+
<span className="slds-assistive-text">Remove</span>
146+
</button>
147+
</div>
148+
);
149+
}
150+
129151
render(){
152+
let inputClasses = this.state.selectedIndex === null ? 'slds-input':'slds-input slds-hide';
153+
let compClasses = this.state.selectedIndex === null ? "slds-lookup ignore-react-onclickoutside":"slds-lookup ignore-react-onclickoutside slds-has-selection";
154+
130155
return (
131-
<div className="slds-lookup ignore-react-onclickoutside" data-select="multi" data-scope="single" data-typeahead="true">
156+
<div className={compClasses} data-select="single" data-scope="single" data-typeahead="true">
132157
<section className="slds-form-element">
133158
<label className="slds-form-element__label" forHTML="lookup">{this.props.label}</label>
134159

135160
<div className="slds-lookup__control slds-input-has-icon slds-input-has-icon--right">
136-
{ this.state.currentSelectedItem ? this.state.currentSelectedItem : null }
161+
{ this.state.selectedIndex ? this.renderSelectedItem() : null }
137162
<InputIcon name="search"/>
138163
<input
139164
id="lookup"
140-
className={'slds-input'}
165+
className={inputClasses}
141166
type="text"
142167
aria-label="lookup"
143168
aria-haspopup="true"
@@ -147,6 +172,7 @@ class SLDSLookup extends React.Component {
147172
role="combobox"
148173
onChange={this.handleChange.bind(this)}
149174
onFocus={this.handleFocus.bind(this)}
175+
onBlur={this.handleBlur.bind(this)}
150176
onClick={this.handleClick.bind(this)}
151177
onKeyDown={this.handleKeyDown.bind(this)}
152178
value={this.state.searchTerm} />

demo/pages/HomePage/LookupBaseSection.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ import SLDSLookup from '../../../components/SLDSLookup';
1515
import {default as PrismCode} from 'react-prism/lib/PrismCode';
1616

1717

18-
const items = ['Paddy\'s Pub', 'Tyrell Corp', 'Paper St. Soap Company', 'Nakatomi Investments', 'Acme Landscaping', 'Acme Construction'];
18+
const items = [
19+
{label:'Paddy\'s Pub'},
20+
{label:'Tyrell Corp'},
21+
{label:'Paper St. Soap Company'},
22+
{label:'Nakatomi Investments'},
23+
{label:'Acme Landscaping'},
24+
{label:'Acme Construction'}
25+
];
1926

2027

2128

0 commit comments

Comments
 (0)