forked from syncfusion/ej2-javascript-ui-controls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrop-down-list.ts
4849 lines (4704 loc) · 232 KB
/
drop-down-list.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 { EventHandler, Property, Event, compile, EmitType, KeyboardEvents, append, select, ModuleDeclaration } from '@syncfusion/ej2-base';
import { attributes, isNullOrUndefined, getUniqueID, formatUnit, isUndefined, getValue } from '@syncfusion/ej2-base';
import { Animation, AnimationModel, Browser, KeyboardEventArgs, NotifyPropertyChanges } from '@syncfusion/ej2-base';
import { addClass, removeClass, closest, prepend, detach, classList } from '@syncfusion/ej2-base';
import { Popup, isCollide, createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-popups';
import { IInput, Input, InputObject, FloatLabelType } from '@syncfusion/ej2-inputs';
import { incrementalSearch, resetIncrementalSearchValues } from '../common/incremental-search';
import { DropDownBase, dropDownBaseClasses, SelectEventArgs, FilteringEventArgs, PopupEventArgs } from '../drop-down-base/drop-down-base';
import { FocusEventArgs, ResultData, BeforeOpenEventArgs } from '../drop-down-base/drop-down-base';
import { FieldSettingsModel } from '../drop-down-base/drop-down-base-model';
import { DropDownListModel } from '../drop-down-list';
import { DataManager, Query, Predicate, DataOptions } from '@syncfusion/ej2-data';
import {Offsets, SentinelType} from '../common/virtual-scroll';
export interface ChangeEventArgs extends SelectEventArgs {
/**
* Returns the selected value
*
* @isGenericType true
*/
value: number | string | boolean | object
/**
* Returns the previous selected list item
*/
previousItem: HTMLLIElement
/**
* Returns the previous selected item as JSON Object from the data source.
*
*/
previousItemData: FieldSettingsModel
/**
* Returns the root element of the component.
*/
element: HTMLElement
/**
* Specifies the original event arguments.
*/
event: MouseEvent | KeyboardEvent | TouchEvent
}
export interface GeneratedData {
[key: string]: Object
}
// don't use space in classnames
export const dropDownListClasses: DropDownListClassList = {
root: 'e-dropdownlist',
hover: dropDownBaseClasses.hover,
selected: dropDownBaseClasses.selected,
rtl: dropDownBaseClasses.rtl,
li: dropDownBaseClasses.li,
disable: dropDownBaseClasses.disabled,
base: dropDownBaseClasses.root,
focus: dropDownBaseClasses.focus,
content: dropDownBaseClasses.content,
input: 'e-input-group',
inputFocus: 'e-input-focus',
icon: 'e-input-group-icon e-ddl-icon',
iconAnimation: 'e-icon-anim',
value: 'e-input-value',
device: 'e-ddl-device',
backIcon: 'e-input-group-icon e-back-icon e-icons',
filterBarClearIcon: 'e-input-group-icon e-clear-icon e-icons',
filterInput: 'e-input-filter',
resizeIcon: 'e-resizer-right e-icons',
filterParent: 'e-filter-parent',
mobileFilter: 'e-ddl-device-filter',
footer: 'e-ddl-footer',
header: 'e-ddl-header',
clearIcon: 'e-clear-icon',
clearIconHide: 'e-clear-icon-hide',
popupFullScreen: 'e-popup-full-page',
disableIcon: 'e-ddl-disable-icon',
hiddenElement: 'e-ddl-hidden',
virtualList: 'e-list-item e-virtual-list'
};
const inputObject: InputObject = {
container: null,
buttons: []
};
/**
* The DropDownList component contains a list of predefined values from which you can
* choose a single value.
* ```html
* <input type="text" tabindex="1" id="list"> </input>
* ```
* ```typescript
* let dropDownListObj:DropDownList = new DropDownList();
* dropDownListObj.appendTo("#list");
* ```
*/
@NotifyPropertyChanges
export class DropDownList extends DropDownBase implements IInput {
protected inputWrapper: InputObject;
protected inputElement: HTMLInputElement;
private valueTempElement: HTMLSpanElement;
private listObject: HTMLElement;
private header: HTMLElement;
private footer: HTMLElement;
protected selectedLI: HTMLElement;
protected previousSelectedLI: HTMLElement;
protected previousItemData: { [key: string]: Object } | string | number | boolean;
protected hiddenElement: HTMLSelectElement;
protected isPopupOpen: boolean;
private isDocumentClick: boolean;
protected isInteracted: boolean;
private isFilterFocus: boolean;
protected beforePopupOpen: boolean;
protected initial: boolean;
private searchBoxHeight: number;
private popupObj: Popup;
private backIconElement: Element;
private clearIconElement: Element;
private containerStyle: ClientRect;
protected previousValue: string | number | boolean | object;
protected activeIndex: number;
protected filterInput: HTMLInputElement;
private searchKeyModule: KeyboardEvents;
private tabIndex: string;
private isNotSearchList: boolean;
protected isTyped: boolean;
protected isSelected: boolean;
protected preventFocus: boolean;
protected preventAutoFill: boolean;
protected queryString: string;
protected isValidKey: boolean;
protected typedString: string;
protected isEscapeKey: boolean;
private isPreventBlur: boolean;
protected isTabKey: boolean;
private actionCompleteData: ActionCompleteData;
private actionData: ActionCompleteData;
protected prevSelectPoints: { [key: string]: number };
protected isSelectCustom: boolean;
protected isDropDownClick: boolean;
protected preventAltUp: boolean;
private searchKeyEvent: KeyboardEventArgs;
private filterInputObj: InputObject;
protected spinnerElement: HTMLElement;
protected keyConfigure: { [key: string]: string };
protected isCustomFilter: boolean;
private isSecondClick: boolean;
protected isListSearched: boolean = false;
protected preventChange: boolean = false;
protected selectedElementID: string;
private preselectedIndex: number;
private isTouched: boolean = false;
protected isFocused: boolean = false;
private clearButton: HTMLElement;
protected autoFill: boolean = false;
private resizer: HTMLElement;
private isResizing: boolean;
private originalHeight: number;
private originalWidth: number;
private originalMouseX: number;
private originalMouseY: number;
private resizeHeight: number;
private resizeWidth: number;
private isUpdateHeaderHeight: boolean = false;
private isUpdateFooterHeight: boolean = false;
private filterArgs: KeyboardEventArgs;
private isReactTemplateUpdate: boolean = false;
/**
* Sets CSS classes to the root element of the component that allows customization of appearance.
*
* @default null
*/
@Property(null)
public cssClass: string;
/**
* Specifies the width of the component. By default, the component width sets based on the width of
* its parent container. You can also set the width in pixel values.
*
* @default '100%'
* @aspType string
*/
@Property('100%')
public width: string | number;
/**
* Specifies a value that indicates whether the component is enabled or not.
*
* @default true
* @deprecated
*/
@Property(true)
public enabled: boolean;
/**
* Enable or disable persisting component's state between page reloads.
* If enabled, following list of states will be persisted.
* 1. value
*
* @default false
* @deprecated
*/
@Property(false)
public enablePersistence: boolean;
/**
* Specifies the height of the popup list.
* > For more details about the popup configuration refer to
* [`Popup Configuration`](../../drop-down-list/getting-started#configure-the-popup-list) documentation.
*
* @default '300px'
* @aspType string
*/
@Property('300px')
public popupHeight: string | number;
/**
* Specifies the width of the popup list. By default, the popup width sets based on the width of
* the component.
* > For more details about the popup configuration refer to
* [`Popup Configuration`](../../drop-down-list/getting-started#configure-the-popup-list) documentation.
*
* @default '100%'
* @aspType string
*/
@Property('100%')
public popupWidth: string | number;
/**
* Specifies a short hint that describes the expected value of the DropDownList component.
*
* @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;
/**
* Allows additional HTML attributes such as title, name, etc., and
* accepts n number of attributes in a key-value pair format.
*
* {% codeBlock src='dropdownlist/htmlAttributes/index.md' %}{% endcodeBlock %}
*
* @default {}
*/
@Property({})
public htmlAttributes: { [key: string]: string };
/**
* Accepts the external `Query`
* that execute along with data processing.
*
* {% codeBlock src='dropdownlist/query/index.md' %}{% endcodeBlock %}
*
* @default null
* @deprecated
*/
@Property(null)
public query: Query;
/**
* 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`](../../drop-down-list/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`](../../drop-down-list/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`](../../drop-down-list/templates) documentation.
*
* @default null
* @aspType string
*/
@Property(null)
public footerTemplate: string | Function;
/**
* When allowFiltering is set to true, show the filter bar (search box) of the component.
* The filter action retrieves matched items through the `filtering` event based on
* the characters typed in the search TextBox.
*
* If no match is found, the value of the `noRecordsTemplate` property will be displayed.
* > For more details about the filtering refer to [`Filtering`](../../drop-down-list/filtering) documentation.
*
* {% codeBlock src="dropdownlist/allow-filtering-api/index.ts" %}{% endcodeBlock %}
*
* {% codeBlock src="dropdownlist/allow-filtering-api/index.html" %}{% endcodeBlock %}
*
* @default false
*/
@Property(false)
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;
/**
* When set to true, the user interactions on the component are disabled.
*
* @default false
*/
@Property(false)
public readonly: boolean;
/**
* Defines whether to enable virtual scrolling in the component.
*
* @default false
*/
@Property(false)
public enableVirtualization: boolean;
/**
* Gets or sets a value that indicates whether the DropDownList 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;
/**
* Gets or sets the display text of the selected item in the component.
*
* @default null
* @aspType string
*/
@Property(null)
public text: string | null;
/**
* Gets or sets the value of the selected item in the component.
*
* @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;
/**
* Gets or sets the index of the selected item in the component.
*
* {% codeBlock src="dropdownlist/index-api/index.ts" %}{% endcodeBlock %}
*
* {% codeBlock src="dropdownlist/index-api/index.html" %}{% endcodeBlock %}
*
* @default null
* @aspType double
*/
@Property(null)
public index: number | null;
/**
* 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.
*
* {% codeBlock src="dropdownlist/float-label-type-api/index.ts" %}{% endcodeBlock %}
*
* {% codeBlock src="dropdownlist/float-label-type-api/index.html" %}{% endcodeBlock %}
*
* @default Syncfusion.EJ2.Inputs.FloatLabelType.Never
* @aspType Syncfusion.EJ2.Inputs.FloatLabelType
* @isEnumeration true
*/
@Property('Never')
public floatLabelType: FloatLabelType;
/**
* Specifies whether to show or hide the clear button.
* When the clear button is clicked, `value`, `text`, and `index` properties are reset to null.
*
* @default false
*/
@Property(false)
public showClearButton: boolean;
/**
* Triggers on typing a character in the filter bar when the
* [`allowFiltering`](./#allowfiltering)
* is enabled.
* > For more details about the filtering refer to [`Filtering`](../../drop-down-list/filtering) documentation.
*
* @event filtering
*/
@Event()
public filtering: EmitType<FilteringEventArgs>;
/**
* Triggers when an item in a popup is selected or when the model value is changed by user.
* Use change event to
* [`Configure the Cascading DropDownList`](../../drop-down-list/how-to/cascading)
*
* @event change
*/
@Event()
public change: EmitType<ChangeEventArgs>;
/**
* Triggers when the popup before opens.
*
* @event beforeOpen
*/
@Event()
public beforeOpen: EmitType<Object>;
/**
* Triggers when the popup opens.
*
* @event open
*/
@Event()
public open: EmitType<PopupEventArgs>;
/**
* Triggers when the popup is closed.
*
* @event close
*/
@Event()
public close: EmitType<PopupEventArgs>;
/**
* Triggers when focus moves out from the component.
*
* @event blur
*/
@Event()
public blur: EmitType<Object>;
/**
* Triggers when the component is focused.
*
* @event focus
*/
@Event()
public focus: EmitType<Object>;
/**
* Triggers when the user finishes resizing the DropDown popup.
*
* @event resizeStop
*/
@Event()
public resizeStop: EmitType<Object>;
/**
* Triggers continuously while the DropDown 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 DropDown popup.
*
* @event resizeStart
*/
@Event()
public resizeStart: EmitType<Object>;
/**
* * Constructor for creating the DropDownList component.
*
* @param {DropDownListModel} options - Specifies the DropDownList model.
* @param {string | HTMLElement} element - Specifies the element to render as component.
* @private
*/
public constructor(options?: DropDownListModel, element?: string | HTMLElement) {
super(options, element);
}
/**
* Initialize the event handler.
*
* @private
* @returns {void}
*/
protected preRender(): void {
this.valueTempElement = null;
this.element.style.opacity = '0';
this.initializeData();
super.preRender();
this.activeIndex = this.index;
this.queryString = '';
}
private initializeData(): void {
this.isPopupOpen = false;
this.isDocumentClick = false;
this.isInteracted = false;
this.isFilterFocus = false;
this.beforePopupOpen = false;
this.initial = true;
this.initialRemoteRender = false;
this.isNotSearchList = false;
this.isTyped = false;
this.isSelected = false;
this.preventFocus = false;
this.preventAutoFill = false;
this.isValidKey = false;
this.typedString = '';
this.isEscapeKey = false;
this.isPreventBlur = false;
this.isTabKey = false;
this.actionCompleteData = { isUpdated: false };
this.actionData = { isUpdated: false };
this.prevSelectPoints = {};
this.isSelectCustom = false;
this.isDropDownClick = false;
this.preventAltUp = false;
this.isCustomFilter = false;
this.isSecondClick = false;
this.previousValue = null;
this.keyConfigure = {
tab: 'tab',
enter: '13',
escape: '27',
end: '35',
home: '36',
down: '40',
up: '38',
pageUp: '33',
pageDown: '34',
open: 'alt+40',
close: 'shift+tab',
hide: 'alt+38',
space: '32'
};
this.viewPortInfo = {
currentPageNumber: null,
direction: null,
sentinelInfo: {},
offsets: {},
startIndex: 0,
endIndex: this.itemCount
};
}
protected setZIndex(): void {
if (this.popupObj) {
this.popupObj.setProperties({ 'zIndex': this.zIndex });
}
}
public requiredModules(): ModuleDeclaration[] {
const modules: ModuleDeclaration[] = [];
if (this.enableVirtualization) {
modules.push({ args: [this], member: 'VirtualScroll' });
}
return modules;
}
protected renderList(e?: MouseEvent | KeyboardEventArgs | TouchEvent, isEmptyData?: boolean): void {
super.render(e, isEmptyData);
if (!(this.dataSource instanceof DataManager)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.totalItemCount = this.dataSource && (this.dataSource as any).length ? (this.dataSource as any).length : 0;
}
if (this.enableVirtualization && this.isFiltering() && this.getModuleName() === 'combobox'){
this.UpdateSkeleton();
this.liCollections = <HTMLElement[] & NodeListOf<Element>>this.list.querySelectorAll('.' + dropDownBaseClasses.li);
this.ulElement = this.list.querySelector('ul');
}
this.unWireListEvents();
this.wireListEvents();
}
private floatLabelChange(): void {
if (this.getModuleName() === 'dropdownlist' && this.floatLabelType === 'Auto') {
const floatElement: HTMLElement = <HTMLElement>this.inputWrapper.container.querySelector('.e-float-text');
if (this.inputElement.value !== '' || this.isInteracted) {
classList(floatElement, ['e-label-top'], ['e-label-bottom']);
} else {
classList(floatElement, ['e-label-bottom'], ['e-label-top']);
}
}
}
protected resetHandler(e: MouseEvent): void {
e.preventDefault();
this.clearAll(e);
if (this.enableVirtualization) {
this.list.scrollTop = 0;
this.virtualListInfo = null;
this.previousStartIndex = 0;
this.previousEndIndex = 0;
}
}
protected resetFocusElement(): void {
this.removeHover();
this.removeSelection();
this.removeFocus();
this.list.scrollTop = 0;
if (this.getModuleName() !== 'autocomplete' && !isNullOrUndefined(this.ulElement)) {
let li: Element = this.fields.disabled ? this.ulElement.querySelector('.' + dropDownListClasses.li + ':not(.e-disabled)') : this.ulElement.querySelector('.' + dropDownListClasses.li);
if (this.enableVirtualization){
li = this.liCollections[this.skeletonCount];
}
if (li) {
li.classList.add(dropDownListClasses.focus);
}
}
}
protected clearAll(e?: MouseEvent | KeyboardEventArgs | TouchEvent, properties?: DropDownListModel): void {
this.previousItemData = (!isNullOrUndefined(this.itemData)) ? this.itemData : null;
if (isNullOrUndefined(properties) || (!isNullOrUndefined(properties) &&
(isNullOrUndefined(properties.dataSource) ||
(!(properties.dataSource instanceof DataManager) && properties.dataSource.length === 0)))) {
this.isActive = true;
this.resetSelection(properties);
}
const dataItem: { [key: string]: string } = this.getItemData();
if ((!this.allowObjectBinding && (this.previousValue === dataItem.value)) ||
(this.allowObjectBinding && this.previousValue &&
this.isObjectInArray(this.previousValue, [(this as any).allowCustom ? this.value ? this.value : dataItem :
dataItem.value ? this.getDataByValue(dataItem.value) : dataItem]))) {
this.checkAndResetCache();
if (this.enableVirtualization && this.list) {
this.updateInitialData();
}
return;
}
this.onChangeEvent(e);
this.checkAndResetCache();
if (this.enableVirtualization) {
this.updateInitialData();
}
}
private resetSelection(properties?: DropDownListModel): void {
if (this.list) {
if ((!isNullOrUndefined(properties) &&
(isNullOrUndefined(properties.dataSource) ||
(!(properties.dataSource instanceof DataManager) && properties.dataSource.length === 0)))) {
this.selectedLI = null;
this.actionCompleteData.isUpdated = false;
this.actionCompleteData.ulElement = null;
this.actionCompleteData.list = null;
this.resetList(properties.dataSource);
} else {
if (this.allowFiltering && this.getModuleName() !== 'autocomplete'
&& !isNullOrUndefined(this.actionCompleteData.ulElement) && !isNullOrUndefined(this.actionCompleteData.list) &&
this.actionCompleteData.list.length > 0) {
this.onActionComplete(this.actionCompleteData.ulElement.cloneNode(true) as HTMLElement, this.actionCompleteData.list);
}
this.resetFocusElement();
}
}
if (!isNullOrUndefined(this.hiddenElement)) {
this.hiddenElement.innerHTML = '';
}
if (!isNullOrUndefined(this.inputElement)) {
this.inputElement.value = '';
}
this.value = null;
this.itemData = null;
this.text = null;
this.index = null;
this.activeIndex = null;
this.item = null;
this.queryString = '';
if (this.valueTempElement) {
detach(this.valueTempElement);
this.inputElement.style.display = 'block';
this.valueTempElement = null;
}
this.setSelection(null, null);
this.isSelectCustom = false;
this.updateIconState();
this.cloneElements();
}
private setHTMLAttributes(): void {
if (Object.keys(this.htmlAttributes).length) {
for (const htmlAttr of Object.keys(this.htmlAttributes)) {
if (htmlAttr === 'class') {
const updatedClassValue: string = (this.htmlAttributes[`${htmlAttr}`].replace(/\s+/g, ' ')).trim();
if (updatedClassValue !== '') {
addClass([this.inputWrapper.container], updatedClassValue.split(' '));
}
} else if (htmlAttr === 'disabled' && this.htmlAttributes[`${htmlAttr}`] === 'disabled') {
this.enabled = false;
this.setEnable();
} else if (htmlAttr === 'readonly' && !isNullOrUndefined(this.htmlAttributes[`${htmlAttr}`])) {
this.readonly = true;
this.dataBind();
} else if (htmlAttr === 'style') {
this.inputWrapper.container.setAttribute('style', this.htmlAttributes[`${htmlAttr}`]);
} else if (htmlAttr === 'aria-label') {
if ((this.getModuleName() === 'autocomplete' || this.getModuleName() === 'combobox') && !this.readonly) {
this.inputElement.setAttribute('aria-label', this.htmlAttributes[`${htmlAttr}`]);
}
else if (this.getModuleName() === 'dropdownlist') {
this.inputWrapper.container.setAttribute('aria-label', this.htmlAttributes[`${htmlAttr}`]);
}
} else {
const defaultAttr: string[] = ['title', 'id', 'placeholder',
'role', 'autocomplete', 'autocapitalize', 'spellcheck', 'minlength', 'maxlength'];
const validateAttr: string[] = ['name', 'required'];
if (this.getModuleName() === 'autocomplete' || this.getModuleName() === 'combobox') {
defaultAttr.push('tabindex');
}
if (validateAttr.indexOf(htmlAttr) > -1 || htmlAttr.indexOf('data') === 0) {
this.hiddenElement.setAttribute(htmlAttr, this.htmlAttributes[`${htmlAttr}`]);
} else if (defaultAttr.indexOf(htmlAttr) > -1) {
if (htmlAttr === 'placeholder') {
Input.setPlaceholder(this.htmlAttributes[`${htmlAttr}`], this.inputElement);
} else {
this.inputElement.setAttribute(htmlAttr, this.htmlAttributes[`${htmlAttr}`]);
}
} else {
this.inputWrapper.container.setAttribute(htmlAttr, this.htmlAttributes[`${htmlAttr}`]);
}
}
}
}
if (this.getModuleName() === 'autocomplete' || this.getModuleName() === 'combobox') {
this.inputWrapper.container.removeAttribute('tabindex');
}
}
protected getAriaAttributes(): { [key: string]: string } {
return {
'aria-disabled': 'false',
'role': 'combobox',
'aria-expanded': 'false',
'aria-live': 'polite',
'aria-labelledby': this.hiddenElement.id
};
}
protected setEnableRtl(): void {
if (!isNullOrUndefined(this.inputElement) && !isNullOrUndefined(this.inputElement.parentElement)) {
Input.setEnableRtl(this.enableRtl, [this.inputElement.parentElement]);
}
if (this.popupObj) {
this.popupObj.enableRtl = this.enableRtl;
this.popupObj.dataBind();
}
}
private setEnable(): void {
Input.setEnabled(this.enabled, this.inputElement);
if (this.enabled) {
removeClass([this.inputWrapper.container], dropDownListClasses.disable);
this.inputElement.setAttribute('aria-disabled', 'false');
this.targetElement().setAttribute('tabindex', this.tabIndex);
if (this.inputWrapper && this.inputWrapper.container) {
this.inputWrapper.container.setAttribute('aria-disabled', 'false');
this.inputWrapper.container.removeAttribute('disabled');
}
} else {
this.hidePopup();
addClass([this.inputWrapper.container], dropDownListClasses.disable);
this.inputElement.setAttribute('aria-disabled', 'true');
this.targetElement().tabIndex = -1;
if (this.inputWrapper && this.inputWrapper.container) {
this.inputWrapper.container.setAttribute('aria-disabled', 'true');
this.inputWrapper.container.setAttribute('disabled', '');
}
}
}
/**
* Get the properties to be maintained in the persisted state.
*
* @returns {string} Returns the persisted data of the component.
*/
protected getPersistData(): string {
return this.addOnPersist(['value']);
}
protected getLocaleName(): string {
return 'drop-down-list';
}
private preventTabIndex(element: HTMLElement): void {
if (this.getModuleName() === 'dropdownlist') {
element.tabIndex = -1;
}
}
protected targetElement(): HTMLElement | HTMLInputElement {
return !isNullOrUndefined(this.inputWrapper) ? this.inputWrapper.container : null;
}
protected getNgDirective(): string {
return 'EJS-DROPDOWNLIST';
}
protected getElementByText(text: string): Element {
return this.getElementByValue(this.getValueByText(text));
}
protected getElementByValue(value: string | number | boolean | object): Element {
let item: Element;
const listItems: Element[] = this.getItems();
for (const liItem of listItems) {
if (this.getFormattedValue(liItem.getAttribute('data-value')) === value) {
item = liItem;
break;
}
}
return item;
}
private initValue(): void {
this.viewPortInfo.startIndex = this.virtualItemStartIndex = 0;
this.viewPortInfo.endIndex = this.virtualItemEndIndex = this.itemCount;
this.renderList();
if (this.dataSource instanceof DataManager) {
this.initialRemoteRender = true;
} else {
this.updateValues();
}
}
/**
* Checks if the given value is disabled.
*
* @param { string | number | boolean | object } value - The value to check for disablement. Can be a string, number, boolean, or object.
* @returns { boolean } A boolean indicating whether the value is disabled.
*/
protected isDisableItemValue(value: string | number | boolean | object) : boolean {
if (typeof(value) === 'object') {
const objectValue: string | number | boolean = JSON.parse(JSON.stringify(value))[this.fields.value];
return this.isDisabledItemByIndex(this.getIndexByValue(objectValue));
}
return this.isDisabledItemByIndex(this.getIndexByValue(value));
}
protected updateValues(): void {
if (this.fields.disabled) {
if (this.value != null) {
this.value = !this.isDisableItemValue(this.value) ? this.value : null;
}
if (this.text != null) {
this.text = !this.isDisabledItemByIndex(this.getIndexByValue(this.getValueByText(this.text))) ? this.text : null;
}
if (this.index != null) {
this.index = !this.isDisabledItemByIndex(this.index) ? this.index : null;
this.activeIndex = this.index;
}
}
this.selectedValueInfo = this.viewPortInfo;
if (!isNullOrUndefined(this.value)) {
const value: string | number | boolean = this.allowObjectBinding && !isNullOrUndefined(this.value) ? getValue(((this.fields.value) ? this.fields.value : ''), this.value) : this.value;
this.setSelection(this.getElementByValue(value), null);
} else if (this.text && isNullOrUndefined(this.value)) {
const element: Element = this.getElementByText(this.text);
if (isNullOrUndefined(element)) {
this.setProperties({ text: null });
return;
} else {
this.setSelection(element, null);
}
} else {
this.setSelection(this.liCollections[this.activeIndex], null);
}
this.setHiddenValue();
Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
}
protected onBlurHandler(e: MouseEvent): void {
if (!this.enabled) {
return;
}
const target: HTMLElement = <HTMLElement>e.relatedTarget;
const currentTarget: HTMLElement = <HTMLElement>e.target;
const isPreventBlur: boolean = this.isPreventBlur;
this.isPreventBlur = false;
//IE 11 - issue
if (isPreventBlur && !this.isDocumentClick && this.isPopupOpen && (!isNullOrUndefined(currentTarget) ||
!this.isFilterLayout() && isNullOrUndefined(target))) {
if (this.getModuleName() === 'dropdownlist' && this.allowFiltering && this.isPopupOpen) {
this.filterInput.focus();
} else {
this.targetElement().focus();
}
return;
}
if (this.isDocumentClick || (!isNullOrUndefined(this.popupObj)
&& document.body.contains(this.popupObj.element) &&
this.popupObj.element.classList.contains(dropDownListClasses.mobileFilter))) {
if (!this.beforePopupOpen) {
this.isDocumentClick = false;
}
return;
}
if (((this.getModuleName() === 'dropdownlist' && !this.isFilterFocus && target !== this.inputElement)
&& (document.activeElement !== target || (document.activeElement === target &&
currentTarget.classList.contains(dropDownListClasses.inputFocus)))) ||
(isNullOrUndefined(target) && this.getModuleName() === 'dropdownlist' && this.allowFiltering &&
currentTarget !== this.inputWrapper.container) || this.getModuleName() !== 'dropdownlist' &&
!this.inputWrapper.container.contains(target) || this.isTabKey) {
this.isDocumentClick = this.isPopupOpen ? true : false;
this.focusOutAction(e);
this.isTabKey = false;
}
if (this.isRequested && !this.isPopupOpen && !this.isPreventBlur) {
this.isActive = false;
this.beforePopupOpen = false;
}
this.isFocused = false;
}
protected focusOutAction(e?: MouseEvent | KeyboardEventArgs): void {
this.isInteracted = false;
this.focusOut(e);
this.onFocusOut(e);
}
protected onFocusOut(e?: MouseEvent | KeyboardEventArgs): void {
if (!this.enabled) {
return;
}
if (this.isSelected) {
this.isSelectCustom = false;
this.onChangeEvent(e);
}
this.floatLabelChange();
this.dispatchEvent(this.hiddenElement as HTMLElement, 'change');
if (this.getModuleName() === 'dropdownlist' && this.element.tagName !== 'INPUT') {
this.dispatchEvent(this.inputElement as HTMLElement, 'blur');
}
if (this.inputWrapper.clearButton) {
addClass([this.inputWrapper.clearButton], dropDownListClasses.clearIconHide);
}
this.trigger('blur');
}
protected onFocus(e?: FocusEvent | MouseEvent | KeyboardEvent | TouchEvent): void {
if (!this.isInteracted) {
this.isInteracted = true;
const args: FocusEventArgs = { isInteracted: e ? true : false, event: e };
this.trigger('focus', args);
}
this.updateIconState();
this.isFocused = true;
}
protected resizingWireEvent(): void {
// Mouse events
EventHandler.add(document, 'mousemove', this.resizePopup, this);
EventHandler.add(document, 'mouseup', this.stopResizing, this);
// Touch events
EventHandler.add(document, 'touchmove', this.resizePopup, this);
EventHandler.add(document, 'touchend', this.stopResizing, this);
}
protected resizingUnWireEvent(): void {
// Mouse events
EventHandler.remove(document, 'mousemove', this.resizePopup);
EventHandler.remove(document, 'mouseup', this.stopResizing);
// Touch events
EventHandler.remove(document, 'touchmove', this.resizePopup);
EventHandler.remove(document, 'touchend', this.stopResizing);
}
private resetValueHandler(e: Event): void {
const formElement: HTMLFormElement = closest(this.inputElement, 'form') as HTMLFormElement;
if (formElement && e.target === formElement) {
const val: string = (this.element.tagName === this.getNgDirective()) ? null : this.inputElement.getAttribute('value');
this.text = val;
}
}
protected wireEvent(): void {
EventHandler.add(this.inputWrapper.container, 'mousedown', this.dropDownClick, this);
EventHandler.add(this.inputWrapper.container, 'focus', this.focusIn, this);
EventHandler.add(this.inputWrapper.container, 'keypress', this.onSearch, this);
EventHandler.add(<HTMLElement & Window><unknown>window, 'resize', this.windowResize, this);
this.bindCommonEvent();
}
protected bindCommonEvent(): void {
EventHandler.add(this.targetElement(), 'blur', this.onBlurHandler, this);
const formElement: HTMLFormElement = closest(this.inputElement, 'form') as HTMLFormElement;
if (formElement) {
EventHandler.add(formElement, 'reset', this.resetValueHandler, this);
}
if (!Browser.isDevice) {
this.keyboardModule = new KeyboardEvents(
this.targetElement(), {
keyAction: this.keyActionHandler.bind(this), keyConfigs: this.keyConfigure, eventName: 'keydown'
});