@@ -285,6 +285,15 @@ describe('combobox-nav', function () {
285
285
assert . equal ( document . querySelector ( '[data-combobox-option-default]' ) , options [ 0 ] )
286
286
} )
287
287
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
+
288
297
it ( 'applies default option on Enter' , ( ) => {
289
298
let commits = 0
290
299
document . addEventListener ( 'combobox-commit' , ( ) => commits ++ )
@@ -299,12 +308,18 @@ describe('combobox-nav', function () {
299
308
assert . equal ( document . querySelectorAll ( '[data-combobox-option-default]' ) . length , 0 )
300
309
} )
301
310
302
- it ( 'resets default indication when selection cleared ' , ( ) => {
311
+ it ( 'resets default indication when selection reset ' , ( ) => {
303
312
combobox . navigate ( 1 )
304
- combobox . clearSelection ( )
313
+ combobox . resetSelection ( )
305
314
assert . equal ( document . querySelectorAll ( '[data-combobox-option-default]' ) . length , 1 )
306
315
} )
307
316
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
+
308
323
it ( 'does not error when no options are visible' , ( ) => {
309
324
assert . doesNotThrow ( ( ) => {
310
325
document . getElementById ( 'list-id' ) . style . display = 'none'
@@ -325,8 +340,6 @@ describe('combobox-nav', function () {
325
340
<li><del>BB-8</del></li>
326
341
<li id="hubot" role="option">Hubot</li>
327
342
<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>
330
343
<li><a href="#link" role="option" id="link">Link</a></li>
331
344
</ul>
332
345
`
@@ -349,6 +362,32 @@ describe('combobox-nav', function () {
349
362
assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
350
363
} )
351
364
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
+
352
391
it ( 'indicates first option when restarted' , ( ) => {
353
392
combobox . stop ( )
354
393
combobox . start ( )
0 commit comments