@@ -280,6 +280,23 @@ describe("multi-select options", () => {
280280 expect ( wrapper . findAll ( ".menu-option" ) . length ) . toBe ( options . length ) ;
281281 expect ( wrapper . findAll ( ".multi-value" ) . length ) . toBe ( 0 ) ;
282282 } ) ;
283+
284+ it ( "should focus second-to-last option when selecting the last option (multi-select)" , async ( ) => {
285+ const wrapper = mount ( VueSelect , { props : { modelValue : [ ] , isMulti : true , options, closeOnSelect : false } } ) ;
286+
287+ await openMenu ( wrapper ) ;
288+
289+ const lastOption = wrapper . findAll ( "div[role='option']" ) [ options . length - 1 ] ;
290+
291+ if ( ! lastOption ) {
292+ throw new Error ( "Last option not found." ) ;
293+ }
294+
295+ await lastOption . trigger ( "click" ) ;
296+ await wrapper . vm . $nextTick ( ) ;
297+
298+ expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 1 ] ?. label ) ;
299+ } ) ;
283300} ) ;
284301
285302describe ( "option-deselected event" , ( ) => {
@@ -828,6 +845,35 @@ describe("menu closing behavior", () => {
828845 await wrapper . get ( "input" ) . trigger ( "mousedown" ) ;
829846 expect ( wrapper . findAll ( "div[role='option']" ) . length ) . toBe ( 2 ) ;
830847 } ) ;
848+
849+ it ( "should not close menu when click target is an option node no longer in DOM (isMulti=true + closeOnSelect=false)" , async ( ) => {
850+ const wrapper = mount ( VueSelect , {
851+ props : { modelValue : [ ] , isMulti : true , options, closeOnSelect : false , hideSelectedOptions : true } ,
852+ attachTo : document . body ,
853+ } ) ;
854+
855+ await openMenu ( wrapper ) ;
856+ expect ( wrapper . findAll ( "div[role='option']" ) . length ) . toBe ( options . length ) ;
857+
858+ const lastOption = wrapper . findAll ( "div[role='option']" ) [ options . length - 1 ] ;
859+ if ( ! lastOption ?. element ) {
860+ throw new Error ( "Last option element not found." ) ;
861+ }
862+
863+ lastOption . trigger ( "click" ) ;
864+ await wrapper . vm . $nextTick ( ) ;
865+
866+ const optionOutsideSelect = document . createElement ( "div" ) ;
867+ optionOutsideSelect . setAttribute ( "role" , "option" ) ;
868+ document . body . appendChild ( optionOutsideSelect ) ;
869+ optionOutsideSelect . dispatchEvent ( new MouseEvent ( "click" , { bubbles : true } ) ) ;
870+ await wrapper . vm . $nextTick ( ) ;
871+
872+ expect ( wrapper . find ( ".menu" ) . exists ( ) ) . toBe ( true ) ;
873+
874+ document . body . removeChild ( optionOutsideSelect ) ;
875+ wrapper . unmount ( ) ;
876+ } ) ;
831877} ) ;
832878
833879describe ( "hideSelectedOptions prop" , ( ) => {
0 commit comments