@@ -13,6 +13,9 @@ const libnpm = require('libnpm')
1313const FOCUS_SEARCH = 'FOCUS_SEARCH'
1414const FOCUS_RESULTS = 'FOCUS_RESULTS'
1515
16+ // @todo Re-typing search after matches have been found installs whatever is highlighted
17+ // @todo Make sure non-focused matches list looks identical, pretty sure it doesn't currently
18+
1619class Search extends Component {
1720 constructor ( props ) {
1821 super ( props )
@@ -129,17 +132,26 @@ class Search extends Component {
129132 selectedPackage
130133 } = this . state
131134
132- // Handle up/down arrow press
135+ // If up/down arrows are pressed, make sure we're focused on search results
133136
134- if ( [ 'up' , 'down' ] . includes ( key . name ) && focusedOn === FOCUS_SEARCH && matches && matches . length ) {
135- this . setState ( { focusedOn : FOCUS_RESULTS } )
137+ if ( [ 'up' , 'down' ] . includes ( key . name ) ) {
138+ if ( focusedOn !== FOCUS_RESULTS && matches && matches . length ) {
139+ return this . setState ( { focusedOn : FOCUS_RESULTS } )
140+ }
136141 return
137142 }
138143
139- // Handle enter press
144+ // If enter is pressed and we're focused on search results, install
140145
141146 if ( key . name === 'enter' && focusedOn === FOCUS_RESULTS && selectedPackage ) {
142- this . install ( selectedPackage )
147+ return this . install ( selectedPackage )
148+ }
149+
150+ // If non up/down/enter keys were pressed and we're not focused on search
151+ // input, focus on search input
152+
153+ if ( focusedOn !== FOCUS_SEARCH ) {
154+ return this . setState ( { focusedOn : FOCUS_SEARCH } )
143155 }
144156 }
145157
@@ -223,7 +235,7 @@ const PackageSelector = ({ isFocused, matches, onSelect }) => {
223235 itemComponent = { PackageItem }
224236 onSelect = { ( { value } ) => onSelect ( value ) } />
225237 } else if ( items && items . length ) {
226- return items . map ( ( { value } ) => < div > < PackageItem value = { value } /> </ div > )
238+ return items . map ( ( { value } ) => < div > { ' ' } < PackageItem value = { value } /> </ div > )
227239 }
228240}
229241
0 commit comments