File tree 2 files changed +46
-2
lines changed
packages/vuetify/src/components/VCombobox
2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -188,11 +188,25 @@ export default VAutocomplete.extend({
188
188
} ,
189
189
updateEditing ( ) {
190
190
const value = this . internalValue . slice ( )
191
- value [ this . editingIndex ] = this . internalSearch
191
+ const index = this . selectedItems . findIndex ( item =>
192
+ this . getText ( item ) === this . internalSearch )
192
193
193
- this . setValue ( value )
194
+ // If user enters a duplicate text on chip edit,
195
+ // don't add it, move it to the end of the list
196
+ if ( index > - 1 ) {
197
+ const item = typeof value [ index ] === 'object'
198
+ ? Object . assign ( { } , value [ index ] )
199
+ : value [ index ]
200
+
201
+ value . splice ( index , 1 )
202
+ value . push ( item )
203
+ } else {
204
+ value [ this . editingIndex ] = this . internalSearch
205
+ }
194
206
207
+ this . setValue ( value )
195
208
this . editingIndex = - 1
209
+ this . internalSearch = null
196
210
} ,
197
211
updateCombobox ( ) {
198
212
// If search is not dirty, do nothing
Original file line number Diff line number Diff line change @@ -548,4 +548,34 @@ describe('VCombobox.ts', () => {
548
548
549
549
expect ( change ) . toHaveBeenLastCalledWith ( [ { text : 'foo' , value : 'foo' } ] )
550
550
} )
551
+
552
+ // https://github.com/vuetifyjs/vuetify/issues/6364
553
+ it ( 'should not add duplicate chip after edit' , async ( ) => {
554
+ const { wrapper, change } = createMultipleCombobox ( {
555
+ chips : true ,
556
+ multiple : true ,
557
+ clearable : true ,
558
+ items : [ 'foo' , 'bar' ] ,
559
+ value : [ 'foo' , 'bar' ] ,
560
+ } )
561
+
562
+ const input = wrapper . find ( 'input' )
563
+ const element = input . element as HTMLInputElement
564
+
565
+ // Dbl click chip at index 1
566
+ const chip = wrapper . findAll ( '.v-chip' ) . at ( 1 )
567
+ chip . trigger ( 'dblclick' )
568
+ expect ( wrapper . vm . editingIndex ) . toBe ( 1 )
569
+ expect ( wrapper . vm . internalSearch ) . toBe ( 'bar' )
570
+
571
+ // Add a duplicate value - 'foo'
572
+ input . trigger ( 'focus' )
573
+ element . value = 'foo'
574
+ input . trigger ( 'input' )
575
+ await wrapper . vm . $nextTick ( )
576
+ input . trigger ( 'keydown.enter' )
577
+ await wrapper . vm . $nextTick ( )
578
+
579
+ expect ( change ) . toHaveBeenLastCalledWith ( [ 'bar' , 'foo' ] )
580
+ } )
551
581
} )
You can’t perform that action at this time.
0 commit comments