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 {
9797 Array . from ( this . list . querySelectorAll < HTMLElement > ( '[role="option"]:not([aria-disabled="true"])' ) )
9898 . filter ( visible ) [ 0 ]
9999 ?. setAttribute ( 'data-combobox-option-default' , 'true' )
100- } else if ( this . firstOptionSelectionMode === 'selected' ) {
100+ } else if ( this . firstOptionSelectionMode === 'selected' && visible ( this . list ) ) {
101101 this . navigate ( 1 )
102102 }
103103 }
@@ -142,9 +142,7 @@ export default class Combobox {
142142 el . removeAttribute ( 'aria-selected' )
143143 }
144144
145- if ( this . firstOptionSelectionMode === 'active' ) {
146- this . indicateDefaultOption ( )
147- }
145+ this . indicateDefaultOption ( )
148146 }
149147}
150148
Original file line number Diff line number Diff line change @@ -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 ++ )
@@ -349,6 +358,15 @@ describe('combobox-nav', function () {
349358 assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
350359 } )
351360
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+
352370 it ( 'indicates first option when restarted' , ( ) => {
353371 combobox . stop ( )
354372 combobox . start ( )
You can’t perform that action at this time.
0 commit comments