@@ -80,7 +80,6 @@ export default class Combobox {
80
80
; ( this . input as HTMLElement ) . addEventListener ( 'keydown' , this . keyboardEventHandler )
81
81
this . list . addEventListener ( 'click' , commitWithElement )
82
82
this . indicateDefaultOption ( )
83
- this . selectFirstItemIfNeeded ( )
84
83
}
85
84
86
85
stop ( ) : void {
@@ -98,11 +97,7 @@ export default class Combobox {
98
97
Array . from ( this . list . querySelectorAll < HTMLElement > ( '[role="option"]:not([aria-disabled="true"])' ) )
99
98
. filter ( visible ) [ 0 ]
100
99
?. setAttribute ( 'data-combobox-option-default' , 'true' )
101
- }
102
- }
103
-
104
- selectFirstItemIfNeeded ( ) : void {
105
- if ( this . firstOptionSelectionMode === 'selected' ) {
100
+ } else if ( this . firstOptionSelectionMode === 'selected' ) {
106
101
this . navigate ( 1 )
107
102
}
108
103
}
@@ -113,7 +108,7 @@ export default class Combobox {
113
108
const focusIndex = els . indexOf ( focusEl )
114
109
115
110
if ( ( focusIndex === els . length - 1 && indexDiff === 1 ) || ( focusIndex === 0 && indexDiff === - 1 ) ) {
116
- this . clearSelection ( )
111
+ this . resetSelection ( )
117
112
this . input . focus ( )
118
113
return
119
114
}
@@ -146,10 +141,11 @@ export default class Combobox {
146
141
for ( const el of this . list . querySelectorAll ( '[aria-selected="true"]' ) ) {
147
142
el . removeAttribute ( 'aria-selected' )
148
143
}
144
+ }
149
145
150
- if ( this . firstOptionSelectionMode === 'active' ) {
151
- this . indicateDefaultOption ( )
152
- }
146
+ resetSelection ( ) : void {
147
+ this . clearSelection ( )
148
+ this . indicateDefaultOption ( )
153
149
}
154
150
}
155
151
@@ -194,8 +190,7 @@ function keyboardBindings(event: KeyboardEvent, combobox: Combobox) {
194
190
break
195
191
default :
196
192
if ( event . ctrlKey ) break
197
- combobox . clearSelection ( )
198
- combobox . selectFirstItemIfNeeded ( )
193
+ combobox . resetSelection ( )
199
194
}
200
195
}
201
196
0 commit comments