Skip to content

Commit

Permalink
fix(core/ix-select): select known items in ediable mode on enter navi…
Browse files Browse the repository at this point in the history
…gation (#1659)

Co-authored-by: Julian Lamplmair <151610373+jul-lam@users.noreply.github.com>
  • Loading branch information
matthiashader and jul-lam authored Jan 29, 2025
1 parent ae4363d commit d28d621
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-garlics-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siemens/ix': patch
---

Fix `ix-select` in editable mode to correctly select a known item when confirmed with Enter.
9 changes: 4 additions & 5 deletions packages/core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,11 @@ export class Select implements IxInputFieldComponent<string | string[]> {

const trimmedInput = this.inputFilterText.trim();
const itemLabel = (el as HTMLIxSelectItemElement)?.label;
const item = this.itemExists(trimmedInput);

if (
this.editable &&
!this.itemExists(trimmedInput) &&
!this.itemExists(itemLabel)
) {
if (item) {
this.itemClick(item.value);
} else if (this.editable && !this.itemExists(itemLabel)) {
const defaultPrevented = this.emitAddItem(trimmedInput);
if (defaultPrevented) {
return;
Expand Down
46 changes: 46 additions & 0 deletions packages/core/src/components/select/test/select.ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,49 @@ test('async set content and check input value', async ({ mount, page }) => {
const input = page.locator('input');
await expect(input).toHaveValue('Item 1');
});

test.describe('Enter selection with non-existing and existing items', () => {
test('editable', async ({ mount, page }) => {
await mount(`
<ix-select editable>
<ix-select-item value="1" label="Item 1">Test</ix-select-item>
<ix-select-item value="2" label="Item 2">Test</ix-select-item>
</ix-select>
`);

const selectElement = page.locator('ix-select');
const input = selectElement.locator('input');

await input.fill('Item 1');
await page.keyboard.press('Enter');

await expect(input).toHaveValue('Item 1');

await input.fill('Item 3');
await page.keyboard.press('Enter');

await expect(input).toHaveValue('Item 3');
});

test('non-editable', async ({ mount, page }) => {
await mount(`
<ix-select>
<ix-select-item value="1" label="Item 1">Test</ix-select-item>
<ix-select-item value="2" label="Item 2">Test</ix-select-item>
</ix-select>
`);

const selectElement = page.locator('ix-select');
const input = selectElement.locator('input');

await input.fill('Item 1');
await page.keyboard.press('Enter');

await expect(input).toHaveValue('Item 1');

await input.fill('Item 3');
await page.keyboard.press('Enter');

await expect(input).toHaveValue('Item 1');
});
});

0 comments on commit d28d621

Please sign in to comment.