File tree Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -51,22 +51,16 @@ function pressUpKey (e) {
5151 e . preventDefault ( )
5252
5353 // if first item, cycle to the bottom
54- if ( this . state . index <= 0 ) {
55- this . setState ( { index : this . state . options . length - 1 } )
56- } else {
57- this . setState ( { index : this . state . index - 1 } )
58- }
54+ const size = this . state . options . length - 1
55+ this . setState ( { index : this . state . index <= 0 ? size : this . state . index - 1 } )
5956}
6057
6158function pressDownKey ( e ) {
6259 e . preventDefault ( )
6360
6461 // if last item, cycle to top
65- if ( this . state . index >= this . state . options . length - 1 ) {
66- this . setState ( { index : 0 } )
67- } else {
68- this . setState ( { index : this . state . index + 1 } )
69- }
62+ const size = this . state . options . length - 1
63+ this . setState ( { index : this . state . index >= size ? 0 : this . state . index + 1 } )
7064}
7165
7266function pressBackspaceKey ( ) {
You can’t perform that action at this time.
0 commit comments