@@ -10,6 +10,9 @@ export function useTypeahead() {
10
10
const firstCharOptionsSig = useComputed$ ( ( ) => {
11
11
return context . optionsSig . value . map ( ( opt ) => opt . value . slice ( 0 , 1 ) . toLowerCase ( ) ) ;
12
12
} ) ;
13
+ const fullStrOptionsSig = useComputed$ ( ( ) => {
14
+ return context . optionsSig . value . map ( ( opt ) => opt . value . toLowerCase ( ) ) ;
15
+ } ) ;
13
16
14
17
const typeahead$ = $ ( ( key : string ) : void => {
15
18
inputStrSig . value += key ;
@@ -18,8 +21,6 @@ export function useTypeahead() {
18
21
}
19
22
20
23
const firstCharOnly$ = $ ( ( ) => {
21
- console . log ( 'herehrere' ) ;
22
-
23
24
// First opens the listbox if it is not already displayed and then moves visual focus to the first option that matches the typed character.
24
25
const singleInputChar = key . toLowerCase ( ) ;
25
26
@@ -55,12 +56,22 @@ export function useTypeahead() {
55
56
} ) ;
56
57
57
58
const multipleChars$ = $ ( ( ) => {
58
- console . log ( inputStrSig . value ) ;
59
+ console . log ( 'im running' ) ;
59
60
// If multiple keys are typed in quick succession, visual focus moves to the first option that matches the full string.
60
61
clearTimeout ( prevTimeoutSig . value ) ;
61
62
prevTimeoutSig . value = setTimeout ( ( ) => {
62
63
inputStrSig . value = '' ;
63
64
} , 1000 ) ;
65
+ const firstPossibleOpt = fullStrOptionsSig . value . findIndex ( ( str ) => {
66
+ const size = inputStrSig . value . length ;
67
+ return str . substring ( 0 , size ) === inputStrSig . value ;
68
+ } ) ;
69
+ if ( firstPossibleOpt !== - 1 ) {
70
+ context . highlightedIndexSig . value = firstPossibleOpt ;
71
+ return ;
72
+ }
73
+ inputStrSig . value = '' ;
74
+ firstCharOnly$ ( ) ;
64
75
} ) ;
65
76
66
77
if ( inputStrSig . value . length === 1 ) {
0 commit comments