File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ export default class Combobox {
97
97
Array . from ( this . list . querySelectorAll < HTMLElement > ( '[role="option"]:not([aria-disabled="true"])' ) )
98
98
. filter ( visible ) [ 0 ]
99
99
?. setAttribute ( 'data-combobox-option-default' , 'true' )
100
- } else if ( this . firstOptionSelectionMode === 'selected' ) {
100
+ } else if ( this . firstOptionSelectionMode === 'selected' && visible ( this . list ) ) {
101
101
this . navigate ( 1 )
102
102
}
103
103
}
@@ -142,9 +142,7 @@ export default class Combobox {
142
142
el . removeAttribute ( 'aria-selected' )
143
143
}
144
144
145
- if ( this . firstOptionSelectionMode === 'active' ) {
146
- this . indicateDefaultOption ( )
147
- }
145
+ this . indicateDefaultOption ( )
148
146
}
149
147
}
150
148
Original file line number Diff line number Diff line change @@ -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 ++ )
@@ -349,6 +358,15 @@ describe('combobox-nav', function () {
349
358
assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
350
359
} )
351
360
361
+ it ( 'first item remains selected when typing' , ( ) => {
362
+ const text = 'R2-D2'
363
+ for ( let i = 0 ; i < text . length ; i ++ ) {
364
+ press ( input , text [ i ] )
365
+ }
366
+
367
+ assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
368
+ } )
369
+
352
370
it ( 'indicates first option when restarted' , ( ) => {
353
371
combobox . stop ( )
354
372
combobox . start ( )
You can’t perform that action at this time.
0 commit comments