@@ -10,7 +10,7 @@ import GroupableList from './ListGroupable';
1010import validateList from './util/validateListInterface' ;
1111import createUncontrolledWidget from 'uncontrollable' ;
1212import { dataItem , dataText , valueMatcher } from './util/dataHelpers' ;
13- import { widgetEditable , widgetEnabled } from './util/interaction' ;
13+ import { widgetEditable } from './util/interaction' ;
1414import { instanceId , notify , isFirstFocusedRender } from './util/widgetHelpers' ;
1515
1616var compatCreate = ( props , msgs ) => typeof msgs . createNew === 'function'
@@ -76,6 +76,20 @@ var Multiselect = React.createClass({
7676 require ( './mixins/DataFilterMixin' ) ,
7777 require ( './mixins/PopupScrollToMixin' ) ,
7878 require ( './mixins/RtlParentContextMixin' ) ,
79+ require ( './mixins/FocusMixin' ) ( {
80+ willHandle ( focused ) {
81+ focused && this . focus ( )
82+ } ,
83+ didHandle ( focused ) {
84+ if ( ! focused ) this . close ( )
85+
86+ if ( ! focused && this . refs . tagList )
87+ this . setState ( { focusedTag : null } )
88+
89+ if ( focused && ! this . props . open )
90+ this . open ( )
91+ }
92+ } ) ,
7993 require ( './mixins/AriaDescendantMixin' ) ( 'input' , function ( key , id ) {
8094 let { ariaActiveDescendantKey : myKey } = this . props ;
8195
@@ -191,9 +205,9 @@ var Multiselect = React.createClass({
191205 ref = "element"
192206 id = { instanceId ( this ) }
193207 onKeyDown = { this . _keyDown }
194- onFocus = { this . _focus . bind ( null , true ) }
195- onBlur = { this . _focus . bind ( null , false ) }
196- onTouchEnd = { this . _focus . bind ( null , true ) }
208+ onBlur = { this . handleBlur }
209+ onFocus = { this . handleFocus }
210+ onTouchEnd = { this . handleFocus }
197211 tabIndex = { '-1' }
198212 className = { cx ( className , 'rw-widget' , 'rw-multiselect' , {
199213 'rw-state-focus' : focused ,
@@ -255,9 +269,8 @@ var Multiselect = React.createClass({
255269 onKeyDown = { this . _searchKeyDown }
256270 onKeyUp = { this . _searchgKeyUp }
257271 onChange = { this . _typing }
258- onFocus = { this . _inputFocus }
259- onClick = { this . _inputFocus }
260- onTouchEnd = { this . _inputFocus }
272+ onClick = { this . handleInputInteraction }
273+ onTouchEnd = { this . handleInputInteraction }
261274 />
262275 </ div >
263276 < Popup { ...popupProps }
@@ -309,54 +322,32 @@ var Multiselect = React.createClass({
309322 return this . state . processedData
310323 } ,
311324
312- _delete ( value ) {
313- this . _focus ( true )
325+ _delete ( value ) {
326+ this . focus ( )
314327 this . change (
315328 this . state . dataItems . filter ( d => d !== value ) )
316329 } ,
317330
318- _inputFocus ( ) {
319- this . _focus ( true )
320- ! this . props . open && this . open ( )
321- } ,
322-
323- @widgetEnabled
324- _focus ( focused , e ) {
325- if ( this . props . disabled === true )
326- return
327-
328- if ( focused ) this . refs . input . focus ( )
329-
330- this . setTimeout ( 'focus' , ( ) => {
331- if ( ! focused )
332- this . refs . tagList && this . setState ( { focusedTag : null } )
333-
334- if ( focused !== this . state . focused ) {
335- focused
336- ? this . open ( )
337- : this . close ( ) ;
338-
339- notify ( this . props [ focused ? 'onFocus' : 'onBlur' ] , e )
340- this . setState ( { focused : focused } )
341- }
342- } )
343- } ,
344-
345- _searchKeyDown ( e ) {
331+ _searchKeyDown ( e ) {
346332 if ( e . key === 'Backspace' && e . target . value && ! this . _deletingText )
347333 this . _deletingText = true
348334 } ,
349335
350- _searchgKeyUp ( e ) {
336+ _searchgKeyUp ( e ) {
351337 if ( e . key === 'Backspace' && this . _deletingText )
352338 this . _deletingText = false
353339 } ,
354340
355- _typing ( e ) {
341+ _typing ( e ) {
356342 notify ( this . props . onSearch , [ e . target . value ] )
357343 this . open ( )
358344 } ,
359345
346+ @widgetEditable
347+ handleInputInteraction ( ) {
348+ this . open ( )
349+ } ,
350+
360351 @widgetEditable
361352 _onSelect ( data ) {
362353
@@ -371,7 +362,7 @@ var Multiselect = React.createClass({
371362 this . change ( this . state . dataItems . concat ( data ) )
372363
373364 this . close ( )
374- this . _focus ( true )
365+ this . focus ( )
375366 } ,
376367
377368 @widgetEditable
@@ -384,7 +375,7 @@ var Multiselect = React.createClass({
384375 && notify ( this . props . onSearch , [ '' ] )
385376
386377 this . close ( )
387- this . _focus ( true )
378+ this . focus ( )
388379 } ,
389380
390381 @widgetEditable
@@ -461,8 +452,12 @@ var Multiselect = React.createClass({
461452 notify ( this . props . onSearch , [ '' ] )
462453 } ,
463454
464- open ( ) {
465- if ( ! ( this . props . disabled === true || this . props . readOnly === true ) )
455+ focus ( ) {
456+ this . refs . input . focus ( )
457+ } ,
458+
459+ open ( ) {
460+ if ( ! this . props . open )
466461 notify ( this . props . onToggle , true )
467462 } ,
468463
@@ -521,4 +516,4 @@ function msgs(msgs){
521516}
522517
523518export default createUncontrolledWidget ( Multiselect
524- , { open : 'onToggle' , value : 'onChange' , searchTerm : 'onSearch' } ) ;
519+ , { open : 'onToggle' , value : 'onChange' , searchTerm : 'onSearch' } , [ 'focus' ] ) ;
0 commit comments