Skip to content

Commit 4553203

Browse files
fix(select): added test for multiple chars (failing
1 parent 05fc920 commit 4553203

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ test.describe('Keyboard Behavior', () => {
491491
'select-typeahead-test',
492492
);
493493
await openListbox('ArrowDown');
494-
await getTrigger().pressSequentially('jj', { delay: 250 });
494+
await getTrigger().pressSequentially('jj', { delay: 1250 });
495495
const highlightedOpt = getRoot().locator('[data-highlighted]');
496496
await expect(highlightedOpt).toContainText('jessie', { ignoreCase: true });
497497
});
@@ -506,10 +506,27 @@ test.describe('Keyboard Behavior', () => {
506506
'select-typeahead-test',
507507
);
508508
await openListbox('ArrowDown');
509-
await getTrigger().pressSequentially('jjt', { delay: 250 });
509+
await getTrigger().pressSequentially('jjt', { delay: 1250 });
510510
const highlightedOpt = getRoot().locator('[data-highlighted]');
511511
await expect(highlightedOpt).toContainText('tim', { ignoreCase: true });
512512
});
513+
514+
test(`GIVEN an open select with typeahead support and multiple characters
515+
WHEN the user types in the letter "a"
516+
AND waits a bit, then types in the letter "je"
517+
THEN the first option starting with "je" should have data-highlighted`, async ({
518+
page,
519+
}) => {
520+
const { getRoot, getTrigger, openListbox } = await setup(
521+
page,
522+
'select-typeahead-test',
523+
);
524+
await openListbox('ArrowDown');
525+
await getTrigger().pressSequentially('a', { delay: 1250 });
526+
await getTrigger().pressSequentially('je', { delay: 250 });
527+
const highlightedOpt = getRoot().locator('[data-highlighted]');
528+
await expect(highlightedOpt).toContainText('jessie', { ignoreCase: true });
529+
});
513530
});
514531
});
515532

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ export function useTypeahead() {
6262
inputStrSig.value = '';
6363
}, 1000);
6464
});
65-
//
65+
6666
if (inputStrSig.value.length === 1) {
6767
firstCharOnly$();
6868
}
69-
69+
// const firstCharOptionsSig = useComputed$(() => {
70+
// return context.optionsSig.value.map((opt) => opt.value.slice(0, 1).toLowerCase());
71+
// });
7072
multipleChars$();
7173
});
7274

0 commit comments

Comments
 (0)