Skip to content

Commit

Permalink
fix(core/select): fixed behaviour and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiashader committed Oct 16, 2023
1 parent 0469f3f commit 6c28109
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,12 @@ export class Select {
this.isDropdownEmpty = this.isEveryDropdownItemHidden;
} else {
this.navigationItem = undefined;
this.inputFilterText = undefined;
this.inputRef.value = this.selectedLabels[0];

if (this.selectedLabels[0] && !this.isMultipleMode) {
this.inputRef.value = this.selectedLabels[0];
} else {
this.clearInput();
}
}
}

Expand Down
23 changes: 22 additions & 1 deletion packages/core/src/components/select/test/select.ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test('editable mode', async ({ mount, page }) => {
.getByRole('listitem')
.filter({ hasText: 'Not existing' });

await expect(addedItem).toBeVisible();
await expect(addedItem.first()).toBeVisible();
});

test('single selection', async ({ mount, page }) => {
Expand Down Expand Up @@ -150,3 +150,24 @@ test('filter', async ({ mount, page }) => {
await expect(item4).not.toBeVisible();
await expect(item_abc).toBeVisible();
});

test('display selected option', async ({ mount, page }) => {
await mount(`
<ix-select>
<ix-select-item value="11" label="Item 1">Test</ix-select-item>
<ix-select-item value="22" label="Item 2">Test</ix-select-item>
</ix-select>
`);
const element = page.locator('ix-select');
await element.evaluate(
(select: HTMLIxSelectElement) => (select.value = '22')
);

await page.locator('[data-select-dropdown]').click();
await page.getByTestId('input').fill('Not existing');

await page.click('body');

const inputText = await page.inputValue('input');
expect(inputText).toEqual('Item 2');
});

0 comments on commit 6c28109

Please sign in to comment.