Skip to content

Commit c157423

Browse files
committed
Fix focus on delete bug in lookup
1 parent f1bfc12 commit c157423

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

components/SLDSLookup/Menu/index.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
*/
99

1010
import React, { Component } from 'react';
11-
import {Icon} from "../../SLDSIcons";
12-
import {KEYS} from '../../utils';
1311
import Item from './Item';
12+
import {Icon} from "../../SLDSIcons";
1413

1514
class Menu extends React.Component {
1615
constructor(props){
1716
super(props);
18-
this.state = {};
17+
this.state = {isEmpty: false};
1918
}
2019

2120
componentDidUpdate(){
@@ -49,6 +48,26 @@ class Menu extends React.Component {
4948
});
5049
}
5150

51+
renderEmptyState(){
52+
let className = 'slds-lookup__item';
53+
return (
54+
<li
55+
className={className}
56+
role="presentaion">
57+
<a
58+
href='#'
59+
id='add-item'
60+
tabIndex="-1"
61+
role="option"
62+
onClick={this.props.addItem}
63+
onMouseDown={this.props.addItem}>
64+
<Icon name="add" category="utility" size="x-small" className="slds-icon-text-default" />
65+
New {this.props.type}
66+
</a>
67+
</li>
68+
);
69+
}
70+
5271
render(){
5372
return (
5473
<div
@@ -59,6 +78,7 @@ class Menu extends React.Component {
5978
role="presentation"
6079
ref="list">
6180
{this.renderItems()}
81+
{this.renderEmptyState()}
6282
</ul>
6383
</div>
6484
)

components/SLDSLookup/index.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
99

1010
import React, { Component } from 'react';
1111
import Menu from './Menu';
12-
import {InputIcon, ButtonIcon} from "./../SLDSIcons";
13-
import {Icon} from "../SLDSIcons";
12+
import {Icon, InputIcon, ButtonIcon} from "./../SLDSIcons";
1413
import {KEYS,EventUtil} from '../utils';
1514
import escapeRegExp from 'lodash.escaperegexp';
1615

@@ -36,8 +35,10 @@ class SLDSLookup extends React.Component {
3635
};
3736
}
3837

39-
componentDidUpdate(){
40-
React.findDOMNode(this.refs.lookup).focus();
38+
componentDidUpdate(prevProps, prevState){
39+
if(prevState.selectedIndex && !this.state.selectIndex){
40+
if(this.refs.lookup) React.findDOMNode(this.refs.lookup).focus();
41+
}
4142
}
4243

4344
//=================================================
@@ -76,6 +77,7 @@ class SLDSLookup extends React.Component {
7677
handleDeleteSelected() {
7778
this.setState({
7879
selectedIndex: null,
80+
isOpen: true,
7981
});
8082
}
8183

@@ -147,7 +149,10 @@ class SLDSLookup extends React.Component {
147149
setFocus={this.setFocus.bind(this)}
148150
getListLength={this.getListLength.bind(this)}
149151
listLength={this.state.listLength}
150-
focusIndex={this.state.focusIndex}/>;
152+
focusIndex={this.state.focusIndex}
153+
addItem={this.props.addItem}
154+
type={this.props.type}
155+
/>;
151156
}else{
152157
return null;
153158
}

demo/pages/HomePage/LookupBaseSection.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ module.exports = React.createClass( {
3636
return {};
3737
},
3838

39+
addItem(){
40+
alert('Add item clicked');
41+
},
42+
3943

4044
render() {
4145
return (
@@ -53,7 +57,7 @@ module.exports = React.createClass( {
5357
</PrismCode>
5458

5559
<div className="slds-p-vertical--large">
56-
<SLDSLookup items={items} label="Contacts" />
60+
<SLDSLookup items={items} label="Accounts" type="account" addItem={this.addItem} />
5761
</div>
5862

5963
</div>

0 commit comments

Comments
 (0)