@@ -7,7 +7,7 @@ import Spinner from './Spinner';
77import Pill from './Pill' ;
88import DropdownButton from './DropdownButton' ;
99import { DropdownMenuItem } from './DropdownMenu' ;
10- import { uuid , registerStyle } from './util' ;
10+ import { uuid , isElInChildren , registerStyle } from './util' ;
1111
1212export class LookupSelection extends Component {
1313 onKeyDown ( e ) {
@@ -143,10 +143,14 @@ export class LookupSearch extends Component {
143143 this . props . onChange ( searchText ) ;
144144 }
145145
146- onInputBlur ( e ) {
147- if ( this . props . onBlur ) {
148- this . props . onBlur ( e ) ;
149- }
146+ onInputBlur = ( e ) => {
147+ setTimeout ( ( ) => {
148+ if ( ! this . isFocusedInComponent ( ) ) {
149+ if ( this . props . onBlur ) {
150+ this . props . onBlur ( e ) ;
151+ }
152+ }
153+ } , 10 ) ;
150154 }
151155
152156 onScopeMenuClick ( e ) {
@@ -161,8 +165,18 @@ export class LookupSearch extends Component {
161165 }
162166 }
163167
168+ isFocusedInComponent ( ) {
169+ return isElInChildren ( this . node , document . activeElement ) ;
170+ }
171+
172+ handleLookupSearchRef = ( node ) => {
173+ this . node = node ;
174+ const { lookupSearchRef } = this . props ;
175+ if ( lookupSearchRef ) { lookupSearchRef ( node ) ; }
176+ }
177+
164178 renderSearchInput ( props ) {
165- const { className, hidden, searchText, iconAlign = 'right' , lookupSearchRef } = props ;
179+ const { className, hidden, searchText, iconAlign = 'right' } = props ;
166180 const searchInputClassNames = classnames (
167181 'slds-grid' ,
168182 'slds-input-has-icon' ,
@@ -186,7 +200,7 @@ export class LookupSearch extends Component {
186200 delete pprops . onValueChange ;
187201 delete pprops . lookupSearchRef ;
188202 return (
189- < div ref = { lookupSearchRef } className = { searchInputClassNames } >
203+ < div ref = { this . handleLookupSearchRef } className = { searchInputClassNames } >
190204 < Input
191205 { ...pprops }
192206 inputRef = { node => ( this . input = node ) }
@@ -195,12 +209,16 @@ export class LookupSearch extends Component {
195209 onChange = { this . onInputChange . bind ( this ) }
196210 onBlur = { this . onInputBlur . bind ( this ) }
197211 />
198- < Icon
199- icon = 'search'
200- className = 'slds-input__icon'
212+ < span
213+ tabIndex = { - 1 }
201214 style = { { cursor : 'pointer' } }
202- onClick = { this . onLookupIconClick . bind ( this ) }
203- />
215+ onClick = { this . onLookupIconClick }
216+ >
217+ < Icon
218+ icon = 'search'
219+ className = 'slds-input__icon'
220+ />
221+ </ span >
204222 </ div >
205223 ) ;
206224 }
@@ -235,7 +253,7 @@ export class LookupSearch extends Component {
235253 }
236254
237255 render ( ) {
238- const { scopes, hidden, targetScope, lookupSearchRef , ...props } = this . props ;
256+ const { scopes, hidden, targetScope, ...props } = this . props ;
239257 if ( scopes ) {
240258 const lookupSearchClassNames = classnames (
241259 'slds-grid' ,
@@ -245,7 +263,7 @@ export class LookupSearch extends Component {
245263 ) ;
246264 const styles = { WebkitFlexWrap : 'nowrap' , msFlexWrap : 'nowrap' , flexWrap : 'nowrap' } ;
247265 return (
248- < div ref = { lookupSearchRef } className = { lookupSearchClassNames } style = { styles } >
266+ < div ref = { this . handleLookupSearchRef } className = { lookupSearchClassNames } style = { styles } >
249267 { this . renderScopeSelector ( scopes , targetScope ) }
250268 { this . renderSearchInput ( { ...props , className : 'slds-col' , bare : true } ) }
251269 </ div >
0 commit comments