forked from syncfusion/ej2-javascript-ui-controls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti-select.ts
7141 lines (7069 loc) · 343 KB
/
multi-select.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path='../drop-down-base/drop-down-base-model.d.ts'/>
import { DropDownBase, SelectEventArgs, dropDownBaseClasses, PopupEventArgs, FilteringEventArgs } from '../drop-down-base/drop-down-base';
import { FocusEventArgs, BeforeOpenEventArgs, FilterType, FieldSettings, ResultData } from '../drop-down-base/drop-down-base';
import { FieldSettingsModel } from '../drop-down-base/drop-down-base-model';
import { isCollide, Popup, createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-popups';
import { IInput, FloatLabelType, Input } from '@syncfusion/ej2-inputs';
import { attributes, setValue , getValue } from '@syncfusion/ej2-base';
import { NotifyPropertyChanges, extend } from '@syncfusion/ej2-base';
import { EventHandler, Property, Event, compile, L10n, EmitType, KeyboardEventArgs } from '@syncfusion/ej2-base';
import { Animation, AnimationModel, Browser, prepend, Complex } from '@syncfusion/ej2-base';
import { MultiSelectModel } from '../multi-select';
import { Search } from '../common/incremental-search';
import { append, addClass, removeClass, closest, detach, remove, select, selectAll } from '@syncfusion/ej2-base';
import { getUniqueID, formatUnit, isNullOrUndefined, isUndefined, ModuleDeclaration } from '@syncfusion/ej2-base';
import { DataManager, Query, Predicate, JsonAdaptor, DataOptions } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
import { createFloatLabel, removeFloating, floatLabelFocus, floatLabelBlur, encodePlaceholder } from './float-label';
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RemoveEventArgs extends SelectEventArgs { }
const FOCUS: string = 'e-input-focus';
const DISABLED: string = 'e-disabled';
const OVER_ALL_WRAPPER: string = 'e-multiselect e-input-group e-control-wrapper';
const ELEMENT_WRAPPER: string = 'e-multi-select-wrapper';
const ELEMENT_MOBILE_WRAPPER: string = 'e-mob-wrapper';
const HIDE_LIST: string = 'e-hide-listitem';
const DELIMITER_VIEW: string = 'e-delim-view';
const CHIP_WRAPPER: string = 'e-chips-collection';
const CHIP: string = 'e-chips';
const CHIP_CONTENT: string = 'e-chipcontent';
const CHIP_CLOSE: string = 'e-chips-close';
const CHIP_SELECTED: string = 'e-chip-selected';
const SEARCHBOX_WRAPPER: string = 'e-searcher';
const DELIMITER_VIEW_WRAPPER: string = 'e-delimiter';
const ZERO_SIZE: string = 'e-zero-size';
const REMAIN_WRAPPER: string = 'e-remain';
const CLOSEICON_CLASS: string = 'e-chips-close e-close-hooker';
const DELIMITER_WRAPPER: string = 'e-delim-values';
const POPUP_WRAPPER: string = 'e-ddl e-popup e-multi-select-list-wrapper';
const INPUT_ELEMENT: string = 'e-dropdownbase';
const RTL_CLASS: string = 'e-rtl';
const CLOSE_ICON_HIDE: string = 'e-close-icon-hide';
const MOBILE_CHIP: string = 'e-mob-chip';
const FOOTER: string = 'e-ddl-footer';
const HEADER: string = 'e-ddl-header';
const DISABLE_ICON: string = 'e-ddl-disable-icon';
const SPINNER_CLASS: string = 'e-ms-spinner-icon';
const HIDDEN_ELEMENT: string = 'e-multi-hidden';
const destroy: string = 'destroy';
const dropdownIcon: string = 'e-input-group-icon e-ddl-icon';
const iconAnimation: string = 'e-icon-anim';
const TOTAL_COUNT_WRAPPER: string = 'e-delim-total';
const BOX_ELEMENT: string = 'e-multiselect-box';
const FILTERPARENT: string = 'e-filter-parent';
const CUSTOM_WIDTH: string = 'e-search-custom-width';
const FILTERINPUT: string = 'e-input-filter';
const RESIZE_ICON: string = 'e-resizer-right e-icons';
/**
* The Multiselect allows the user to pick a more than one value from list of predefined values.
* ```html
* <select id="list">
* <option value='1'>Badminton</option>
* <option value='2'>Basketball</option>
* <option value='3'>Cricket</option>
* <option value='4'>Football</option>
* <option value='5'>Tennis</option>
* </select>
* ```
* ```typescript
* <script>
* var multiselectObj = new Multiselect();
* multiselectObj.appendTo("#list");
* </script>
* ```
*/
@NotifyPropertyChanges
export class MultiSelect extends DropDownBase implements IInput {
private spinnerElement: HTMLElement;
private selectAllAction: Function;
private setInitialValue: Function;
private setDynValue: boolean;
private listCurrentOptions: { [key: string]: Object };
private targetInputElement: HTMLInputElement | string;
private selectAllHeight?: number;
private searchBoxHeight?: number;
private mobFilter?: boolean;
private isFiltered: boolean;
private isFirstClick: boolean;
private focused: boolean;
private initial: boolean;
private backCommand: boolean;
private keyAction: boolean;
private isSelectAll: boolean;
private clearIconWidth: number = 0;
private previousFilterText: string = '';
private selectedElementID: string;
private focusFirstListItem: boolean;
private currentFocuedListElement: HTMLElement;
private isCustomRendered: boolean;
private isRemoteSelection: boolean;
private isSelectAllTarget: boolean;
private isClearAllItem: boolean;
private previousFocusItem: HTMLElement;
private isRemoveSelection: boolean;
private resizer: HTMLElement;
private storedSelectAllHeight: number = 0;
private isResizing: boolean;
private originalHeight: number;
private originalWidth: number;
private originalMouseX: number;
private originalMouseY: number;
private resizeHeight: number;
private resizeWidth: number;
private currentRemoveValue: string | number | boolean;
private selectedListData: { [key: string]: Object }[] | string[] | boolean[] | number[];
private isClearAllAction: boolean;
private isUpdateHeaderHeight: boolean = false;
private isUpdateFooterHeight: boolean = false;
private isBlurDispatching: boolean = false;
private isFilterPrevented: boolean = false;
/**
* The `fields` property maps the columns of the data table and binds the data to the component.
* * text - Maps the text column from data table for each list item.
* * value - Maps the value column from data table for each list item.
* * iconCss - Maps the icon class column from data table for each list item.
* * groupBy - Group the list items with it's related items by mapping groupBy field.
* ```html
* <input type="text" tabindex="1" id="list"> </input>
* ```
* ```typescript
* let customers: MultiSelect = new MultiSelect({
* dataSource:new DataManager({ url:'http://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/' }),
* query: new Query().from('Customers').select(['ContactName', 'CustomerID']).take(5),
* fields: { text: 'ContactName', value: 'CustomerID' },
* placeholder: 'Select a customer'
* });
* customers.appendTo("#list");
* ```
*
* @default {text: null, value: null, iconCss: null, groupBy: null}
*/
@Complex<FieldSettingsModel>({ text: null, value: null, iconCss: null, groupBy: null, disabled: null }, FieldSettings)
public fields: FieldSettingsModel;
/**
* Enable or disable persisting MultiSelect component's state between page reloads.
* If enabled, following list of states will be persisted.
* 1. value
*
* @default false
*/
@Property(false)
public enablePersistence: boolean;
/**
* Accepts the template design and assigns it to the group headers present in the MultiSelect popup list.
*
* @default null
* @aspType string
*/
@Property(null)
public groupTemplate: string | Function;
/**
* Accepts the template design and assigns it to popup list of MultiSelect component
* when no data is available on the component.
*
* @default 'No records found'
* @aspType string
*/
@Property('No records found')
public noRecordsTemplate: string | Function;
/**
* Accepts the template and assigns it to the popup list content of the MultiSelect component
* when the data fetch request from the remote server fails.
*
* @default 'Request failed'
* @aspType string
*/
@Property('Request failed')
public actionFailureTemplate: string | Function;
/**
* Specifies the `sortOrder` to sort the data source. The available type of sort orders are
* * `None` - The data source is not sorting.
* * `Ascending` - The data source is sorting with ascending order.
* * `Descending` - The data source is sorting with descending order.
*
* @default null
* @asptype object
* @aspjsonconverterignore
*/
@Property<SortOrder>('None')
public sortOrder: SortOrder;
/**
* Specifies a value that indicates whether the MultiSelect component is enabled or not.
*
* @default true
*/
@Property(true)
public enabled: boolean;
/**
* Defines whether to allow the cross-scripting site or not.
*
* @default true
*/
@Property(true)
public enableHtmlSanitizer: boolean;
/**
* Defines whether to enable virtual scrolling in the component.
*
* @default false
*/
@Property(false)
public enableVirtualization: boolean;
/**
* Accepts the list items either through local or remote service and binds it to the MultiSelect component.
* It can be an array of JSON Objects or an instance of
* `DataManager`.
*
* @default []
*/
@Property([])
public dataSource: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[];
/**
* Accepts the external `Query`
* which will execute along with the data processing in MultiSelect.
*
* @default null
*/
@Property(null)
public query: Query;
/**
* Determines on which filter type, the MultiSelect component needs to be considered on search action.
* The `FilterType` and its supported data types are
*
* <table>
* <tr>
* <td colSpan=1 rowSpan=1>
* FilterType<br/></td><td colSpan=1 rowSpan=1>
* Description<br/></td><td colSpan=1 rowSpan=1>
* Supported Types<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* StartsWith<br/></td><td colSpan=1 rowSpan=1>
* Checks whether a value begins with the specified value.<br/></td><td colSpan=1 rowSpan=1>
* String<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* EndsWith<br/></td><td colSpan=1 rowSpan=1>
* Checks whether a value ends with specified value.<br/><br/></td><td colSpan=1 rowSpan=1>
* <br/>String<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* Contains<br/></td><td colSpan=1 rowSpan=1>
* Checks whether a value contains with specified value.<br/><br/></td><td colSpan=1 rowSpan=1>
* <br/>String<br/></td></tr>
* </table>
*
* The default value set to `StartsWith`, all the suggestion items which contain typed characters to listed in the suggestion popup.
*
* @default 'StartsWith'
*/
@Property('StartsWith')
public filterType: FilterType;
/**
* specifies the z-index value of the component popup element.
*
* @default 1000
*/
@Property(1000)
public zIndex: number;
/**
* ignoreAccent set to true, then ignores the diacritic characters or accents when filtering.
*/
@Property(false)
public ignoreAccent: boolean;
/**
* Overrides the global culture and localization value for this component. Default global culture is 'en-US'.
*
* @default 'en-US'
*/
@Property()
public locale: string;
/**
* Specifies a Boolean value that indicates the whether the grouped list items are
* allowed to check by checking the group header in checkbox mode.
* By default, there is no checkbox provided for group headers.
* This property allows you to render checkbox for group headers and to select
* all the grouped items at once
*
* @default false
*/
@Property(false)
public enableGroupCheckBox: boolean;
/**
* Sets the CSS classes to root element of this component which helps to customize the
* complete styles.
*
* @default null
*/
@Property(null)
public cssClass: string;
/**
* Gets or sets the width of the component. By default, it sizes based on its parent.
* container dimension.
*
* @default '100%'
* @aspType string
*/
@Property('100%')
public width: string | number;
/**
* Gets or sets the height of the popup list. By default it renders based on its list item.
* > For more details about the popup configuration refer to
* [`Popup Configuration`](../../multi-select/getting-started/#configure-the-popup-list) documentation.
*
* @default '300px'
* @aspType string
*/
@Property('300px')
public popupHeight: string | number;
/**
* Gets or sets the width of the popup list and percentage values has calculated based on input width.
* > For more details about the popup configuration refer to
* [`Popup Configuration`](../../multi-select/getting-started/#configure-the-popup-list) documentation.
*
* @default '100%'
* @aspType string
*/
@Property('100%')
public popupWidth: string | number;
/**
* Gets or sets the placeholder in the component to display the given information
* in input when no item selected.
*
* @default null
*/
@Property(null)
public placeholder: string;
/**
* Accepts the value to be displayed as a watermark text on the filter bar.
*
* @default null
*/
@Property(null)
public filterBarPlaceholder: string;
/**
* Gets or sets the additional attribute to `HtmlAttributes` property in MultiSelect,
* which helps to add attribute like title, name etc, input should be key value pair.
*
* {% codeBlock src='multiselect/htmlAttributes/index.md' %}{% endcodeBlock %}
*
* @default {}
*/
@Property({})
public htmlAttributes: { [key: string]: string };
/**
* Accepts the template design and assigns it to the selected list item in the input element of the component.
* For more details about the available template options refer to
* [`Template`](../../multi-select/templates) documentation.
*
* We have built-in `template engine`
* which provides options to compile template string into a executable function.
* For EX: We have expression evolution as like ES6 expression string literals.
*
* @default null
* @aspType string
*/
@Property(null)
public valueTemplate: string | Function;
/**
* Accepts the template design and assigns it to the header container of the popup list.
* > For more details about the available template options refer to [`Template`](../../multi-select/templates) documentation.
*
* @default null
* @aspType string
*/
@Property(null)
public headerTemplate: string | Function;
/**
* Accepts the template design and assigns it to the footer container of the popup list.
* > For more details about the available template options refer to [`Template`](../../multi-select/templates) documentation.
*
* @default null
* @aspType string
*/
@Property(null)
public footerTemplate: string | Function;
/**
* Accepts the template design and assigns it to each list item present in the popup.
* > For more details about the available template options refer to [`Template`](../../multi-select/templates) documentation.
*
* We have built-in `template engine`
* which provides options to compile template string into a executable function.
* For EX: We have expression evolution as like ES6 expression string literals.
*
* @default null
* @aspType string
*/
@Property(null)
public itemTemplate: string | Function;
/**
* To enable the filtering option in this component.
* Filter action performs when type in search box and collect the matched item through `filtering` event.
* If searching character does not match, `noRecordsTemplate` property value will be shown.
*
* {% codeBlock src="multiselect/allow-filtering-api/index.ts" %}{% endcodeBlock %}
*
* {% codeBlock src="multiselect/allow-filtering-api/index.html" %}{% endcodeBlock %}
*
* @default null
*/
@Property(null)
public allowFiltering: boolean;
/**
* Defines whether the popup opens in fullscreen mode on mobile devices when filtering is enabled. When set to false, the popup will display similarly on both mobile and desktop devices.
*
* @default true
*/
@Property(true)
public isDeviceFullScreen: boolean;
/**
* By default, the multiselect component fires the change event while focus out the component.
* If you want to fires the change event on every value selection and remove, then disable the changeOnBlur property.
*
* @default true
*/
@Property(true)
public changeOnBlur: boolean;
/**
* Allows user to add a
* [`custom value`](../../multi-select/custom-value), the value which is not present in the suggestion list.
*
* @default false
*/
@Property(false)
public allowCustomValue: boolean;
/**
* Enables close icon with the each selected item.
*
* @default true
*/
@Property(true)
public showClearButton: boolean;
/**
* Sets limitation to the value selection.
* based on the limitation, list selection will be prevented.
*
* @default 1000
*/
@Property(1000)
public maximumSelectionLength: number;
/**
* Gets or sets the `readonly` to input or not. Once enabled, just you can copy or highlight
* the text however tab key action will perform.
*
* @default false
*/
@Property(false)
public readonly: boolean;
/**
* Gets or sets a value that indicates whether the Multiselect popup can be resized.
* When set to `true`, a resize handle appears in the bottom-right corner of the popup,
* allowing the user to resize the width and height of the popup.
*
* @default false
*/
@Property(false)
public allowResize: boolean;
/**
* Selects the list item which maps the data `text` field in the component.
*
* @default null
* @aspType string
*/
@Property(null)
public text: string | null;
/**
* Selects the list item which maps the data `value` field in the component.
* {% codeBlock src='multiselect/value/index.md' %}{% endcodeBlock %}
*
* @default null
* @isGenericType true
*/
@Property(null)
public value: number[] | string[] | boolean[] | object[] | null ;
/**
* Defines whether the object binding is allowed or not in the component.
*
* @default false
*/
@Property(false)
public allowObjectBinding: boolean;
/**
* Hides the selected item from the list item.
*
* @default true
*/
@Property(true)
public hideSelectedItem: boolean;
/**
* Based on the property, when item get select popup visibility state will changed.
*
* @default true
*/
@Property(true)
public closePopupOnSelect: boolean;
/**
* configures visibility mode for component interaction.
*
* - `Box` - selected items will be visualized in chip.
*
* - `Delimiter` - selected items will be visualized in text content.
*
* - `Default` - on `focus in` component will act in `box` mode.
* on `blur` component will act in `delimiter` mode.
*
* - `CheckBox` - The 'checkbox' will be visualized in list item.
*
* {% codeBlock src="multiselect/visual-mode-api/index.ts" %}{% endcodeBlock %}
*
* {% codeBlock src="multiselect/visual-mode-api/index.html" %}{% endcodeBlock %}
*
* @default Default
*/
@Property('Default')
public mode: visualMode;
/**
* Sets the delimiter character for 'default' and 'delimiter' visibility modes.
*
* @default ','
*/
@Property(',')
public delimiterChar: string;
/**
* Sets [`case sensitive`](../../multi-select/filtering/#case-sensitive-filtering)
* option for filter operation.
*
* @default true
*/
@Property(true)
public ignoreCase: boolean;
/**
* Allows you to either show or hide the DropDown button on the component
*
* @default false
*/
@Property(false)
public showDropDownIcon: boolean;
/**
* Specifies whether to display the floating label above the input element.
* Possible values are:
* * Never: The label will never float in the input when the placeholder is available.
* * Always: The floating label will always float above the input.
* * Auto: The floating label will float above the input after focusing or entering a value in the input.
*
* @default Syncfusion.EJ2.Inputs.FloatLabelType.Never
* @aspType Syncfusion.EJ2.Inputs.FloatLabelType
* @isEnumeration true
*/
@Property('Never')
public floatLabelType: FloatLabelType;
/**
* Allows you to either show or hide the selectAll option on the component.
*
* @default false
*/
@Property(false)
public showSelectAll: boolean;
/**
* Specifies the selectAllText to be displayed on the component.
*
* @default 'select All'
*/
@Property('Select All')
public selectAllText: string;
/**
* Specifies the UnSelectAllText to be displayed on the component.
*
* @default 'select All'
*/
@Property('Unselect All')
public unSelectAllText: string;
/**
* Reorder the selected items in popup visibility state.
*
* @default true
*/
@Property(true)
public enableSelectionOrder: boolean;
/**
* Whether to automatically open the popup when the control is clicked.
*
* @default true
*/
@Property(true)
public openOnClick: boolean;
/**
* By default, the typed value is converting into chip or update as value of the component when you press the enter key or select from the popup.
* If you want to convert the typed value into chip or update as value of the component while focusing out the component, then enable this property.
* If custom value is enabled, both custom value and value present in the list are converted into tag while focusing out the component; Otherwise, value present in the list is converted into tag while focusing out the component.
*
* @default false
*/
@Property(false)
public addTagOnBlur: boolean;
/**
* Fires each time when selection changes happened in list items after model and input value get affected.
*
* @event change
*/
@Event()
public change: EmitType<MultiSelectChangeEventArgs>;
/**
* Fires before the selected item removed from the widget.
*
* @event removing
*/
@Event()
public removing: EmitType<RemoveEventArgs>;
/**
* Fires after the selected item removed from the widget.
*
* @event removed
*/
@Event()
public removed: EmitType<RemoveEventArgs>;
/**
* Fires before select all process.
*
* @event beforeSelectAll
* @blazorProperty 'beforeSelectAll'
*/
@Event()
public beforeSelectAll: EmitType<ISelectAllEventArgs>;
/**
* Fires after select all process completion.
*
* @event selectedAll
*/
@Event()
public selectedAll: EmitType<ISelectAllEventArgs>;
/**
* Fires when popup opens before animation.
*
* @event beforeOpen
*/
@Event()
public beforeOpen: EmitType<Object>;
/**
* Fires when popup opens after animation completion.
*
* @event open
*/
@Event()
public open: EmitType<PopupEventArgs>;
/**
* Fires when popup close after animation completion.
*
* @event close
*/
@Event()
public close: EmitType<PopupEventArgs>;
/**
* Event triggers when the input get focus-out.
*
* @event blur
*/
@Event()
public blur: EmitType<Object>;
/**
* Event triggers when the input get focused.
*
* @event focus
*/
@Event()
public focus: EmitType<Object>;
/**
* Event triggers when the chip selection.
*
* @event chipSelection
*/
@Event()
public chipSelection: EmitType<Object>;
/**
* Triggers when the user finishes resizing the Multiselect popup.
*
* @event resizeStop
*/
@Event()
public resizeStop: EmitType<Object>;
/**
* Triggers continuously while the Multiselect popup is being resized by the user.
* This event provides live updates on the width and height of the popup.
*
* @event resizing
*/
@Event()
public resizing: EmitType<Object>;
/**
* Triggers when the user starts resizing the Multiselect popup.
*
* @event resizeStart
*/
@Event()
public resizeStart: EmitType<Object>;
/**
* Triggers event,when user types a text in search box.
* > For more details about filtering, refer to [`Filtering`](../../multi-select/filtering) documentation.
*
* @event filtering
*/
@Event()
public filtering: EmitType<FilteringEventArgs>;
/**
* Fires before set the selected item as chip in the component.
* > For more details about chip customization refer [`Chip Customization`](../../multi-select/chip-customization)
*
* @event tagging
*/
@Event()
public tagging: EmitType<TaggingEventArgs>;
/**
* Triggers when the [`customValue`](../../multi-select/custom-value) is selected.
*
* @event customValueSelection
*/
@Event()
public customValueSelection: EmitType<CustomValueEventArgs>;
/**
* Constructor for creating the DropDownList widget.
*
* @param {MultiSelectModel} option - Specifies the MultiSelect model.
* @param {string | HTMLElement} element - Specifies the element to render as component.
* @private
*/
public constructor(option?: MultiSelectModel, element?: string | HTMLElement) {
super(option, element);
}
private isValidKey: boolean = false;
private mainList: HTMLElement;
public ulElement: HTMLElement;
private mainData: { [key: string]: Object }[] | string[] | number[] | boolean[];
protected virtualCustomSelectData: { [key: string]: Object }[];
private mainListCollection: HTMLElement[];
private customValueFlag: boolean;
private inputElement: HTMLInputElement;
private componentWrapper: HTMLDivElement;
private overAllWrapper: HTMLDivElement;
private searchWrapper: HTMLElement;
private viewWrapper: HTMLElement;
private chipCollectionWrapper: HTMLElement;
private overAllClear: HTMLElement;
private dropIcon: HTMLElement;
private hiddenElement: HTMLSelectElement;
private delimiterWrapper: HTMLElement;
private popupObj: Popup;
private inputFocus: boolean;
private header: HTMLElement;
private footer: HTMLElement;
private initStatus: boolean;
private isInitRemoteVirtualData: boolean;
private isDynamicRemoteVirtualData: boolean;
private popupWrapper: HTMLDivElement;
private keyCode: number;
private beforePopupOpen: boolean;
private remoteCustomValue: boolean;
private filterAction: boolean;
private remoteFilterAction: boolean;
private selectAllEventData: FieldSettingsModel[] = [];
private selectAllEventEle: HTMLLIElement[] = [];
private filterParent: HTMLElement;
private removeIndex: number;
private preventSetCurrentData: boolean = false;
private virtualCustomData: { [key: string]: string | Object };
private isSelectAllLoop: boolean = false;
private enableRTL(state: boolean): void {
if (state) {
this.overAllWrapper.classList.add(RTL_CLASS);
} else {
this.overAllWrapper.classList.remove(RTL_CLASS);
}
if (this.popupObj) {
this.popupObj.enableRtl = state;
this.popupObj.dataBind();
}
}
public requiredModules(): ModuleDeclaration[] {
const modules: ModuleDeclaration[] = [];
if (this.enableVirtualization) {
modules.push({ args: [this], member: 'VirtualScroll' });
}
if (this.mode === 'CheckBox') {
this.isGroupChecking = this.enableGroupCheckBox;
if (this.enableGroupCheckBox) {
const prevOnChange: boolean = this.isProtectedOnChange;
this.isProtectedOnChange = true;
this.enableSelectionOrder = false;
this.isProtectedOnChange = prevOnChange;
}
this.allowCustomValue = false;
this.hideSelectedItem = false;
this.closePopupOnSelect = false;
modules.push({
member: 'CheckBoxSelection',
args: [this]
});
}
return modules;
}
private updateHTMLAttribute(): void {
if (Object.keys(this.htmlAttributes).length) {
for (const htmlAttr of Object.keys(this.htmlAttributes)) {
switch (htmlAttr) {
case 'class': {
const updatedClassValue : string = (this.htmlAttributes[`${htmlAttr}`].replace(/\s+/g, ' ')).trim();
if (updatedClassValue !== '') {
addClass([this.overAllWrapper], updatedClassValue.split(' '));
addClass([this.popupWrapper], updatedClassValue.split(' '));
}
break;
}
case 'disabled':
this.enable(false);
break;
case 'placeholder':
if (!this.placeholder) {
this.inputElement.setAttribute(htmlAttr, this.htmlAttributes[`${htmlAttr}`]);
this.setProperties({placeholder: this.inputElement.placeholder}, true);
this.refreshPlaceHolder();
}
break;
default: {
const defaultAttr: string[] = ['id'];
const validateAttr: string[] = ['name', 'required', 'aria-required', 'form'];
const containerAttr: string[] = ['title', 'role', 'style', 'class'];
if (defaultAttr.indexOf(htmlAttr) > -1) {
this.element.setAttribute(htmlAttr, this.htmlAttributes[`${htmlAttr}`]);
} else if (htmlAttr.indexOf('data') === 0 || validateAttr.indexOf(htmlAttr) > -1) {
this.hiddenElement.setAttribute(htmlAttr, this.htmlAttributes[`${htmlAttr}`]);
} else if (containerAttr.indexOf(htmlAttr) > -1) {
this.overAllWrapper.setAttribute(htmlAttr, this.htmlAttributes[`${htmlAttr}`]);
} else if (htmlAttr !== 'size' && !isNullOrUndefined(this.inputElement)) {
this.inputElement.setAttribute(htmlAttr, this.htmlAttributes[`${htmlAttr}`]);
}
break;
}
}
}
}
}
private updateReadonly(state: boolean): void {
if (!isNullOrUndefined(this.inputElement)) {
if (state || this.mode === 'CheckBox') {
this.inputElement.setAttribute('readonly', 'true');
} else {
this.inputElement.removeAttribute('readonly');
}
}
}
private updateClearButton(state: boolean): void {
if (state) {
if (this.overAllClear.parentNode) {
this.overAllClear.style.display = '';
} else {
this.componentWrapper.appendChild(this.overAllClear);
}
this.componentWrapper.classList.remove(CLOSE_ICON_HIDE);
} else {
this.overAllClear.style.display = 'none';
this.componentWrapper.classList.add(CLOSE_ICON_HIDE);
}
}
private updateCssClass(): void {
if (!isNullOrUndefined(this.cssClass) && this.cssClass !== '') {
let updatedCssClassValues : string = this.cssClass;
updatedCssClassValues = (this.cssClass.replace(/\s+/g, ' ')).trim();
if (updatedCssClassValues !== '') {
addClass([this.overAllWrapper], updatedCssClassValues.split(' '));
addClass([this.popupWrapper], updatedCssClassValues.split(' '));
}
}
}
private updateOldPropCssClass(oldClass : string) : void {
if (!isNullOrUndefined(oldClass) && oldClass !== '') {
oldClass = (oldClass.replace(/\s+/g, ' ')).trim();
if (oldClass !== '' ) {
removeClass([this.overAllWrapper], oldClass.split(' '));
removeClass([this.popupWrapper], oldClass.split(' '));
}
}
}
private onPopupShown(e?: MouseEvent | KeyboardEventArgs | TouchEvent | Object): void {
if (Browser.isDevice && (this.mode === 'CheckBox' && this.allowFiltering)) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const proxy: this = this;
window.onpopstate = () => {
proxy.hidePopup();
proxy.inputElement.focus();
};
history.pushState({}, '');
}
const animModel: AnimationModel = { name: 'FadeIn', duration: 100 };
const eventArgs: PopupEventArgs = { popup: this.popupObj, event: e, cancel: false, animation: animModel };
this.trigger('open', eventArgs, (eventArgs: PopupEventArgs) => {
if (!eventArgs.cancel) {
this.focusAtFirstListItem(true);
if (this.popupObj){
document.body.appendChild(this.popupObj.element);
}
if (this.mode === 'CheckBox' && this.enableGroupCheckBox && !isNullOrUndefined(this.fields.groupBy)) {
this.updateListItems(this.list.querySelectorAll('li.e-list-item'), this.mainList.querySelectorAll('li.e-list-item'));
}
if (this.mode === 'CheckBox' || this.showDropDownIcon) {
addClass([this.overAllWrapper], [iconAnimation]);
}
this.refreshPopup();
this.renderReactTemplates();
if (this.popupObj){
this.popupObj.show(eventArgs.animation, (this.zIndex === 1000) ? this.element : null);
}
if (this.isReact) {
setTimeout(() => {
if (this.popupHeight && this.list && this.popupHeight !== 'auto') {
const popupHeightValue: number = typeof this.popupHeight === 'string' ? parseInt(this.popupHeight, 10) : this.popupHeight;
if (!this.isUpdateHeaderHeight && this.headerTemplate && this.header) {
const listHeight: number = this.list.style.maxHeight === '' ? popupHeightValue : parseInt(this.list.style.maxHeight as string, 10);
this.list.style.maxHeight = (listHeight - this.header.offsetHeight).toString() + 'px';
this.isUpdateHeaderHeight = true;
}
if (!this.isUpdateFooterHeight && this.footerTemplate && this.footer) {
const listHeight: number = this.list.style.maxHeight === '' ? popupHeightValue : parseInt(this.list.style.maxHeight as string, 10);
this.list.style.maxHeight = (listHeight - this.footer.offsetHeight).toString() + 'px';
this.isUpdateFooterHeight = true;
}
}
}, 15);
}
attributes(this.inputElement, {
'aria-expanded': 'true', 'aria-owns':
this.element.id + '_popup', 'aria-controls': this.element.id
});
this.updateAriaActiveDescendant();
if (this.isFirstClick) {
if (!this.enableVirtualization) {
this.loadTemplate();
}
}
if (this.mode === 'CheckBox' && this.showSelectAll){
EventHandler.add((this as any).popupObj.element, 'click', this.clickHandler, this);
}
}
});
}
private updateVirtualReOrderList(isCheckBoxUpdate?: boolean): void {
const query: Query = this.getForQuery(this.value, true).clone();
if (this.enableVirtualization && this.dataSource instanceof DataManager) {
this.resetList(this.selectedListData, this.fields, query);
} else {
this.resetList(this.dataSource, this.fields, query);
}
this.UpdateSkeleton();
this.liCollections = <HTMLElement[] & NodeListOf<Element>>this.list.querySelectorAll('.' + dropDownBaseClasses.li);
this.virtualItemCount = this.itemCount;
if (this.mode !== 'CheckBox') {
this.totalItemCount = this.value && this.value.length ? this.totalItemCount - this.value.length : this.totalItemCount;
}
if (!this.list.querySelector('.e-virtual-ddl')) {
const virualElement: any = this.createElement('div', {
id: this.element.id + '_popup', className: 'e-virtual-ddl', styles: this.GetVirtualTrackHeight()
});
this.popupWrapper.querySelector('.e-dropdownbase').appendChild(virualElement);
}
else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(this.list.getElementsByClassName('e-virtual-ddl')[0] as any).style = this.GetVirtualTrackHeight();
}
if (this.list.querySelector('.e-virtual-ddl-content')) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(this.list.getElementsByClassName('e-virtual-ddl-content')[0] as any).style = this.getTransformValues();
}
if (isCheckBoxUpdate){
this.loadTemplate();
}
}
private updateListItems(listItems: NodeListOf<Element> , mainListItems: NodeListOf<Element>): void {
for (let i: number = 0; i < listItems.length; i++) {
this.findGroupStart(listItems[i as number] as HTMLElement);
this.findGroupStart(mainListItems[i as number] as HTMLElement);
}
this.deselectHeader();