@@ -27,7 +27,9 @@ export default class Autocomplete {
27
27
this . container = container
28
28
this . input = input
29
29
this . results = results
30
- this . combobox = new Combobox ( input , results )
30
+ this . combobox = new Combobox ( input , results , {
31
+ defaultFirstOption : autoselectEnabled ,
32
+ } )
31
33
this . feedback = ( container . getRootNode ( ) as Document ) . getElementById ( `${ this . results . id } -feedback` )
32
34
this . autoselectEnabled = autoselectEnabled
33
35
this . clearButton = ( container . getRootNode ( ) as Document ) . getElementById ( `${ this . input . id || this . input . name } -clear` )
@@ -108,17 +110,6 @@ export default class Autocomplete {
108
110
}
109
111
110
112
onKeydown ( event : KeyboardEvent ) : void {
111
- // if autoselect is enabled, Enter key will select the first option
112
- if ( event . key === 'Enter' && this . container . open && this . autoselectEnabled ) {
113
- const firstOption = this . results . children [ 0 ]
114
- if ( firstOption ) {
115
- event . stopPropagation ( )
116
- event . preventDefault ( )
117
-
118
- this . onCommit ( { target : firstOption } )
119
- }
120
- }
121
-
122
113
if ( event . key === 'Escape' && this . container . open ) {
123
114
this . container . open = false
124
115
event . stopPropagation ( )
@@ -212,6 +203,7 @@ export default class Autocomplete {
212
203
// eslint-disable-next-line github/no-inner-html
213
204
this . results . innerHTML = html as string
214
205
this . identifyOptions ( )
206
+ this . combobox . indicateDefaultOption ( )
215
207
const allNewOptions = this . results . querySelectorAll ( '[role="option"]' )
216
208
const hasResults = ! ! allNewOptions . length
217
209
const numOptions = allNewOptions . length
0 commit comments