Skip to content

Commit 07501d6

Browse files
fix(core/select): fixed input clear issue if selection option changes (#2404)
Co-authored-by: Lukas Maurer <lukas.maurer@siemens.com>
1 parent a5f8477 commit 07501d6

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

.changeset/dry-pandas-knock.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@siemens/ix": patch
3+
---
4+
5+
Keep user input if select items change in _ix-select_.
6+
7+
Fixes #1716

packages/core/src/components/select/select.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ export class Select implements IxInputFieldComponent<string | string[]> {
464464

465465
this.selectedLabels = this.selectedItems.map((item) => item.label);
466466

467+
if (this.dropdownShow && this.inputFilterText) {
468+
return;
469+
}
470+
467471
if (this.selectedLabels?.length && this.isSingleMode) {
468472
this.inputValue = this.selectedLabels[0] ?? '';
469473
} else {

packages/core/src/components/select/test/select.ct.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,3 +1080,35 @@ test('clear button returns empty string in single mode', async ({
10801080

10811081
expect(emittedValue).toBe('');
10821082
});
1083+
1084+
test('input does not clear when items added during search', async ({
1085+
mount,
1086+
page,
1087+
}) => {
1088+
await mount(`
1089+
<ix-select i18n-placeholder="Search in database...">
1090+
<ix-select-item value="1" label="Initial">Initial</ix-select-item>
1091+
</ix-select>
1092+
`);
1093+
1094+
const input = page.getByTestId('input');
1095+
1096+
await page.locator('[data-select-dropdown]').click();
1097+
await input.fill('test');
1098+
await expect(input).toHaveValue('test');
1099+
1100+
await page.evaluate(() => {
1101+
const select = document.querySelector('ix-select');
1102+
const newItem = document.createElement('ix-select-item');
1103+
newItem.setAttribute('value', 'test-result');
1104+
newItem.setAttribute('label', 'Test Result from API');
1105+
select?.appendChild(newItem);
1106+
});
1107+
1108+
await page.waitForTimeout(100);
1109+
1110+
await expect(input).toHaveValue('test');
1111+
await expect(
1112+
page.getByRole('button', { name: 'Test Result from API' })
1113+
).toBeVisible();
1114+
});

0 commit comments

Comments
 (0)