Skip to content

Commit bbf4cd1

Browse files
authored
fix(combobox-multi-select): DP-180791 cursor position (#1141)
1 parent 81e25ed commit bbf4cd1

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

packages/dialtone-vue/components/combobox_multi_select/combobox_multi_select.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,38 @@ describe('DtComboboxMultiSelect Tests', () => {
305305
});
306306
});
307307

308+
describe('Duplicate Items Tests', () => {
309+
beforeEach(async () => {
310+
await wrapper.setProps({ selectedItems: ['item1', 'item1', 'item1'] });
311+
await flushPromises();
312+
_setChildWrappers();
313+
});
314+
315+
it('should render a chip for each duplicate item', () => {
316+
expect(chips.length).toBe(3);
317+
});
318+
319+
it('should return distinct elements from getChips for duplicates', () => {
320+
const chipElements = wrapper.vm.getChips();
321+
const unique = new Set(chipElements);
322+
expect(unique.size).toBe(3);
323+
});
324+
});
325+
326+
describe('Bulk Update Tests', () => {
327+
it('should return chips in selectedItems order after bulk update', async () => {
328+
await wrapper.setProps({ selectedItems: ['alpha', 'beta', 'gamma'] });
329+
await flushPromises();
330+
_setChildWrappers();
331+
332+
const chipElements = wrapper.vm.getChips();
333+
const labels = chipElements.map(
334+
el => el.querySelector('.d-chip__label')?.textContent?.trim(),
335+
);
336+
expect(labels).toEqual(['alpha', 'beta', 'gamma']);
337+
});
338+
});
339+
308340
describe('Validation Tests', () => {
309341
beforeEach(async () => {
310342
await wrapper.setProps({

packages/dialtone-vue/components/combobox_multi_select/combobox_multi_select.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
:class="['d-recipe-combobox-multi-select__chip-wrapper', chipWrapperClass]"
2828
>
2929
<dt-chip
30-
v-for="item in selectedItems"
30+
v-for="(item, index) in selectedItems"
3131
ref="chips"
32-
:key="item"
32+
:key="`${index}-${item}`"
3333
:label-class="['d-chip__label']"
3434
:class="[
3535
'd-recipe-combobox-multi-select__chip',
@@ -586,11 +586,18 @@ export default {
586586
getChips () {
587587
if (!this.selectedItems.length || !this.$refs.chips) return null;
588588
589-
// use the order from selectedItems to not rely on DOM order which may be stale
589+
// Use the order from selectedItems to not rely on DOM order which may be stale.
590+
// Track matched indices to handle duplicate item names correctly.
591+
const matched = new Set();
590592
const chips = this.selectedItems.map(item => {
591-
return this.$refs.chips.find(chip => {
593+
return this.$refs.chips.find((chip, index) => {
594+
if (matched.has(index)) return false;
592595
const chipLabel = returnFirstEl(chip.$el)?.querySelector('.d-chip__label')?.textContent?.trim();
593-
return chipLabel === item;
596+
if (chipLabel === item) {
597+
matched.add(index);
598+
return true;
599+
}
600+
return false;
594601
});
595602
});
596603
return chips.filter(Boolean).map(chip => returnFirstEl(chip.$el));

0 commit comments

Comments
 (0)