Skip to content

Commit 9a0b871

Browse files
fix(select): typeahead now properly moves to other options
1 parent 1f800d5 commit 9a0b871

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

apps/website/src/routes/docs/headless/select/select.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,21 @@ test.describe('Keyboard Behavior', () => {
495495
const highlightedOpt = getRoot().locator('[data-highlighted]');
496496
await expect(highlightedOpt).toContainText('jessie', { ignoreCase: true });
497497
});
498+
499+
test(`GIVEN an open select with a typeahead support
500+
WHEN the user types in the letters "jjt"
501+
THEN the first option starting with the letter "t" should have data-highlighted`, async ({
502+
page,
503+
}) => {
504+
const { getRoot, getTrigger, openListbox } = await setup(
505+
page,
506+
'select-typeahead-test',
507+
);
508+
await openListbox('ArrowDown');
509+
await getTrigger().pressSequentially('jjt', { delay: 250 });
510+
const highlightedOpt = getRoot().locator('[data-highlighted]');
511+
await expect(highlightedOpt).toContainText('tim', { ignoreCase: true });
512+
});
498513
});
499514
});
500515

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export function useTypeahead() {
2727
return null;
2828
}
2929
if (indexDiffSig.value === undefined) {
30-
console.log('Is key length 1?', charIndex);
3130
indexDiffSig.value = charIndex + 1;
3231
context.highlightedIndexSig.value = charIndex;
3332
return;
@@ -45,11 +44,18 @@ export function useTypeahead() {
4544
context.highlightedIndexSig.value = nextIndex;
4645
indexDiffSig.value = nextIndex + 1;
4746
}
47+
return;
4848
}
49+
indexDiffSig.value = charIndex + 1;
50+
context.highlightedIndexSig.value = charIndex;
4951

5052
return;
5153
});
5254

55+
const multipleChars$ = $(() => {
56+
// If multiple keys are typed in quick succession, visual focus moves to the first option that matches the full string.
57+
});
58+
5359
firstCharOnly$();
5460
});
5561

0 commit comments

Comments
 (0)