@@ -65,8 +65,12 @@ export class MultipleSelectInstance {
65
65
this . initSelected ( true ) ;
66
66
this . initFilter ( ) ;
67
67
this . initDrop ( ) ;
68
- this . initView ( ) ;
69
- this . options . onAfterCreate ( ) ;
68
+
69
+ // wait a CPU cycle for the select auto-width to return a width which is over 0
70
+ setTimeout ( ( ) => {
71
+ this . initView ( ) ;
72
+ this . options . onAfterCreate ( ) ;
73
+ } ) ;
70
74
}
71
75
72
76
/**
@@ -206,9 +210,9 @@ export class MultipleSelectInstance {
206
210
className : `ms-drop ${ this . options . position } ` ,
207
211
} ) ;
208
212
209
- // add name attribute when defined
213
+ // add data- name attribute when name option is defined
210
214
if ( name ) {
211
- this . dropElm . setAttribute ( ' name' , name ) ;
215
+ this . dropElm . dataset . name = name ;
212
216
}
213
217
214
218
this . closeElm = this . choiceElm . querySelector ( '.icon-close' ) ;
@@ -356,7 +360,7 @@ export class MultipleSelectInstance {
356
360
}
357
361
358
362
let length = 0 ;
359
- for ( const option of this . data ) {
363
+ for ( const option of this . data || [ ] ) {
360
364
if ( option . type === 'optgroup' ) {
361
365
length += ( option as OptGroupRowData ) . children . length ;
362
366
} else {
@@ -382,10 +386,11 @@ export class MultipleSelectInstance {
382
386
}
383
387
384
388
if ( this . options . selectAll && ! this . options . single ) {
389
+ const selectName = this . elm . getAttribute ( 'name' ) || this . options . name || '' ;
385
390
this . selectAllParentElm = createDomElement ( 'div' , { className : 'ms-select-all' } ) ;
386
391
const saLabelElm = createDomElement ( 'label' ) ;
387
392
const saInputElm = createDomElement ( 'input' , { type : 'checkbox' , checked : this . allSelected } ) ;
388
- saInputElm . dataset . name = ' selectAll' ;
393
+ saInputElm . dataset . name = ` selectAll${ selectName } ` ;
389
394
saLabelElm . appendChild ( saInputElm ) ;
390
395
saLabelElm . appendChild ( createDomElement ( 'span' , { textContent : this . formatSelectAll ( ) } ) ) ;
391
396
this . selectAllParentElm . appendChild ( saLabelElm ) ;
@@ -416,9 +421,7 @@ export class MultipleSelectInstance {
416
421
}
417
422
418
423
if ( rows . length > Constants . BLOCK_ROWS * Constants . CLUSTER_BLOCKS ) {
419
- if ( this . virtualScroll ) {
420
- this . virtualScroll . destroy ( ) ;
421
- }
424
+ this . virtualScroll ?. destroy ( ) ;
422
425
423
426
const dropVisible = this . dropElm . style . display !== 'none' ;
424
427
if ( ! dropVisible ) {
@@ -427,13 +430,15 @@ export class MultipleSelectInstance {
427
430
}
428
431
429
432
const updateDataOffset = ( ) => {
430
- this . updateDataStart = this . virtualScroll ! . dataStart + offset ;
431
- this . updateDataEnd = this . virtualScroll ! . dataEnd + offset ;
432
- if ( this . updateDataStart < 0 ) {
433
- this . updateDataStart = 0 ;
434
- }
435
- if ( this . updateDataEnd > this . data . length ) {
436
- this . updateDataEnd = this . data . length ;
433
+ if ( this . virtualScroll ) {
434
+ this . updateDataStart = this . virtualScroll . dataStart + offset ;
435
+ this . updateDataEnd = this . virtualScroll . dataEnd + offset ;
436
+ if ( this . updateDataStart < 0 ) {
437
+ this . updateDataStart = 0 ;
438
+ }
439
+ if ( this . updateDataEnd > this . data . length ) {
440
+ this . updateDataEnd = this . data . length ;
441
+ }
437
442
}
438
443
} ;
439
444
@@ -459,10 +464,10 @@ export class MultipleSelectInstance {
459
464
} else {
460
465
if ( this . ulElm ) {
461
466
this . ulElm . innerHTML = this . options . sanitizer ? this . options . sanitizer ( rows . join ( '' ) ) : rows . join ( '' ) ;
462
- this . updateDataStart = 0 ;
463
- this . updateDataEnd = this . updateData . length ;
464
- this . virtualScroll = null ;
465
467
}
468
+ this . updateDataStart = 0 ;
469
+ this . updateDataEnd = this . updateData . length ;
470
+ this . virtualScroll = null ;
466
471
}
467
472
this . events ( ) ;
468
473
}
@@ -566,7 +571,7 @@ export class MultipleSelectInstance {
566
571
protected initSelected ( ignoreTrigger = false ) {
567
572
let selectedTotal = 0 ;
568
573
569
- for ( const row of this . data ) {
574
+ for ( const row of this . data || [ ] ) {
570
575
if ( row . type === 'optgroup' ) {
571
576
const selectedCount = ( row as OptGroupRowData ) . children . filter ( ( child ) => {
572
577
return child && child . selected && ! child . disabled && child . visible ;
@@ -1031,7 +1036,7 @@ export class MultipleSelectInstance {
1031
1036
// value html, or text, default: 'value'
1032
1037
getSelects ( type = 'value' ) {
1033
1038
const values = [ ] ;
1034
- for ( const row of this . data ) {
1039
+ for ( const row of this . data || [ ] ) {
1035
1040
if ( row . type === 'optgroup' ) {
1036
1041
const selectedChildren = ( row as OptGroupRowData ) . children . filter ( ( child ) => child ?. selected ) ;
1037
1042
if ( ! selectedChildren . length ) {
@@ -1079,7 +1084,7 @@ export class MultipleSelectInstance {
1079
1084
}
1080
1085
} ;
1081
1086
1082
- for ( const row of this . data ) {
1087
+ for ( const row of this . data || [ ] ) {
1083
1088
if ( row . type === 'optgroup' ) {
1084
1089
_setSelects ( ( row as OptGroupRowData ) . children ) ;
1085
1090
} else {
@@ -1137,7 +1142,7 @@ export class MultipleSelectInstance {
1137
1142
}
1138
1143
1139
1144
protected _checkAll ( checked : boolean , ignoreUpdate ?: boolean ) {
1140
- for ( const row of this . data ) {
1145
+ for ( const row of this . data || [ ] ) {
1141
1146
if ( row . type === 'optgroup' ) {
1142
1147
this . _checkGroup ( row , checked , true ) ;
1143
1148
} else if ( ! row . disabled && ! row . divider && ( ignoreUpdate || row . visible ) ) {
@@ -1171,7 +1176,7 @@ export class MultipleSelectInstance {
1171
1176
if ( this . options . single ) {
1172
1177
return ;
1173
1178
}
1174
- for ( const row of this . data ) {
1179
+ for ( const row of this . data || [ ] ) {
1175
1180
if ( row . type === 'optgroup' ) {
1176
1181
for ( const child of ( row as OptGroupRowData ) . children ) {
1177
1182
if ( child ) {
@@ -1215,7 +1220,7 @@ export class MultipleSelectInstance {
1215
1220
}
1216
1221
this . filterText = text ;
1217
1222
1218
- for ( const row of this . data ) {
1223
+ for ( const row of this . data || [ ] ) {
1219
1224
if ( row . type === 'optgroup' ) {
1220
1225
if ( this . options . filterGroup ) {
1221
1226
const rowLabel = `${ row ?. label ?? '' } ` ;
0 commit comments