File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
packages/kit-headless/src/components/select Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ export function useTypeahead() {
5
5
const context = useContext ( SelectContextId ) ;
6
6
const inputStrSig = useSignal ( '' ) ;
7
7
const indexDiffSig = useSignal < number | undefined > ( undefined ) ;
8
+ const prevTimeoutSig = useSignal < undefined | NodeJS . Timeout > ( undefined ) ;
8
9
9
10
const firstCharOptionsSig = useComputed$ ( ( ) => {
10
11
return context . optionsSig . value . map ( ( opt ) => opt . value . slice ( 0 , 1 ) . toLowerCase ( ) ) ;
11
12
} ) ;
12
13
13
14
const typeahead$ = $ ( ( key : string ) : void => {
15
+ inputStrSig . value += key ;
14
16
if ( key . length > 1 ) {
15
17
return ;
16
18
}
@@ -53,10 +55,17 @@ export function useTypeahead() {
53
55
} ) ;
54
56
55
57
const multipleChars$ = $ ( ( ) => {
58
+ console . log ( inputStrSig . value ) ;
59
+
56
60
// If multiple keys are typed in quick succession, visual focus moves to the first option that matches the full string.
61
+ clearTimeout ( prevTimeoutSig . value ) ;
62
+ prevTimeoutSig . value = setTimeout ( ( ) => {
63
+ inputStrSig . value = '' ;
64
+ } , 1000 ) ;
57
65
} ) ;
58
66
59
67
firstCharOnly$ ( ) ;
68
+ multipleChars$ ( ) ;
60
69
} ) ;
61
70
62
71
return { typeahead$ } ;
You can’t perform that action at this time.
0 commit comments