3
3
*/
4
4
import Constants from './constants' ;
5
5
import type { HtmlStruct , MultipleSelectLocales , OptGroupRowData , OptionDataObject , OptionRowData } from './interfaces' ;
6
- import type { MultipleSelectOption } from './interfaces/multipleSelectOption.interface' ;
6
+ import type { CloseReason , MultipleSelectOption } from './interfaces/multipleSelectOption.interface' ;
7
7
import { BindingEventService , VirtualScroll } from './services' ;
8
8
import { compareObjects , deepCopy , findByParam , removeDiacritics , removeUndefined , setDataKeys , stripScripts } from './utils' ;
9
9
import {
@@ -267,7 +267,7 @@ export class MultipleSelectInstance {
267
267
( e . target === this . dropElm || ( findParent ( e . target , '.ms-drop' ) !== this . dropElm && e . target !== this . elm ) ) &&
268
268
this . options . isOpen
269
269
) {
270
- this . close ( ) ;
270
+ this . close ( 'body.click' ) ;
271
271
}
272
272
} ) as EventListener ,
273
273
undefined ,
@@ -372,7 +372,7 @@ export class MultipleSelectInstance {
372
372
373
373
if ( this . options . openOnHover && this . parentElm ) {
374
374
this . _bindEventService . bind ( this . parentElm , 'mouseover' , ( ) => this . open ( null ) ) ;
375
- this . _bindEventService . bind ( this . parentElm , 'mouseout' , ( ) => this . close ( ) ) ;
375
+ this . _bindEventService . bind ( this . parentElm , 'mouseout' , ( ) => this . close ( 'hover.mouseout' ) ) ;
376
376
}
377
377
}
378
378
@@ -801,7 +801,7 @@ export class MultipleSelectInstance {
801
801
if ( e . target . classList . contains ( 'ms-icon-close' ) ) {
802
802
return ;
803
803
}
804
- this [ this . options . isOpen ? ' close' : ' open' ] ( ) ;
804
+ this . options . isOpen ? this . close ( 'toggle. close') : this . open ( ) ;
805
805
} ;
806
806
807
807
if ( this . labelElm ) {
@@ -864,7 +864,7 @@ export class MultipleSelectInstance {
864
864
( ( e : KeyboardEvent ) => {
865
865
// Ensure shift-tab causes lost focus from filter as with clicking away
866
866
if ( e . code === 'Tab' && e . shiftKey ) {
867
- this . close ( ) ;
867
+ this . close ( 'key.shift+tab' ) ;
868
868
}
869
869
} ) as EventListener ,
870
870
undefined ,
@@ -891,7 +891,7 @@ export class MultipleSelectInstance {
891
891
} else {
892
892
this . selectAllElm ?. click ( ) ;
893
893
}
894
- this . close ( ) ;
894
+ this . close ( `key. ${ e . code . toLowerCase ( ) as 'enter' | 'space' } ` ) ;
895
895
this . focus ( ) ;
896
896
return ;
897
897
}
@@ -966,7 +966,7 @@ export class MultipleSelectInstance {
966
966
const option = findByParam ( this . data , '_key' , selectElm . dataset . key ) ;
967
967
const close = ( ) => {
968
968
if ( this . options . single && this . options . isOpen && ! this . options . keepOpen ) {
969
- this . close ( ) ;
969
+ this . close ( 'selection' ) ;
970
970
}
971
971
} ;
972
972
@@ -1068,7 +1068,7 @@ export class MultipleSelectInstance {
1068
1068
this . focusSelectAllOrList ( ) ;
1069
1069
this . highlightCurrentOption ( ) ;
1070
1070
} else {
1071
- this . close ( ) ;
1071
+ this . close ( 'key.shift+tab' ) ;
1072
1072
this . choiceElm . focus ( ) ;
1073
1073
}
1074
1074
} else {
@@ -1091,7 +1091,7 @@ export class MultipleSelectInstance {
1091
1091
1092
1092
protected handleEscapeKey ( ) {
1093
1093
if ( ! this . options . keepOpen ) {
1094
- this . close ( ) ;
1094
+ this . close ( 'key.escape' ) ;
1095
1095
this . choiceElm . focus ( ) ;
1096
1096
}
1097
1097
}
@@ -1339,7 +1339,7 @@ export class MultipleSelectInstance {
1339
1339
}
1340
1340
}
1341
1341
1342
- close ( ) {
1342
+ close ( reason ?: CloseReason ) {
1343
1343
this . options . isOpen = false ;
1344
1344
this . parentElm . classList . remove ( 'ms-parent-open' ) ;
1345
1345
this . choiceElm ?. querySelector ( 'div.ms-icon-caret' ) ?. classList . remove ( 'open' ) ;
@@ -1351,7 +1351,7 @@ export class MultipleSelectInstance {
1351
1351
this . dropElm . style . top = 'auto' ;
1352
1352
this . dropElm . style . left = 'auto' ;
1353
1353
}
1354
- this . options . onClose ( ) ;
1354
+ this . options . onClose ( reason ) ;
1355
1355
}
1356
1356
1357
1357
/**
0 commit comments