@@ -6,6 +6,7 @@ import { nextTick } from 'vue'
66import { handleSubmit , sleep } from '@/test'
77import Combobox from './story/_Combobox.vue'
88import ComboboxObject from './story/_ComboboxObject.vue'
9+ import ComboboxTagsInput from './story/_ComboboxTagsInput.vue'
910
1011describe ( 'given default Combobox' , ( ) => {
1112 let wrapper : VueWrapper < InstanceType < typeof Combobox > >
@@ -403,3 +404,57 @@ describe('given combobox in a form', async () => {
403404 } )
404405 } )
405406} )
407+
408+ describe ( 'given Combobox with TagsInput and addOnBlur' , ( ) => {
409+ let wrapper : VueWrapper < InstanceType < typeof ComboboxTagsInput > >
410+ let input : DOMWrapper < HTMLInputElement >
411+
412+ beforeEach ( ( ) => {
413+ document . body . innerHTML = ''
414+ wrapper = mount ( ComboboxTagsInput , {
415+ props : { addOnBlur : true } ,
416+ attachTo : document . body ,
417+ } )
418+ input = wrapper . find ( 'input' )
419+ } )
420+
421+ it ( 'should select the combobox item instead of adding raw input text as tag' , async ( ) => {
422+ // Focus input and type "a" to filter
423+ input . element . focus ( )
424+ await input . setValue ( 'a' )
425+ await nextTick ( )
426+
427+ // Simulate the blur that happens when clicking an option (jsdom doesn't do this automatically)
428+ const option = wrapper . find ( '[role=option]' )
429+ expect ( option . text ( ) ) . toContain ( 'Apple' )
430+
431+ // In a real browser: mousedown on option → input blurs → click fires
432+ await input . trigger ( 'blur' , { relatedTarget : option . element } )
433+ await option . trigger ( 'click' )
434+ await nextTick ( )
435+
436+ // "Apple" should be added as tag, NOT the raw text "a"
437+ const tags = wrapper . findAll ( '[data-reka-collection-item]' )
438+ const tagTexts = tags . map ( t => t . text ( ) )
439+ expect ( tagTexts ) . toContain ( 'Apple' )
440+ expect ( tagTexts ) . not . toContain ( 'a' )
441+ } )
442+
443+ it ( 'should refocus input after selecting in multiple mode' , async ( ) => {
444+ // Focus input and open dropdown
445+ input . element . focus ( )
446+ await input . setValue ( 'a' )
447+ await nextTick ( )
448+
449+ const option = wrapper . find ( '[role=option]' )
450+
451+ // In a real browser, mousedown on option blurs the input.
452+ // Simulate this: blur the input, then click the option.
453+ input . element . blur ( )
454+ await option . trigger ( 'click' )
455+ await nextTick ( )
456+
457+ // Input should be refocused so subsequent blur can trigger addOnBlur
458+ expect ( document . activeElement ) . toBe ( input . element )
459+ } )
460+ } )
0 commit comments