@@ -285,6 +285,15 @@ describe('combobox-nav', function () {
285285 assert . equal ( document . querySelector ( '[data-combobox-option-default]' ) , options [ 0 ] )
286286 } )
287287
288+ it ( 'first item remains active when typing' , ( ) => {
289+ const text = 'R2-D2'
290+ for ( let i = 0 ; i < text . length ; i ++ ) {
291+ press ( input , text [ i ] )
292+ }
293+
294+ assert . equal ( document . querySelector ( '[data-combobox-option-default]' ) , options [ 0 ] )
295+ } )
296+
288297 it ( 'applies default option on Enter' , ( ) => {
289298 let commits = 0
290299 document . addEventListener ( 'combobox-commit' , ( ) => commits ++ )
@@ -299,12 +308,18 @@ describe('combobox-nav', function () {
299308 assert . equal ( document . querySelectorAll ( '[data-combobox-option-default]' ) . length , 0 )
300309 } )
301310
302- it ( 'resets default indication when selection cleared ' , ( ) => {
311+ it ( 'resets default indication when selection reset ' , ( ) => {
303312 combobox . navigate ( 1 )
304- combobox . clearSelection ( )
313+ combobox . resetSelection ( )
305314 assert . equal ( document . querySelectorAll ( '[data-combobox-option-default]' ) . length , 1 )
306315 } )
307316
317+ it ( 'removes default indication when selection cleared' , ( ) => {
318+ combobox . navigate ( 1 )
319+ combobox . clearSelection ( )
320+ assert . equal ( document . querySelectorAll ( '[data-combobox-option-default]' ) . length , 0 )
321+ } )
322+
308323 it ( 'does not error when no options are visible' , ( ) => {
309324 assert . doesNotThrow ( ( ) => {
310325 document . getElementById ( 'list-id' ) . style . display = 'none'
@@ -325,8 +340,6 @@ describe('combobox-nav', function () {
325340 <li><del>BB-8</del></li>
326341 <li id="hubot" role="option">Hubot</li>
327342 <li id="r2-d2" role="option">R2-D2</li>
328- <li id="johnny-5" hidden role="option">Johnny 5</li>
329- <li id="wall-e" role="option" aria-disabled="true">Wall-E</li>
330343 <li><a href="#link" role="option" id="link">Link</a></li>
331344 </ul>
332345 `
@@ -349,6 +362,32 @@ describe('combobox-nav', function () {
349362 assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
350363 } )
351364
365+ it ( 'first item remains selected when typing' , ( ) => {
366+ const text = 'R2-D2'
367+ for ( let i = 0 ; i < text . length ; i ++ ) {
368+ press ( input , text [ i ] )
369+ }
370+
371+ assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
372+ } )
373+
374+ it ( 'pressing key down off the last item will have no items selected' , ( ) => {
375+ // Get all visible options in the list
376+ const options = document . querySelectorAll ( '[role=option]:not([aria-hidden=true])' )
377+ // Key press down for each item and ensure the next is selected
378+ for ( let i = 0 ; i < options . length ; i ++ ) {
379+ if ( i > 0 ) {
380+ assert . equal ( options [ i - 1 ] . getAttribute ( 'aria-selected' ) , null )
381+ }
382+
383+ assert . equal ( options [ i ] . getAttribute ( 'aria-selected' ) , 'true' )
384+ press ( input , 'ArrowDown' )
385+ }
386+
387+ const selected = document . querySelectorAll ( '[aria-selected]' )
388+ assert . equal ( selected . length , 0 )
389+ } )
390+
352391 it ( 'indicates first option when restarted' , ( ) => {
353392 combobox . stop ( )
354393 combobox . start ( )
0 commit comments