fix(VCombobox): correctly handle duplicate items #13366
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Correctly handle duplicate item addition in combobox. Fixes #12351
Motivation and Context
Combobox removes the saved value on blur when an input string matches an existing item. This only happens with the list of objects and works fine with the list of strings. When we input a string in the combobox it is checked for the duplicate in the existing selected item list. This is done in updateTags() in VCombobox.ts
const index = this.selectedItems.indexOf(this.internalSearch)
This check will always fail for objects, as it is compared with a string. Then we try to add the search value to the list of selected items in selectItem() in VSelect.ts . There this value is found in the list of items and hence deselected, which removes it from the selected items list.
The fix is to correctly search and add object in the selected items list.
How Has This Been Tested?
Unit testing and Visually
Markup:
Types of changes
Checklist:
master
for bug fixes and documentation updates,dev
for new features and backwards compatible changes andnext
for non-backwards compatible changes).