@@ -154,7 +154,7 @@ var DropdownList = React.createClass({
154154 aria-owns = { listID }
155155 aria-busy = { ! ! busy }
156156 aria-live = { ! open && 'polite' }
157- //aria-activedescendant={activeID }
157+ onKeyPress = { this . _keyPress }
158158 aria-autocomplete = "list"
159159 aria-disabled = { disabled }
160160 aria-readonly = { readOnly }
@@ -234,9 +234,9 @@ var DropdownList = React.createClass({
234234 _focus ( focused , e ) {
235235
236236 this . setTimeout ( 'focus' , ( ) => {
237- if ( ! focused ) this . close ( )
237+ if ( ! focused ) this . close ( )
238238
239- if ( focused !== this . state . focused ) {
239+ if ( focused !== this . state . focused ) {
240240 notify ( this . props [ focused ? 'onFocus' : 'onBlur' ] , e )
241241 this . setState ( { focused : focused } )
242242 }
@@ -281,40 +281,34 @@ var DropdownList = React.createClass({
281281 if ( e . defaultPrevented )
282282 return
283283
284- if ( key === 'End' ) {
285- if ( isOpen ) this . setState ( { focusedItem : list . last ( ) } )
286- else change ( list . last ( ) )
284+ if ( key === 'End' ) {
285+ if ( isOpen ) this . setState ( { focusedItem : list . last ( ) } )
286+ else change ( list . last ( ) )
287287 e . preventDefault ( )
288288 }
289- else if ( key === 'Home' ) {
290- if ( isOpen ) this . setState ( { focusedItem : list . first ( ) } )
291- else change ( list . first ( ) )
289+ else if ( key === 'Home' ) {
290+ if ( isOpen ) this . setState ( { focusedItem : list . first ( ) } )
291+ else change ( list . first ( ) )
292292 e . preventDefault ( )
293293 }
294- else if ( key === 'Escape' && isOpen ) {
294+ else if ( key === 'Escape' && isOpen ) {
295295 closeWithFocus ( )
296296 }
297- else if ( ( key === 'Enter' || ( key === ' ' && ! filtering ) ) && isOpen ) {
297+ else if ( ( key === 'Enter' || ( key === ' ' && ! filtering ) ) && isOpen ) {
298298 change ( this . state . focusedItem , true )
299299 }
300- else if ( key === 'ArrowDown' ) {
301- if ( alt ) this . open ( )
302- else if ( isOpen ) this . setState ( { focusedItem : list . next ( focusedItem ) } )
303- else change ( list . next ( selectedItem ) )
300+ else if ( key === 'ArrowDown' ) {
301+ if ( alt ) this . open ( )
302+ else if ( isOpen ) this . setState ( { focusedItem : list . next ( focusedItem ) } )
303+ else change ( list . next ( selectedItem ) )
304304 e . preventDefault ( )
305305 }
306- else if ( key === 'ArrowUp' ) {
307- if ( alt ) closeWithFocus ( )
308- else if ( isOpen ) this . setState ( { focusedItem : list . prev ( focusedItem ) } )
309- else change ( list . prev ( selectedItem ) )
306+ else if ( key === 'ArrowUp' ) {
307+ if ( alt ) closeWithFocus ( )
308+ else if ( isOpen ) this . setState ( { focusedItem : list . prev ( focusedItem ) } )
309+ else change ( list . prev ( selectedItem ) )
310310 e . preventDefault ( )
311311 }
312- else if ( ! ( this . props . filter && isOpen ) )
313- this . search ( String . fromCharCode ( e . keyCode ) , item => {
314- isOpen
315- ? this . setState ( { focusedItem : item } )
316- : change ( item )
317- } )
318312
319313 function change ( item , fromList ) {
320314 if ( ! item ) return
@@ -324,6 +318,21 @@ var DropdownList = React.createClass({
324318 }
325319 } ,
326320
321+ @widgetEditable
322+ _keyPress ( e ) {
323+ notify ( this . props . onKeyPress , [ e ] )
324+
325+ if ( e . defaultPrevented )
326+ return
327+
328+ if ( ! ( this . props . filter && this . props . open ) )
329+ this . search ( String . fromCharCode ( e . which ) , item => {
330+ this . isMounted ( ) && this . props . open
331+ ? this . setState ( { focusedItem : item } )
332+ : item && this . change ( item )
333+ } )
334+ } ,
335+
327336 change ( data ) {
328337 if ( ! _ . isShallowEqual ( data , this . props . value ) ) {
329338 notify ( this . props . onChange , data )
@@ -335,7 +344,7 @@ var DropdownList = React.createClass({
335344 focus ( target ) {
336345 var inst = target || ( this . props . filter && this . props . open ? this . refs . filter : this . refs . input ) ;
337346
338- if ( activeElement ( ) !== compat . findDOMNode ( inst ) )
347+ if ( activeElement ( ) !== compat . findDOMNode ( inst ) )
339348 compat . findDOMNode ( inst ) . focus ( )
340349 } ,
341350
@@ -346,6 +355,9 @@ var DropdownList = React.createClass({
346355 search ( character , cb ) {
347356 var word = ( ( this . _searchTerm || '' ) + character ) . toLowerCase ( ) ;
348357
358+ if ( ! character )
359+ return
360+
349361 this . _searchTerm = word
350362
351363 this . setTimeout ( 'search' , ( ) => {
@@ -354,7 +366,7 @@ var DropdownList = React.createClass({
354366 , item = list . next ( this . state [ key ] , word ) ;
355367
356368 this . _searchTerm = ''
357- if ( item ) cb ( item )
369+ if ( item ) cb ( item )
358370
359371 } , this . props . delay )
360372 } ,
0 commit comments