Skip to content

Commit 4408ba2

Browse files
fix more tests
1 parent 83b4141 commit 4408ba2

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export const HSelectTrigger = component$<SelectTriggerProps>((props) => {
4242
const handleKeyDown$ = $(async (e: KeyboardEvent) => {
4343
if (!context.itemsMapSig.value) return;
4444

45-
typeahead$(e.key);
45+
if (!context.isListboxOpenSig.value) {
46+
typeahead$(e.key);
47+
}
4648

4749
switch (e.key) {
4850
case 'Tab':

packages/kit-headless/src/components/select/select.test.ts

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,14 @@ test.describe('Keyboard Behavior', () => {
396396
AND the Enter key is pressed
397397
THEN option value should be the selected value
398398
AND should have an aria-selected of true`, async ({ page }) => {
399-
const {
400-
getTrigger,
401-
getItemAt: getOptionAt,
402-
getValueElement,
403-
openListbox,
404-
} = await setup(page, 'hero');
399+
const { driver: d } = await setup(page, 'hero');
405400

406-
await openListbox('Enter');
401+
await d.openListbox('Enter');
407402

408-
await expect(getOptionAt(0)).toHaveAttribute('data-highlighted');
409-
const expectedValue = await getOptionAt(0).textContent();
410-
await getTrigger().press('Enter');
411-
await expect(getValueElement()).toHaveText(expectedValue!);
403+
await expect(d.getItemAt(0)).toHaveAttribute('data-highlighted');
404+
const expectedValue = await d.getItemAt(0).textContent();
405+
await d.getItemAt(0).press('Enter');
406+
await expect(d.getValueElement()).toHaveText(expectedValue!);
412407
});
413408

414409
test(`GIVEN an open hero select
@@ -438,19 +433,14 @@ test.describe('Keyboard Behavior', () => {
438433
AND the Space key is pressed
439434
THEN option value should be the selected value
440435
AND should have an aria-selected of true`, async ({ page }) => {
441-
const {
442-
getTrigger,
443-
getItemAt: getOptionAt,
444-
getValueElement,
445-
openListbox,
446-
} = await setup(page, 'hero');
436+
const { driver: d } = await setup(page, 'hero');
447437

448-
await openListbox('Space');
438+
await d.openListbox('Space');
449439

450-
await expect(getOptionAt(0)).toHaveAttribute('data-highlighted');
451-
const expectedValue = await getOptionAt(0).textContent();
452-
await getTrigger().press('Space');
453-
await expect(getValueElement()).toHaveText(expectedValue!);
440+
await expect(d.getItemAt(0)).toHaveAttribute('data-highlighted');
441+
const expectedValue = await d.getItemAt(0).textContent();
442+
await d.getItemAt(0).press('Space');
443+
await expect(d.getValueElement()).toHaveText(expectedValue!);
454444
});
455445

456446
test(`GIVEN no selected item and a placeholder
@@ -535,11 +525,12 @@ test.describe('Keyboard Behavior', () => {
535525
THEN the second option starting with the letter "j" should have data-highlighted`, async ({
536526
page,
537527
}) => {
538-
const { getRoot, getTrigger, openListbox } = await setup(page, 'typeahead');
528+
const { getRoot, openListbox } = await setup(page, 'typeahead');
539529
await openListbox('ArrowDown');
540-
await getTrigger().pressSequentially('jj', { delay: 1250 });
541-
const highlightedOpt = getRoot().locator('[data-highlighted]');
542-
await expect(highlightedOpt).toContainText('jessie', { ignoreCase: true });
530+
const highlightedItem = getRoot().locator('[data-highlighted]');
531+
532+
await highlightedItem.pressSequentially('jj', { delay: 1250 });
533+
await expect(highlightedItem).toContainText('jessie', { ignoreCase: true });
543534
});
544535

545536
test(`GIVEN an open select with a typeahead support

0 commit comments

Comments
 (0)