Skip to content

Commit fe7322e

Browse files
fix(select): correct behavior on input str, multiple keys
1 parent 9a0b871 commit fe7322e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/kit-headless/src/components/select/use-select.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ export function useTypeahead() {
55
const context = useContext(SelectContextId);
66
const inputStrSig = useSignal('');
77
const indexDiffSig = useSignal<number | undefined>(undefined);
8+
const prevTimeoutSig = useSignal<undefined | NodeJS.Timeout>(undefined);
89

910
const firstCharOptionsSig = useComputed$(() => {
1011
return context.optionsSig.value.map((opt) => opt.value.slice(0, 1).toLowerCase());
1112
});
1213

1314
const typeahead$ = $((key: string): void => {
15+
inputStrSig.value += key;
1416
if (key.length > 1) {
1517
return;
1618
}
@@ -53,10 +55,17 @@ export function useTypeahead() {
5355
});
5456

5557
const multipleChars$ = $(() => {
58+
console.log(inputStrSig.value);
59+
5660
// 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);
5765
});
5866

5967
firstCharOnly$();
68+
multipleChars$();
6069
});
6170

6271
return { typeahead$ };

0 commit comments

Comments
 (0)