UNPKG

457 kBJavaScriptView Raw
1import { Animation, Browser, ChildProperty, Complex, Component, Event, EventHandler, KeyboardEvents, L10n, NotifyPropertyChanges, Property, addClass, append, attributes, classList, closest, compile, createElement, detach, extend, formatUnit, getComponent, getUniqueID, getValue, isBlazor, isNullOrUndefined, isUndefined, prepend, remove, removeClass, resetBlazorTemplate, rippleEffect, select, setStyleAttribute, setValue, updateBlazorTemplate } from '@syncfusion/ej2-base';
2import { DataManager, DataUtil, Predicate, Query } from '@syncfusion/ej2-data';
3import { ListBase, Sortable, cssClass, moveTo } from '@syncfusion/ej2-lists';
4import { Popup, createSpinner, hideSpinner, isCollide, showSpinner } from '@syncfusion/ej2-popups';
5import { Input } from '@syncfusion/ej2-inputs';
6import { Button, createCheckBox } from '@syncfusion/ej2-buttons';
7
8/**
9 * IncrementalSearch module file
10 */
11let queryString = '';
12let prevString = '';
13let matches = [];
14let activeClass = 'e-active';
15/**
16 * Search and focus the list item based on key code matches with list text content
17 * @param { number } keyCode - Specifies the key code which pressed on keyboard events.
18 * @param { HTMLElement[]] } items - Specifies an array of HTMLElement, from which matches find has done.
19 * @param { number } selectedIndex - Specifies the selected item in list item, so that search will happen
20 * after selected item otherwise it will do from initial.
21 * @param { boolean } ignoreCase - Specifies the case consideration when search has done.
22 */
23function incrementalSearch(keyCode, items, selectedIndex, ignoreCase, isBlazor$$1) {
24 queryString += String.fromCharCode(keyCode);
25 setTimeout(() => { queryString = ''; }, 1000);
26 let index;
27 queryString = ignoreCase ? queryString.toLowerCase() : queryString;
28 if (prevString === queryString) {
29 for (let i = 0; i < matches.length; i++) {
30 if (matches[i].classList.contains(activeClass)) {
31 index = i;
32 break;
33 }
34 }
35 index = index + 1;
36 return matches[index];
37 }
38 else {
39 let listItems = items;
40 let strLength = queryString.length;
41 let text;
42 let item;
43 selectedIndex = selectedIndex ? selectedIndex + 1 : 0;
44 let i = selectedIndex;
45 matches = [];
46 do {
47 if (i === listItems.length) {
48 i = -1;
49 }
50 i === -1 ? index = 0 : index = i;
51 item = listItems[index];
52 if (isBlazor$$1) {
53 text = ignoreCase ? item.textContent.trim().toLowerCase() : item.textContent.trim();
54 }
55 else {
56 text = ignoreCase ? item.innerText.toLowerCase() : item.innerText;
57 }
58 if (text.substr(0, strLength) === queryString) {
59 matches.push(listItems[index]);
60 }
61 i++;
62 } while (i !== selectedIndex);
63 prevString = queryString;
64 return matches[0];
65 }
66}
67function Search(inputVal, items, searchType, ignoreCase) {
68 let listItems = items;
69 ignoreCase = ignoreCase !== undefined && ignoreCase !== null ? ignoreCase : true;
70 let itemData = { item: null, index: null };
71 if (inputVal && inputVal.length) {
72 let strLength = inputVal.length;
73 let queryStr = ignoreCase ? inputVal.toLocaleLowerCase() : inputVal;
74 for (let i = 0, itemsData = listItems; i < itemsData.length; i++) {
75 let item = itemsData[i];
76 let text = (ignoreCase ? item.textContent.toLocaleLowerCase() : item.textContent).replace(/^\s+|\s+$/g, '');
77 if ((searchType === 'Equal' && text === queryStr) || (searchType === 'StartsWith' && text.substr(0, strLength) === queryStr)) {
78 itemData.item = item;
79 itemData.index = i;
80 return { item: item, index: i };
81 }
82 }
83 return itemData;
84 }
85 return itemData;
86}
87
88/**
89 * Function helps to find which highlightSearch is to call based on your data.
90 * @param {HTMLElement} element - Specifies an li element.
91 * @param {string} query - Specifies the string to be highlighted.
92 * @param {boolean} ignoreCase - Specifies the ignoreCase option.
93 * @param {HightLightType} type - Specifies the type of highlight.
94 */
95function highlightSearch(element, query, ignoreCase, type) {
96 if (query === '') {
97 return;
98 }
99 else {
100 let ignoreRegex = ignoreCase ? 'gim' : 'gm';
101 query = /^[a-zA-Z0-9- ]*$/.test(query) ? query : query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
102 let replaceQuery = type === 'StartsWith' ? '^(' + query + ')' : type === 'EndsWith' ? '(' + query + ')$' : '(' + query + ')';
103 findTextNode(element, new RegExp(replaceQuery, ignoreRegex));
104 }
105}
106function findTextNode(element, pattern) {
107 for (let index = 0; element.childNodes && (index < element.childNodes.length); index++) {
108 if (element.childNodes[index].nodeType === 3) {
109 element.innerHTML = element.innerHTML.replace(pattern, '<span class="e-highlight">$1</span>');
110 break;
111 }
112 else {
113 findTextNode(element.childNodes[index], pattern);
114 }
115 }
116}
117/**
118 * Function helps to remove highlighted element based on your data.
119 * @param {HTMLElement} content - Specifies an content element.
120 */
121function revertHighlightSearch(content) {
122 let contentElement = content.querySelectorAll('.e-highlight');
123 for (let i = contentElement.length - 1; i >= 0; i--) {
124 let parent = contentElement[i].parentNode;
125 let text = document.createTextNode(contentElement[i].textContent);
126 parent.replaceChild(text, contentElement[i]);
127 }
128}
129
130/**
131 * Common source
132 */
133
134var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
135 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
136 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
137 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
138 return c > 3 && r && Object.defineProperty(target, key, r), r;
139};
140class FieldSettings extends ChildProperty {
141}
142__decorate([
143 Property()
144], FieldSettings.prototype, "text", void 0);
145__decorate([
146 Property()
147], FieldSettings.prototype, "value", void 0);
148__decorate([
149 Property()
150], FieldSettings.prototype, "iconCss", void 0);
151__decorate([
152 Property()
153], FieldSettings.prototype, "groupBy", void 0);
154__decorate([
155 Property()
156], FieldSettings.prototype, "htmlAttributes", void 0);
157const dropDownBaseClasses = {
158 root: 'e-dropdownbase',
159 rtl: 'e-rtl',
160 content: 'e-content',
161 selected: 'e-active',
162 hover: 'e-hover',
163 noData: 'e-nodata',
164 fixedHead: 'e-fixed-head',
165 focus: 'e-item-focus',
166 li: cssClass.li,
167 group: cssClass.group,
168 disabled: cssClass.disabled,
169 grouping: 'e-dd-group'
170};
171const ITEMTEMPLATE_PROPERTY = 'ItemTemplate';
172const VALUETEMPLATE_PROPERTY = 'ValueTemplate';
173const GROUPTEMPLATE_PROPERTY = 'GroupTemplate';
174const HEADERTEMPLATE_PROPERTY = 'HeaderTemplate';
175const FOOTERTEMPLATE_PROPERTY = 'FooterTemplate';
176const NORECORDSTEMPLATE_PROPERTY = 'NoRecordsTemplate';
177const ACTIONFAILURETEMPLATE_PROPERTY = 'ActionFailureTemplate';
178/**
179 * DropDownBase component will generate the list items based on given data and act as base class to drop-down related components
180 */
181let DropDownBase = class DropDownBase extends Component {
182 /**
183 * * Constructor for DropDownBase class
184 */
185 constructor(options, element) {
186 super(options, element);
187 }
188 ;
189 getPropObject(prop, newProp, oldProp) {
190 let newProperty = new Object();
191 let oldProperty = new Object();
192 // tslint:disable-next-line:no-function-constructor-with-string-args
193 let propName = (prop) => {
194 return prop;
195 };
196 newProperty[propName(prop)] = newProp[propName(prop)];
197 oldProperty[propName(prop)] = oldProp[propName(prop)];
198 let data = new Object();
199 data.newProperty = newProperty;
200 data.oldProperty = oldProperty;
201 return data;
202 }
203 getValueByText(text, ignoreCase, ignoreAccent) {
204 let value = null;
205 if (!isNullOrUndefined(this.listData)) {
206 if (ignoreCase) {
207 value = this.checkValueCase(text, true, ignoreAccent);
208 }
209 else {
210 value = this.checkValueCase(text, false, ignoreAccent);
211 }
212 }
213 return value;
214 }
215 ;
216 checkValueCase(text, ignoreCase, ignoreAccent, isTextByValue) {
217 let value = null;
218 if (isTextByValue) {
219 value = text;
220 }
221 let dataSource = this.listData;
222 let fields = this.fields;
223 let type = this.typeOfData(dataSource).typeof;
224 if (type === 'string' || type === 'number' || type === 'boolean') {
225 for (let item of dataSource) {
226 if (!isNullOrUndefined(item)) {
227 if (ignoreAccent) {
228 value = this.checkingAccent(String(item), text, ignoreCase);
229 }
230 else {
231 if (ignoreCase) {
232 if (this.checkIgnoreCase(String(item), text)) {
233 value = this.getItemValue(String(item), text, ignoreCase);
234 }
235 }
236 else {
237 if (this.checkNonIgnoreCase(String(item), text)) {
238 value = this.getItemValue(String(item), text, ignoreCase, isTextByValue);
239 }
240 }
241 }
242 }
243 }
244 }
245 else {
246 if (ignoreCase) {
247 dataSource.filter((item) => {
248 let itemValue = getValue(fields.value, item);
249 if (!isNullOrUndefined(itemValue) && this.checkIgnoreCase(getValue(fields.text, item).toString(), text)) {
250 value = getValue(fields.value, item);
251 }
252 });
253 }
254 else {
255 if (isTextByValue) {
256 dataSource.filter((item) => {
257 let itemValue = getValue(fields.value, item);
258 if (!isNullOrUndefined(itemValue) && !isNullOrUndefined(value) && itemValue.toString() === value.toString()) {
259 value = getValue(fields.text, item);
260 }
261 });
262 }
263 else {
264 dataSource.filter((item) => {
265 if (this.checkNonIgnoreCase(getValue(fields.text, item), text)) {
266 value = getValue(fields.value, item);
267 }
268 });
269 }
270 }
271 }
272 return value;
273 }
274 checkingAccent(item, text, ignoreCase) {
275 let dataItem = DataUtil.ignoreDiacritics(String(item));
276 let textItem = DataUtil.ignoreDiacritics(text.toString());
277 let value = null;
278 if (ignoreCase) {
279 if (this.checkIgnoreCase(dataItem, textItem)) {
280 value = this.getItemValue(String(item), text, ignoreCase);
281 }
282 }
283 else {
284 if (this.checkNonIgnoreCase(String(item), text)) {
285 value = this.getItemValue(String(item), text, ignoreCase);
286 }
287 }
288 return value;
289 }
290 checkIgnoreCase(item, text) {
291 return String(item).toLowerCase() === text.toString().toLowerCase() ? true : false;
292 }
293 checkNonIgnoreCase(item, text) {
294 return String(item) === text.toString() ? true : false;
295 }
296 getItemValue(dataItem, typedText, ignoreCase, isTextByValue) {
297 let value = null;
298 let dataSource = this.listData;
299 let type = this.typeOfData(dataSource).typeof;
300 if (isTextByValue) {
301 value = dataItem.toString();
302 }
303 else {
304 if (ignoreCase) {
305 value = type === 'string' ? String(dataItem) : this.getFormattedValue(String(dataItem));
306 }
307 else {
308 value = type === 'string' ? typedText : this.getFormattedValue(typedText);
309 }
310 }
311 return value;
312 }
313 l10nUpdate(actionFailure) {
314 let ele = this.getModuleName() === 'listbox' ? this.ulElement : this.list;
315 if (this.noRecordsTemplate !== 'No Records Found' || this.actionFailureTemplate !== 'The Request Failed') {
316 this.DropDownBaseresetBlazorTemplates(false, false, true, true);
317 let template = actionFailure ? this.actionFailureTemplate : this.noRecordsTemplate;
318 let compiledString;
319 let templateId = actionFailure ? this.actionFailureTemplateId : this.noRecordsTemplateId;
320 ele.innerHTML = '';
321 compiledString = compile(template);
322 for (let item of compiledString({}, null, null, templateId, this.isStringTemplate)) {
323 ele.appendChild(item);
324 }
325 this.DropDownBaseupdateBlazorTemplates(false, false, !actionFailure, actionFailure, false, false, false, false);
326 }
327 else {
328 let l10nLocale = { noRecordsTemplate: 'No Records Found', actionFailureTemplate: 'The Request Failed' };
329 let componentLocale = new L10n(this.getLocaleName(), {}, this.locale);
330 if (componentLocale.getConstant('actionFailureTemplate') !== '') {
331 this.l10n = componentLocale;
332 }
333 else {
334 this.l10n = new L10n(this.getModuleName() === 'listbox' ? 'listbox' : 'dropdowns', l10nLocale, this.locale);
335 }
336 ele.innerHTML = actionFailure ?
337 this.l10n.getConstant('actionFailureTemplate') : this.l10n.getConstant('noRecordsTemplate');
338 }
339 }
340 getLocaleName() {
341 return 'drop-down-base';
342 }
343 ;
344 getTextByValue(value) {
345 let text;
346 text = this.checkValueCase(value, false, false, true);
347 return text;
348 }
349 getFormattedValue(value) {
350 if (this.listData && this.listData.length) {
351 let item = this.typeOfData(this.listData);
352 if (isBlazor() && isNullOrUndefined(value) || value === 'null') {
353 return null;
354 }
355 if (typeof getValue((this.fields.value ? this.fields.value : 'value'), item.item) === 'number'
356 || item.typeof === 'number') {
357 return parseFloat(value);
358 }
359 if (typeof getValue((this.fields.value ? this.fields.value : 'value'), item.item) === 'boolean'
360 || item.typeof === 'boolean') {
361 return (value === 'true');
362 }
363 }
364 return value;
365 }
366 /**
367 * Sets RTL to dropdownbase wrapper
368 */
369 setEnableRtl() {
370 if (this.list) {
371 this.enableRtlElements.push(this.list);
372 }
373 this.enableRtl ? addClass(this.enableRtlElements, dropDownBaseClasses.rtl) :
374 removeClass(this.enableRtlElements, dropDownBaseClasses.rtl);
375 }
376 ;
377 /**
378 * Initialize the Component.
379 */
380 initialize() {
381 this.bindEvent = true;
382 this.actionFailureTemplateId = `${this.element.id}${ACTIONFAILURETEMPLATE_PROPERTY}`;
383 if (this.element.tagName === 'UL') {
384 let jsonElement = ListBase.createJsonFromElement(this.element);
385 this.setProperties({ fields: { text: 'text', value: 'text' } }, true);
386 this.resetList(jsonElement, this.fields);
387 }
388 else if (this.element.tagName === 'SELECT') {
389 let dataSource = this.dataSource instanceof Array ? (this.dataSource.length > 0 ? true : false)
390 : !isNullOrUndefined(this.dataSource) ? true : false;
391 if (!dataSource) {
392 this.renderItemsBySelect();
393 }
394 }
395 else {
396 this.setListData(this.dataSource, this.fields, this.query);
397 }
398 }
399 ;
400 DropDownBaseupdateBlazorTemplates(item, group, noRecord, action, value, header, footer, isEmpty) {
401 if (!this.isStringTemplate) {
402 if (this.itemTemplate && item) {
403 updateBlazorTemplate(this.itemTemplateId, ITEMTEMPLATE_PROPERTY, this, isEmpty);
404 }
405 if (this.groupTemplate && group) {
406 updateBlazorTemplate(this.groupTemplateId, GROUPTEMPLATE_PROPERTY, this, isEmpty);
407 }
408 if (this.noRecordsTemplate && noRecord) {
409 updateBlazorTemplate(this.noRecordsTemplateId, NORECORDSTEMPLATE_PROPERTY, this, isEmpty);
410 }
411 if (this.actionFailureTemplate && action) {
412 updateBlazorTemplate(this.actionFailureTemplateId, ACTIONFAILURETEMPLATE_PROPERTY, this, isEmpty);
413 }
414 if (value) {
415 updateBlazorTemplate(this.valueTemplateId, VALUETEMPLATE_PROPERTY, this, isEmpty);
416 }
417 if (header) {
418 updateBlazorTemplate(this.headerTemplateId, HEADERTEMPLATE_PROPERTY, this);
419 }
420 if (footer) {
421 updateBlazorTemplate(this.footerTemplateId, FOOTERTEMPLATE_PROPERTY, this);
422 }
423 }
424 }
425 DropDownBaseresetBlazorTemplates(item, group, noRecord, action, value, header, footer) {
426 if (!this.isStringTemplate) {
427 if (this.itemTemplate && item) {
428 resetBlazorTemplate(this.itemTemplateId, ITEMTEMPLATE_PROPERTY);
429 }
430 if (this.groupTemplate && group) {
431 resetBlazorTemplate(this.groupTemplateId, GROUPTEMPLATE_PROPERTY);
432 }
433 if (this.noRecordsTemplate && noRecord) {
434 resetBlazorTemplate(this.noRecordsTemplateId, NORECORDSTEMPLATE_PROPERTY);
435 }
436 if (this.actionFailureTemplate && action) {
437 resetBlazorTemplate(this.actionFailureTemplateId, ACTIONFAILURETEMPLATE_PROPERTY);
438 }
439 if (value) {
440 resetBlazorTemplate(this.valueTemplateId, VALUETEMPLATE_PROPERTY);
441 }
442 if (header) {
443 resetBlazorTemplate(this.headerTemplateId, HEADERTEMPLATE_PROPERTY);
444 }
445 if (footer) {
446 resetBlazorTemplate(this.footerTemplateId, FOOTERTEMPLATE_PROPERTY);
447 }
448 }
449 }
450 /**
451 * Get the properties to be maintained in persisted state.
452 */
453 getPersistData() {
454 return this.addOnPersist([]);
455 }
456 ;
457 /**
458 * Sets the enabled state to DropDownBase.
459 */
460 setEnabled() {
461 this.element.setAttribute('aria-disabled', (this.enabled) ? 'false' : 'true');
462 }
463 ;
464 /**
465 * Sets the enabled state to DropDownBase.
466 */
467 updateDataAttribute(value) {
468 let invalidAttr = ['class', 'style', 'id', 'type'];
469 let attr = {};
470 for (let a = 0; a < this.element.attributes.length; a++) {
471 if (invalidAttr.indexOf(this.element.attributes[a].name) === -1 &&
472 !(this.getModuleName() === 'dropdownlist' && this.element.attributes[a].name === 'readonly')) {
473 attr[this.element.attributes[a].name] = this.element.getAttribute(this.element.attributes[a].name);
474 }
475 }
476 extend(attr, value, attr);
477 this.setProperties({ htmlAttributes: attr }, true);
478 }
479 renderItemsBySelect() {
480 let element = this.element;
481 let fields = { value: 'value', text: 'text' };
482 let jsonElement = [];
483 let group = element.querySelectorAll('select>optgroup');
484 let option = element.querySelectorAll('select>option');
485 this.getJSONfromOption(jsonElement, option, fields);
486 if (group.length) {
487 for (let i = 0; i < group.length; i++) {
488 let item = group[i];
489 let optionGroup = {};
490 optionGroup[fields.text] = item.label;
491 optionGroup.isHeader = true;
492 let child = item.querySelectorAll('option');
493 jsonElement.push(optionGroup);
494 this.getJSONfromOption(jsonElement, child, fields);
495 }
496 let items = element.querySelectorAll('select>option');
497 }
498 this.fields.text = fields.text;
499 this.fields.value = fields.value;
500 this.resetList(jsonElement, fields);
501 }
502 getJSONfromOption(items, options, fields) {
503 for (let option of options) {
504 let json = {};
505 json[fields.text] = option.innerText;
506 json[fields.value] = option.getAttribute(fields.value) ? option.getAttribute(fields.value) : option.innerText;
507 items.push(json);
508 }
509 }
510 /**
511 * Execute before render the list items
512 * @private
513 */
514 preRender() {
515 // there is no event handler
516 this.scrollTimer = -1;
517 this.enableRtlElements = [];
518 this.isRequested = false;
519 this.isDataFetched = false;
520 this.itemTemplateId = `${this.element.id}${ITEMTEMPLATE_PROPERTY}`;
521 this.valueTemplateId = `${this.element.id}${VALUETEMPLATE_PROPERTY}`;
522 this.groupTemplateId = `${this.element.id}${GROUPTEMPLATE_PROPERTY}`;
523 this.headerTemplateId = `${this.element.id}${HEADERTEMPLATE_PROPERTY}`;
524 this.footerTemplateId = `${this.element.id}${FOOTERTEMPLATE_PROPERTY}`;
525 this.noRecordsTemplateId = `${this.element.id}${NORECORDSTEMPLATE_PROPERTY}`;
526 }
527 /**
528 * Creates the list items of DropDownBase component.
529 */
530 setListData(dataSource, fields, query) {
531 fields = fields ? fields : this.fields;
532 let ulElement;
533 this.isActive = true;
534 let eventArgs = { cancel: false, data: dataSource, query: query };
535 this.trigger('actionBegin', eventArgs, (eventArgs) => {
536 if (!eventArgs.cancel) {
537 this.showSpinner();
538 if (dataSource instanceof DataManager) {
539 this.isRequested = true;
540 if (this.isDataFetched) {
541 this.emptyDataRequest(fields);
542 return;
543 }
544 eventArgs.data.executeQuery(this.getQuery(eventArgs.query)).then((e) => {
545 this.trigger('actionComplete', e, (e) => {
546 if (!e.cancel) {
547 let listItems = e.result;
548 if (listItems.length === 0) {
549 this.isDataFetched = true;
550 }
551 ulElement = this.renderItems(listItems, fields);
552 this.onActionComplete(ulElement, listItems, e);
553 if (this.groupTemplate) {
554 this.renderGroupTemplate(ulElement);
555 }
556 this.isRequested = false;
557 this.bindChildItems(listItems, ulElement, fields, e);
558 }
559 });
560 }).catch((e) => {
561 this.isRequested = false;
562 this.onActionFailure(e);
563 this.hideSpinner();
564 });
565 }
566 else {
567 let dataManager = new DataManager(eventArgs.data);
568 let listItems = (this.getQuery(eventArgs.query)).executeLocal(dataManager);
569 let localDataArgs = { cancel: false, result: listItems };
570 this.trigger('actionComplete', localDataArgs, (localDataArgs) => {
571 if (!localDataArgs.cancel) {
572 ulElement = this.renderItems(localDataArgs.result, fields);
573 this.onActionComplete(ulElement, localDataArgs.result);
574 if (this.groupTemplate) {
575 this.renderGroupTemplate(ulElement);
576 }
577 this.bindChildItems(localDataArgs.result, ulElement, fields);
578 }
579 });
580 }
581 }
582 });
583 }
584 bindChildItems(listItems, ulElement, fields, e) {
585 if (listItems.length >= 100 && this.getModuleName() === 'autocomplete') {
586 setTimeout(() => {
587 let childNode = this.remainingItems(this.sortedData, fields);
588 append(childNode, ulElement);
589 this.DropDownBaseupdateBlazorTemplates(true, false, false, false);
590 this.liCollections = this.list.querySelectorAll('.' + dropDownBaseClasses.li);
591 this.updateListValues();
592 this.raiseDataBound(listItems, e);
593 }, 0);
594 }
595 else {
596 this.raiseDataBound(listItems, e);
597 }
598 }
599 updateListValues() {
600 // Used this method in component side.
601 }
602 findListElement(list, findNode, attribute, value) {
603 let liElement = null;
604 let listArr = [].slice.call(list.querySelectorAll(findNode));
605 for (let index = 0; index < listArr.length; index++) {
606 if (listArr[index].getAttribute(attribute) === (value + '')) {
607 liElement = listArr[index];
608 break;
609 }
610 }
611 return liElement;
612 }
613 raiseDataBound(listItems, e) {
614 this.hideSpinner();
615 let dataBoundEventArgs = {
616 items: listItems,
617 e: e
618 };
619 this.trigger('dataBound', dataBoundEventArgs);
620 }
621 remainingItems(dataSource, fields) {
622 let spliceData = new DataManager(dataSource).executeLocal(new Query().skip(100));
623 if (this.itemTemplate) {
624 let listElements = this.templateListItem(spliceData, fields);
625 return [].slice.call(listElements.childNodes);
626 }
627 let type = this.typeOfData(spliceData).typeof;
628 if (type === 'string' || type === 'number' || type === 'boolean') {
629 return ListBase.createListItemFromArray(this.createElement, spliceData, true, this.listOption(spliceData, fields));
630 }
631 return ListBase.createListItemFromJson(this.createElement, spliceData, this.listOption(spliceData, fields), 1, true);
632 }
633 emptyDataRequest(fields) {
634 let listItems = [];
635 this.onActionComplete(this.renderItems(listItems, fields), listItems);
636 this.isRequested = false;
637 this.hideSpinner();
638 }
639 showSpinner() {
640 // Used this method in component side.
641 }
642 hideSpinner() {
643 // Used this method in component side.
644 }
645 onActionFailure(e) {
646 this.liCollections = [];
647 this.trigger('actionFailure', e);
648 this.l10nUpdate(true);
649 addClass([this.list], dropDownBaseClasses.noData);
650 }
651 onActionComplete(ulElement, list, e) {
652 this.listData = list;
653 this.list.innerHTML = '';
654 this.fixedHeaderElement = isNullOrUndefined(this.fixedHeaderElement) ? this.fixedHeaderElement : null;
655 this.list.appendChild(ulElement);
656 this.liCollections = this.list.querySelectorAll('.' + dropDownBaseClasses.li);
657 this.ulElement = this.list.querySelector('ul');
658 this.postRender(this.list, list, this.bindEvent);
659 }
660 postRender(listElement, list, bindEvent) {
661 let focusItem = listElement.querySelector('.' + dropDownBaseClasses.li);
662 let selectedItem = listElement.querySelector('.' + dropDownBaseClasses.selected);
663 if (focusItem && !selectedItem) {
664 focusItem.classList.add(dropDownBaseClasses.focus);
665 }
666 if (list.length <= 0) {
667 this.l10nUpdate();
668 addClass([listElement], dropDownBaseClasses.noData);
669 }
670 else {
671 listElement.classList.remove(dropDownBaseClasses.noData);
672 }
673 }
674 /**
675 * Get the query to do the data operation before list item generation.
676 */
677 getQuery(query) {
678 return query ? query : this.query ? this.query : new Query();
679 }
680 /**
681 * To render the template content for group header element.
682 */
683 renderGroupTemplate(listEle) {
684 if (this.fields.groupBy !== null && this.dataSource || this.element.querySelector('.' + dropDownBaseClasses.group)) {
685 let dataSource = this.dataSource;
686 let option = { groupTemplateID: this.groupTemplateId, isStringTemplate: this.isStringTemplate };
687 let headerItems = listEle.querySelectorAll('.' + dropDownBaseClasses.group);
688 let tempHeaders = ListBase.renderGroupTemplate(this.groupTemplate, dataSource, this.fields.properties, headerItems, option);
689 this.DropDownBaseupdateBlazorTemplates(false, true, false, false, false, false, false, false);
690 }
691 }
692 /**
693 * To create the ul li list items
694 */
695 createListItems(dataSource, fields) {
696 if (dataSource && fields.groupBy || this.element.querySelector('optgroup')) {
697 if (fields.groupBy) {
698 if (this.sortOrder !== 'None') {
699 dataSource = this.getSortedDataSource(dataSource);
700 }
701 dataSource = ListBase.groupDataSource(dataSource, fields.properties, this.sortOrder);
702 }
703 addClass([this.list], dropDownBaseClasses.grouping);
704 }
705 else {
706 dataSource = this.getSortedDataSource(dataSource);
707 }
708 let options = this.listOption(dataSource, fields);
709 let spliceData = (dataSource.length > 100) ?
710 new DataManager(dataSource).executeLocal(new Query().take(100))
711 : dataSource;
712 this.sortedData = dataSource;
713 return ListBase.createList(this.createElement, (this.getModuleName() === 'autocomplete') ? spliceData : dataSource, options, true);
714 }
715 ;
716 listOption(dataSource, fields) {
717 let iconCss = isNullOrUndefined(fields.iconCss) ? false : true;
718 let fieldValues = !isNullOrUndefined(fields.properties) ?
719 fields.properties : fields;
720 let options = (fields.text !== null || fields.value !== null) ? {
721 fields: fieldValues,
722 showIcon: iconCss, ariaAttributes: { groupItemRole: 'presentation' }
723 } : { fields: { value: 'text' } };
724 return extend({}, options, fields, true);
725 }
726 ;
727 setFloatingHeader(e) {
728 if (isNullOrUndefined(this.fixedHeaderElement)) {
729 this.fixedHeaderElement = this.createElement('div', { className: dropDownBaseClasses.fixedHead });
730 if (!this.list.querySelector('li').classList.contains(dropDownBaseClasses.group)) {
731 this.fixedHeaderElement.style.display = 'none';
732 }
733 prepend([this.fixedHeaderElement], this.list);
734 this.setFixedHeader();
735 }
736 if (!isNullOrUndefined(this.fixedHeaderElement) && this.fixedHeaderElement.style.zIndex === '0') {
737 this.setFixedHeader();
738 }
739 this.scrollStop(e);
740 }
741 scrollStop(e) {
742 let target = e.target;
743 let liHeight = parseInt(getComputedStyle(this.liCollections[0], null).getPropertyValue('height'), 10);
744 let topIndex = Math.round(target.scrollTop / liHeight);
745 let liCollections = this.list.querySelectorAll('li');
746 for (let i = topIndex; i > -1; i--) {
747 if (!isNullOrUndefined(liCollections[i]) && liCollections[i].classList.contains(dropDownBaseClasses.group)) {
748 let currentLi = liCollections[i];
749 this.fixedHeaderElement.innerHTML = currentLi.innerHTML;
750 this.fixedHeaderElement.style.top = e.target.scrollTop + 'px';
751 this.fixedHeaderElement.style.display = 'block';
752 break;
753 }
754 else {
755 this.fixedHeaderElement.style.display = 'none';
756 this.fixedHeaderElement.style.top = 'none';
757 }
758 }
759 }
760 /**
761 * To render the list items
762 */
763 renderItems(listData, fields) {
764 let ulElement;
765 if (this.itemTemplate && listData) {
766 let dataSource = listData;
767 if (dataSource && fields.groupBy) {
768 if (this.sortOrder !== 'None') {
769 dataSource = this.getSortedDataSource(dataSource);
770 }
771 dataSource = ListBase.groupDataSource(dataSource, fields.properties, this.sortOrder);
772 }
773 else {
774 dataSource = this.getSortedDataSource(dataSource);
775 }
776 this.sortedData = dataSource;
777 let spliceData = (dataSource.length > 100) ?
778 new DataManager(dataSource).executeLocal(new Query().take(100))
779 : dataSource;
780 ulElement = this.templateListItem((this.getModuleName() === 'autocomplete') ? spliceData : dataSource, fields);
781 let isTempEmpty = (this.getModuleName() === 'listbox') ? true : false;
782 this.DropDownBaseupdateBlazorTemplates(true, false, false, false, false, false, false, isTempEmpty);
783 }
784 else {
785 ulElement = this.createListItems(listData, fields);
786 }
787 return ulElement;
788 }
789 ;
790 templateListItem(dataSource, fields) {
791 this.DropDownBaseresetBlazorTemplates(true, false, false, false);
792 let option = this.listOption(dataSource, fields);
793 option.templateID = this.itemTemplateId;
794 option.isStringTemplate = this.isStringTemplate;
795 return ListBase.renderContentTemplate(this.createElement, this.itemTemplate, dataSource, fields.properties, option);
796 }
797 typeOfData(items) {
798 let item = { typeof: null, item: null };
799 for (let i = 0; (!isNullOrUndefined(items) && i < items.length); i++) {
800 if (!isNullOrUndefined(items[i])) {
801 let listDataType = typeof (items[i]) === 'string' ||
802 typeof (items[i]) === 'number' || typeof (items[i]) === 'boolean';
803 let isNullData = listDataType ? isNullOrUndefined(items[i]) :
804 isNullOrUndefined(getValue((this.fields.value ? this.fields.value : 'value'), items[i]));
805 if (!isNullData) {
806 return item = { typeof: typeof items[i], item: items[i] };
807 }
808 }
809 }
810 return item;
811 }
812 setFixedHeader() {
813 this.list.parentElement.style.display = 'block';
814 let borderWidth = 0;
815 if (this.list && this.list.parentElement) {
816 borderWidth = parseInt(document.defaultView.getComputedStyle(this.list.parentElement, null).getPropertyValue('border-width'), 10);
817 }
818 let liWidth = this.liCollections[0].offsetWidth - borderWidth;
819 this.fixedHeaderElement.style.width = liWidth.toString() + 'px';
820 setStyleAttribute(this.fixedHeaderElement, { zIndex: 10 });
821 let firstLi = this.ulElement.querySelector('.' + dropDownBaseClasses.group);
822 this.fixedHeaderElement.innerHTML = firstLi.innerHTML;
823 }
824 getSortedDataSource(dataSource) {
825 if (dataSource && this.sortOrder !== 'None') {
826 let textField = this.fields.text ? this.fields.text : 'text';
827 dataSource = ListBase.getDataSource(dataSource, ListBase.addSorting(this.sortOrder, textField));
828 }
829 return dataSource;
830 }
831 /**
832 * Return the index of item which matched with given value in data source
833 */
834 getIndexByValue(value) {
835 let index;
836 let listItems = this.getItems();
837 for (let i = 0; i < listItems.length; i++) {
838 if (!isNullOrUndefined(value) && listItems[i].getAttribute('data-value') === value.toString()) {
839 index = i;
840 break;
841 }
842 }
843 return index;
844 }
845 ;
846 /**
847 * To dispatch the event manually
848 */
849 dispatchEvent(element, type) {
850 let evt = document.createEvent('HTMLEvents');
851 evt.initEvent(type, false, true);
852 element.dispatchEvent(evt);
853 }
854 /**
855 * To set the current fields
856 */
857 setFields() {
858 if (this.fields.value && !this.fields.text) {
859 this.fields.text = this.fields.value;
860 }
861 else if (!this.fields.value && this.fields.text) {
862 this.fields.value = this.fields.text;
863 }
864 else if (!this.fields.value && !this.fields.text) {
865 this.fields.value = this.fields.text = 'text';
866 }
867 }
868 /**
869 * reset the items list.
870 */
871 resetList(dataSource, fields, query) {
872 if (this.list) {
873 if ((this.element.tagName === 'SELECT' && this.element.options.length > 0)
874 || (this.element.tagName === 'UL' && this.element.childNodes.length > 0)) {
875 let data = dataSource instanceof Array ? (dataSource.length > 0)
876 : !isNullOrUndefined(dataSource);
877 if (!data && this.selectData && this.selectData.length > 0) {
878 dataSource = this.selectData;
879 }
880 }
881 this.setListData(dataSource, fields, query);
882 }
883 }
884 updateSelectElementData(isFiltering) {
885 if (isFiltering && isNullOrUndefined(this.selectData) && this.listData && this.listData.length > 0) {
886 this.selectData = this.listData;
887 }
888 }
889 updateSelection() {
890 // This is for after added the item, need to update the selected index values.
891 }
892 renderList() {
893 // This is for render the list items.
894 this.render();
895 }
896 updateDataSource(props) {
897 this.resetList(this.dataSource);
898 }
899 setUpdateInitial(props, newProp) {
900 this.isDataFetched = false;
901 let updateData = {};
902 for (let j = 0; props.length > j; j++) {
903 if (newProp[props[j]] && props[j] === 'fields') {
904 this.setFields();
905 }
906 else if (newProp[props[j]]) {
907 updateData[props[j]] = newProp[props[j]];
908 }
909 }
910 if (Object.keys(updateData).length > 0) {
911 if (Object.keys(updateData).indexOf('dataSource') === -1) {
912 updateData.dataSource = this.dataSource;
913 }
914 this.updateDataSource(updateData);
915 }
916 }
917 /**
918 * When property value changes happened, then onPropertyChanged method will execute the respective changes in this component.
919 * @private
920 */
921 onPropertyChanged(newProp, oldProp) {
922 if (this.getModuleName() === 'dropdownbase') {
923 this.setUpdateInitial(['fields', 'query', 'dataSource'], newProp);
924 }
925 this.setUpdateInitial(['sortOrder', 'itemTemplate'], newProp);
926 for (let prop of Object.keys(newProp)) {
927 switch (prop) {
928 case 'query':
929 case 'sortOrder':
930 case 'dataSource':
931 case 'itemTemplate':
932 break;
933 case 'enableRtl':
934 this.setEnableRtl();
935 break;
936 case 'enabled':
937 this.setEnabled();
938 break;
939 case 'groupTemplate':
940 this.renderGroupTemplate(this.list);
941 if (this.ulElement && this.fixedHeaderElement) {
942 let firstLi = this.ulElement.querySelector('.' + dropDownBaseClasses.group);
943 this.fixedHeaderElement.innerHTML = firstLi.innerHTML;
944 }
945 break;
946 case 'locale':
947 if (this.list && (!isNullOrUndefined(this.liCollections) && this.liCollections.length === 0)) {
948 this.l10nUpdate();
949 }
950 break;
951 case 'zIndex':
952 this.setProperties({ zIndex: newProp.zIndex }, true);
953 this.setZIndex();
954 break;
955 }
956 }
957 }
958 ;
959 /**
960 * Build and render the component
961 * @private
962 */
963 render(isEmptyData) {
964 this.list = this.createElement('div', { className: dropDownBaseClasses.content, attrs: { 'tabindex': '0' } });
965 this.list.classList.add(dropDownBaseClasses.root);
966 this.setFields();
967 let rippleModel = { duration: 300, selector: '.' + dropDownBaseClasses.li };
968 this.rippleFun = rippleEffect(this.list, rippleModel);
969 let group = this.element.querySelector('select>optgroup');
970 if ((this.fields.groupBy || !isNullOrUndefined(group)) && !this.isGroupChecking) {
971 EventHandler.add(this.list, 'scroll', this.setFloatingHeader, this);
972 }
973 if (this.getModuleName() === 'dropdownbase') {
974 if (this.element.getAttribute('tabindex')) {
975 this.list.setAttribute('tabindex', this.element.getAttribute('tabindex'));
976 }
977 removeClass([this.element], dropDownBaseClasses.root);
978 this.element.style.display = 'none';
979 let wrapperElement = this.createElement('div');
980 this.element.parentElement.insertBefore(wrapperElement, this.element);
981 wrapperElement.appendChild(this.element);
982 wrapperElement.appendChild(this.list);
983 }
984 this.setEnableRtl();
985 this.setEnabled();
986 if (!isEmptyData) {
987 this.initialize();
988 }
989 }
990 ;
991 /**
992 * Return the module name of this component.
993 * @private
994 */
995 getModuleName() {
996 return 'dropdownbase';
997 }
998 ;
999 /**
1000 * Gets all the list items bound on this component.
1001 * @returns Element[].
1002 */
1003 getItems() {
1004 return this.ulElement.querySelectorAll('.' + dropDownBaseClasses.li);
1005 }
1006 ;
1007 /**
1008 * Adds a new item to the popup list. By default, new item appends to the list as the last item,
1009 * but you can insert based on the index parameter.
1010 * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
1011 * @param { number } itemIndex - Specifies the index to place the newly added item in the popup list.
1012 * @return {void}.
1013 * @deprecated
1014 */
1015 addItem(items, itemIndex) {
1016 if (!this.list || (this.list.textContent === this.noRecordsTemplate && this.getModuleName() !== 'listbox')) {
1017 this.renderList();
1018 }
1019 this.DropDownBaseresetBlazorTemplates(true, false, false, false);
1020 let itemsCount = this.getItems().length;
1021 let selectedItemValue = this.list.querySelector('.' + dropDownBaseClasses.selected);
1022 items = (items instanceof Array ? items : [items]);
1023 let index;
1024 index = (isNullOrUndefined(itemIndex) || itemIndex < 0 || itemIndex > itemsCount - 1) ? itemsCount : itemIndex;
1025 let fields = this.fields;
1026 if (items && fields.groupBy) {
1027 items = ListBase.groupDataSource(items, fields.properties);
1028 }
1029 let liCollections = [];
1030 for (let i = 0; i < items.length; i++) {
1031 let item = items[i];
1032 let isHeader = item.isHeader;
1033 let li = this.createElement('li', { className: isHeader ? dropDownBaseClasses.group : dropDownBaseClasses.li, id: 'option-add-' + i });
1034 let itemText = item instanceof Object ? getValue(fields.text, item) : item;
1035 if (isHeader) {
1036 li.innerText = itemText;
1037 }
1038 if (this.itemTemplate && !isHeader) {
1039 let compiledString = compile(this.itemTemplate);
1040 append(compiledString(item, null, null, this.itemTemplateId, this.isStringTemplate), li);
1041 this.DropDownBaseupdateBlazorTemplates(true, false, false, false);
1042 }
1043 else if (!isHeader) {
1044 li.appendChild(document.createTextNode(itemText));
1045 }
1046 li.setAttribute('data-value', item instanceof Object ? getValue(fields.value, item) : item);
1047 li.setAttribute('role', 'option');
1048 this.notify('addItem', { module: 'CheckBoxSelection', item: li });
1049 liCollections.push(li);
1050 this.listData.push(item);
1051 this.updateActionCompleteData(li, item);
1052 //Listbox event
1053 this.trigger('beforeItemRender', { element: li, item: item });
1054 }
1055 if (itemsCount === 0 && isNullOrUndefined(this.list.querySelector('ul'))) {
1056 this.list.innerHTML = '';
1057 this.list.classList.remove(dropDownBaseClasses.noData);
1058 this.list.appendChild(this.ulElement);
1059 append(liCollections, this.ulElement);
1060 }
1061 else {
1062 if (this.getModuleName() === 'listbox' && itemsCount === 0) {
1063 this.ulElement.innerHTML = '';
1064 }
1065 let attr = [];
1066 for (let i = 0; i < items.length; i++) {
1067 let listGroupItem = this.ulElement.querySelectorAll('.e-list-group-item');
1068 for (let j = 0; j < listGroupItem.length; j++) {
1069 attr[j] = listGroupItem[j].innerText;
1070 }
1071 if (attr.indexOf(liCollections[i].innerText) > -1 && fields.groupBy) {
1072 for (let j = 0; j < listGroupItem.length; j++) {
1073 if (attr[j] === liCollections[i].innerText) {
1074 this.ulElement.insertBefore(liCollections[i + 1], listGroupItem[j + 1]);
1075 i = i + 1;
1076 break;
1077 }
1078 }
1079 }
1080 else {
1081 if (this.liCollections[index]) {
1082 this.liCollections[index].parentNode.insertBefore(liCollections[i], this.liCollections[index]);
1083 }
1084 else {
1085 this.ulElement.appendChild(liCollections[i]);
1086 }
1087 }
1088 let tempLi = [].slice.call(this.liCollections);
1089 tempLi.splice(index, 0, liCollections[i]);
1090 this.liCollections = tempLi;
1091 index += 1;
1092 if (this.getModuleName() === 'multiselect') {
1093 this.updateDataList();
1094 }
1095 }
1096 }
1097 if (selectedItemValue || itemIndex === 0) {
1098 this.updateSelection();
1099 }
1100 }
1101 validationAttribute(target, hidden) {
1102 let name = target.getAttribute('name') ? target.getAttribute('name') : target.getAttribute('id');
1103 hidden.setAttribute('name', name);
1104 target.removeAttribute('name');
1105 let attributes$$1 = ['required', 'aria-required', 'form'];
1106 for (let i = 0; i < attributes$$1.length; i++) {
1107 if (!target.getAttribute(attributes$$1[i])) {
1108 continue;
1109 }
1110 let attr = target.getAttribute(attributes$$1[i]);
1111 hidden.setAttribute(attributes$$1[i], attr);
1112 target.removeAttribute(attributes$$1[i]);
1113 }
1114 }
1115 setZIndex() {
1116 // this is for component wise
1117 }
1118 updateActionCompleteData(li, item) {
1119 // this is for ComboBox custom value
1120 }
1121 updateDataList() {
1122 // this is for multiselect update list items
1123 }
1124 /**
1125 * Gets the data Object that matches the given value.
1126 * @param { string | number } value - Specifies the value of the list item.
1127 * @returns Object.
1128 * @blazorType object
1129 */
1130 getDataByValue(value) {
1131 if (!isNullOrUndefined(this.listData)) {
1132 let type = this.typeOfData(this.listData).typeof;
1133 if (type === 'string' || type === 'number' || type === 'boolean') {
1134 for (let item of this.listData) {
1135 if (!isNullOrUndefined(item) && item === value) {
1136 return item;
1137 }
1138 }
1139 }
1140 else {
1141 for (let item of this.listData) {
1142 if (!isNullOrUndefined(item) && getValue((this.fields.value ? this.fields.value : 'value'), item) === value) {
1143 return item;
1144 }
1145 }
1146 }
1147 }
1148 return null;
1149 }
1150 /**
1151 * Removes the component from the DOM and detaches all its related event handlers. It also removes the attributes and classes.
1152 * @method destroy
1153 * @return {void}.
1154 */
1155 destroy() {
1156 if (document.body.contains(this.list)) {
1157 EventHandler.remove(this.list, 'scroll', this.setFloatingHeader);
1158 if (!isNullOrUndefined(this.rippleFun)) {
1159 this.rippleFun();
1160 }
1161 detach(this.list);
1162 }
1163 super.destroy();
1164 }
1165 ;
1166};
1167__decorate([
1168 Complex({ text: null, value: null, iconCss: null, groupBy: null }, FieldSettings)
1169], DropDownBase.prototype, "fields", void 0);
1170__decorate([
1171 Property(false)
1172], DropDownBase.prototype, "enablePersistence", void 0);
1173__decorate([
1174 Property(null)
1175], DropDownBase.prototype, "itemTemplate", void 0);
1176__decorate([
1177 Property(null)
1178], DropDownBase.prototype, "groupTemplate", void 0);
1179__decorate([
1180 Property('No Records Found')
1181], DropDownBase.prototype, "noRecordsTemplate", void 0);
1182__decorate([
1183 Property('The Request Failed')
1184], DropDownBase.prototype, "actionFailureTemplate", void 0);
1185__decorate([
1186 Property('None')
1187], DropDownBase.prototype, "sortOrder", void 0);
1188__decorate([
1189 Property(true)
1190], DropDownBase.prototype, "enabled", void 0);
1191__decorate([
1192 Property([])
1193], DropDownBase.prototype, "dataSource", void 0);
1194__decorate([
1195 Property(null)
1196], DropDownBase.prototype, "query", void 0);
1197__decorate([
1198 Property('StartsWith')
1199], DropDownBase.prototype, "filterType", void 0);
1200__decorate([
1201 Property(true)
1202], DropDownBase.prototype, "ignoreCase", void 0);
1203__decorate([
1204 Property(1000)
1205], DropDownBase.prototype, "zIndex", void 0);
1206__decorate([
1207 Property(false)
1208], DropDownBase.prototype, "ignoreAccent", void 0);
1209__decorate([
1210 Property()
1211], DropDownBase.prototype, "locale", void 0);
1212__decorate([
1213 Event()
1214], DropDownBase.prototype, "actionBegin", void 0);
1215__decorate([
1216 Event()
1217], DropDownBase.prototype, "actionComplete", void 0);
1218__decorate([
1219 Event()
1220], DropDownBase.prototype, "actionFailure", void 0);
1221__decorate([
1222 Event()
1223], DropDownBase.prototype, "select", void 0);
1224__decorate([
1225 Event()
1226], DropDownBase.prototype, "dataBound", void 0);
1227__decorate([
1228 Event()
1229], DropDownBase.prototype, "created", void 0);
1230__decorate([
1231 Event()
1232], DropDownBase.prototype, "destroyed", void 0);
1233DropDownBase = __decorate([
1234 NotifyPropertyChanges
1235], DropDownBase);
1236
1237/**
1238 * export all modules from current location
1239 */
1240
1241var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
1242 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1243 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1244 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1245 return c > 3 && r && Object.defineProperty(target, key, r), r;
1246};
1247/// <reference path='../drop-down-base/drop-down-base-model.d.ts'/>
1248/* tslint:disable */
1249// don't use space in classnames
1250const dropDownListClasses = {
1251 root: 'e-dropdownlist',
1252 hover: dropDownBaseClasses.hover,
1253 selected: dropDownBaseClasses.selected,
1254 rtl: dropDownBaseClasses.rtl,
1255 li: dropDownBaseClasses.li,
1256 disable: dropDownBaseClasses.disabled,
1257 base: dropDownBaseClasses.root,
1258 focus: dropDownBaseClasses.focus,
1259 input: 'e-input-group',
1260 inputFocus: 'e-input-focus',
1261 icon: 'e-input-group-icon e-ddl-icon',
1262 iconAnimation: 'e-icon-anim',
1263 value: 'e-input-value',
1264 device: 'e-ddl-device',
1265 backIcon: 'e-input-group-icon e-back-icon e-icons',
1266 filterBarClearIcon: 'e-input-group-icon e-clear-icon e-icons',
1267 filterInput: 'e-input-filter',
1268 filterParent: 'e-filter-parent',
1269 mobileFilter: 'e-ddl-device-filter',
1270 footer: 'e-ddl-footer',
1271 header: 'e-ddl-header',
1272 clearIcon: 'e-clear-icon',
1273 clearIconHide: 'e-clear-icon-hide',
1274 popupFullScreen: 'e-popup-full-page',
1275 disableIcon: 'e-ddl-disable-icon',
1276 hiddenElement: 'e-ddl-hidden'
1277};
1278let inputObject = {
1279 container: null,
1280 buttons: []
1281};
1282/**
1283 * The DropDownList component contains a list of predefined values from which you can
1284 * choose a single value.
1285 * ```html
1286 * <input type="text" tabindex="1" id="list"> </input>
1287 * ```
1288 * ```typescript
1289 * let dropDownListObj:DropDownList = new DropDownList();
1290 * dropDownListObj.appendTo("#list");
1291 * ```
1292 */
1293let DropDownList = class DropDownList extends DropDownBase {
1294 /**
1295 * * Constructor for creating the DropDownList component.
1296 */
1297 constructor(options, element) {
1298 super(options, element);
1299 this.previousValue = null;
1300 }
1301 ;
1302 /**
1303 * Initialize the event handler.
1304 * @private
1305 */
1306 preRender() {
1307 this.isServerBlazor = (isBlazor() && this.isServerRendered && this.getModuleName() === 'dropdownlist') ? true : false;
1308 if (this.isServerBlazor) {
1309 this.initializeData();
1310 }
1311 else {
1312 this.element.style.opacity = '0';
1313 this.initializeData();
1314 super.preRender();
1315 }
1316 this.activeIndex = this.index;
1317 this.queryString = '';
1318 }
1319 initializeData() {
1320 this.isPopupOpen = false;
1321 this.isDocumentClick = false;
1322 this.isInteracted = false;
1323 this.isFilterFocus = false;
1324 this.beforePopupOpen = false;
1325 this.initial = true;
1326 this.initRemoteRender = false;
1327 this.isNotSearchList = false;
1328 this.isTyped = false;
1329 this.isSelected = false;
1330 this.preventFocus = false;
1331 this.preventAutoFill = false;
1332 this.isValidKey = false;
1333 this.typedString = '';
1334 this.isEscapeKey = false;
1335 this.isPreventBlur = false;
1336 this.isTabKey = false;
1337 this.actionCompleteData = { isUpdated: false };
1338 this.prevSelectPoints = {};
1339 this.isSelectCustom = false;
1340 this.isDropDownClick = false;
1341 this.preventAltUp = false;
1342 this.isCustomFilter = false;
1343 this.isSecondClick = false;
1344 this.keyConfigure = {
1345 tab: 'tab',
1346 enter: '13',
1347 escape: '27',
1348 end: '35',
1349 home: '36',
1350 down: '40',
1351 up: '38',
1352 pageUp: '33',
1353 pageDown: '34',
1354 open: 'alt+40',
1355 close: 'shift+tab',
1356 hide: 'alt+38',
1357 space: '32'
1358 };
1359 }
1360 setZIndex() {
1361 if (this.popupObj) {
1362 this.popupObj.setProperties({ 'zIndex': this.zIndex });
1363 }
1364 }
1365 renderList(isEmptyData) {
1366 if (!this.isServerBlazor) {
1367 super.render(isEmptyData);
1368 this.wireListEvents();
1369 }
1370 else {
1371 // tslint:disable-next-line
1372 this.interopAdaptor.invokeMethodAsync('OnServerRenderList', this.beforePopupOpen);
1373 }
1374 }
1375 floatLabelChange() {
1376 if (this.getModuleName() === 'dropdownlist' && this.floatLabelType === 'Auto') {
1377 let floatElement = this.inputWrapper.container.querySelector('.e-float-text');
1378 if (this.inputElement.value !== '' || this.isInteracted) {
1379 classList(floatElement, ['e-label-top'], ['e-label-bottom']);
1380 }
1381 else {
1382 classList(floatElement, ['e-label-bottom'], ['e-label-top']);
1383 }
1384 }
1385 }
1386 resetHandler(e) {
1387 e.preventDefault();
1388 this.clearAll(e);
1389 }
1390 resetFocusElement() {
1391 this.removeHover();
1392 this.removeSelection();
1393 this.removeFocus();
1394 this.list.scrollTop = 0;
1395 if (this.getModuleName() !== 'autocomplete' && !isNullOrUndefined(this.ulElement)) {
1396 let li = this.ulElement.querySelector('.' + dropDownListClasses.li);
1397 if (li) {
1398 li.classList.add(dropDownListClasses.focus);
1399 }
1400 }
1401 }
1402 clearAll(e, properties) {
1403 if (isNullOrUndefined(properties) || (!isNullOrUndefined(properties) &&
1404 (isNullOrUndefined(properties.dataSource) ||
1405 (!(properties.dataSource instanceof DataManager) && properties.dataSource.length === 0)))) {
1406 this.isActive = true;
1407 this.resetSelection(properties);
1408 }
1409 let dataItem = this.getItemData();
1410 if (this.previousValue === dataItem.value) {
1411 return;
1412 }
1413 this.onChangeEvent(e);
1414 }
1415 resetSelection(properties) {
1416 if (this.list) {
1417 if ((!isNullOrUndefined(properties) &&
1418 (isNullOrUndefined(properties.dataSource) ||
1419 (!(properties.dataSource instanceof DataManager) && properties.dataSource.length === 0)))) {
1420 this.selectedLI = null;
1421 this.actionCompleteData.isUpdated = false;
1422 this.actionCompleteData.ulElement = null;
1423 this.actionCompleteData.list = null;
1424 this.resetList(properties.dataSource);
1425 }
1426 else {
1427 if (this.allowFiltering && this.getModuleName() !== 'autocomplete'
1428 && !isNullOrUndefined(this.actionCompleteData.ulElement) && !isNullOrUndefined(this.actionCompleteData.list)) {
1429 let actionList = this.actionCompleteData.ulElement.querySelector('li');
1430 let ulElement = this.ulElement && this.ulElement.querySelector('li');
1431 if (this.element.tagName === 'EJS-COMBOBOX' && actionList && ulElement &&
1432 actionList.childElementCount > 0 && ulElement.childElementCount > 0 &&
1433 actionList.textContent !== ulElement.textContent && this.itemTemplate) {
1434 this.cloneElements();
1435 }
1436 this.onActionComplete(this.actionCompleteData.ulElement.cloneNode(true), this.actionCompleteData.list);
1437 }
1438 this.resetFocusElement();
1439 }
1440 }
1441 this.hiddenElement.innerHTML = '';
1442 this.inputElement.value = '';
1443 this.value = null;
1444 this.itemData = null;
1445 this.text = null;
1446 this.index = null;
1447 this.activeIndex = null;
1448 this.item = null;
1449 this.queryString = '';
1450 if (this.valueTempElement) {
1451 detach(this.valueTempElement);
1452 this.inputElement.style.display = 'block';
1453 this.valueTempElement = null;
1454 }
1455 this.setSelection(null, null);
1456 this.isSelectCustom = false;
1457 this.updateIconState();
1458 this.cloneElements();
1459 }
1460 setHTMLAttributes() {
1461 if (Object.keys(this.htmlAttributes).length) {
1462 for (let htmlAttr of Object.keys(this.htmlAttributes)) {
1463 if (htmlAttr === 'class') {
1464 this.inputWrapper.container.classList.add(this.htmlAttributes[htmlAttr]);
1465 }
1466 else if (htmlAttr === 'disabled' && this.htmlAttributes[htmlAttr] === 'disabled') {
1467 this.enabled = false;
1468 this.setEnable();
1469 }
1470 else if (htmlAttr === 'readonly' && !isNullOrUndefined(this.htmlAttributes[htmlAttr])) {
1471 this.readonly = true;
1472 this.dataBind();
1473 }
1474 else if (htmlAttr === 'style') {
1475 this.inputWrapper.container.setAttribute('style', this.htmlAttributes[htmlAttr]);
1476 }
1477 else {
1478 let defaultAttr = ['title', 'id', 'placeholder', 'aria-placeholder',
1479 'role', 'autocorrect', 'autocomplete', 'autocapitalize', 'spellcheck', 'minlength', 'maxlength'];
1480 let validateAttr = ['name', 'required'];
1481 if (htmlAttr.indexOf('data') === 0 || validateAttr.indexOf(htmlAttr) > -1) {
1482 this.hiddenElement.setAttribute(htmlAttr, this.htmlAttributes[htmlAttr]);
1483 }
1484 else if (defaultAttr.indexOf(htmlAttr) > -1) {
1485 htmlAttr === 'placeholder' ? Input.setPlaceholder(this.htmlAttributes[htmlAttr], this.inputElement) :
1486 this.inputElement.setAttribute(htmlAttr, this.htmlAttributes[htmlAttr]);
1487 }
1488 else {
1489 this.inputWrapper.container.setAttribute(htmlAttr, this.htmlAttributes[htmlAttr]);
1490 }
1491 }
1492 }
1493 }
1494 if (this.getModuleName() === 'autocomplete' || this.getModuleName() === 'combobox') {
1495 this.inputWrapper.container.removeAttribute('tabindex');
1496 }
1497 }
1498 getAriaAttributes() {
1499 return {
1500 'aria-disabled': 'false',
1501 'aria-owns': this.element.id + '_options',
1502 'role': 'listbox',
1503 'aria-haspopup': 'true',
1504 'aria-expanded': 'false',
1505 'aria-activedescendant': 'null',
1506 'aria-live': 'polite',
1507 'aria-labelledby': this.hiddenElement.id
1508 };
1509 }
1510 setEnableRtl() {
1511 Input.setEnableRtl(this.enableRtl, [this.inputElement.parentElement]);
1512 if (this.popupObj) {
1513 this.popupObj.enableRtl = this.enableRtl;
1514 this.popupObj.dataBind();
1515 }
1516 }
1517 setEnable() {
1518 Input.setEnabled(this.enabled, this.inputElement);
1519 if (this.enabled) {
1520 removeClass([this.inputWrapper.container], dropDownListClasses.disable);
1521 this.inputElement.setAttribute('aria-disabled', 'false');
1522 this.targetElement().setAttribute('tabindex', this.tabIndex);
1523 }
1524 else {
1525 this.hidePopup();
1526 addClass([this.inputWrapper.container], dropDownListClasses.disable);
1527 this.inputElement.setAttribute('aria-disabled', 'true');
1528 this.targetElement().tabIndex = -1;
1529 }
1530 }
1531 /**
1532 * Get the properties to be maintained in the persisted state.
1533 */
1534 getPersistData() {
1535 return this.addOnPersist(['value']);
1536 }
1537 ;
1538 getLocaleName() {
1539 return 'drop-down-list';
1540 }
1541 ;
1542 preventTabIndex(element) {
1543 if (this.getModuleName() === 'dropdownlist') {
1544 element.tabIndex = -1;
1545 }
1546 }
1547 targetElement() {
1548 return this.inputWrapper.container;
1549 }
1550 getNgDirective() {
1551 return 'EJS-DROPDOWNLIST';
1552 }
1553 getElementByText(text) {
1554 return this.getElementByValue(this.getValueByText(text));
1555 }
1556 getElementByValue(value) {
1557 let item;
1558 let listItems = this.getItems();
1559 for (let liItem of listItems) {
1560 if (this.getFormattedValue(liItem.getAttribute('data-value')) === value) {
1561 item = liItem;
1562 break;
1563 }
1564 }
1565 return item;
1566 }
1567 ;
1568 initValue() {
1569 this.renderList();
1570 if (this.dataSource instanceof DataManager) {
1571 this.initRemoteRender = true;
1572 }
1573 else {
1574 this.updateValues();
1575 }
1576 }
1577 updateValues() {
1578 if (!isNullOrUndefined(this.value)) {
1579 this.setSelection(this.getElementByValue(this.value), null);
1580 }
1581 else if (this.text && isNullOrUndefined(this.value)) {
1582 let element = this.getElementByText(this.text);
1583 if (isNullOrUndefined(element)) {
1584 this.setProperties({ text: null });
1585 return;
1586 }
1587 else {
1588 this.setSelection(element, null);
1589 }
1590 }
1591 else {
1592 this.setSelection(this.liCollections[this.activeIndex], null);
1593 }
1594 this.setHiddenValue();
1595 Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
1596 }
1597 onBlur(e) {
1598 if (!this.enabled) {
1599 return;
1600 }
1601 let target = e.relatedTarget;
1602 let currentTarget = e.target;
1603 let isPreventBlur = this.isPreventBlur;
1604 this.isPreventBlur = false;
1605 //IE 11 - issue
1606 if (isPreventBlur && !this.isDocumentClick && this.isPopupOpen && (!isNullOrUndefined(currentTarget) ||
1607 !this.isFilterLayout() && isNullOrUndefined(target))) {
1608 if (this.getModuleName() === 'dropdownlist' && this.allowFiltering && this.isPopupOpen) {
1609 this.filterInput.focus();
1610 }
1611 else {
1612 this.targetElement().focus();
1613 }
1614 return;
1615 }
1616 if (this.isDocumentClick || (!isNullOrUndefined(this.popupObj)
1617 && document.body.contains(this.popupObj.element) &&
1618 this.popupObj.element.classList.contains(dropDownListClasses.mobileFilter))) {
1619 if (!this.beforePopupOpen) {
1620 this.isDocumentClick = false;
1621 }
1622 return;
1623 }
1624 if (((this.getModuleName() === 'dropdownlist' && !this.isFilterFocus && target !== this.inputElement)
1625 && (document.activeElement !== target || (document.activeElement === target &&
1626 currentTarget.classList.contains(dropDownListClasses.inputFocus)))) ||
1627 (isNullOrUndefined(target) && this.getModuleName() === 'dropdownlist' && this.allowFiltering &&
1628 currentTarget !== this.inputWrapper.container) || this.getModuleName() !== 'dropdownlist' &&
1629 !this.inputWrapper.container.contains(target) || this.isTabKey) {
1630 this.isDocumentClick = this.isPopupOpen ? true : false;
1631 this.focusOutAction();
1632 this.isTabKey = false;
1633 }
1634 if (this.isRequested && !this.isPopupOpen && !this.isPreventBlur) {
1635 this.isActive = false;
1636 this.beforePopupOpen = false;
1637 }
1638 }
1639 focusOutAction() {
1640 this.isInteracted = false;
1641 this.focusOut();
1642 this.onFocusOut();
1643 }
1644 onFocusOut() {
1645 if (!this.enabled) {
1646 return;
1647 }
1648 if (this.isSelected) {
1649 this.isSelectCustom = false;
1650 this.onChangeEvent(null);
1651 }
1652 this.floatLabelChange();
1653 this.dispatchEvent(this.hiddenElement, 'change');
1654 if (this.getModuleName() === 'dropdownlist' && this.element.tagName !== 'INPUT') {
1655 this.dispatchEvent(this.inputElement, 'blur');
1656 }
1657 if (this.inputWrapper.clearButton) {
1658 addClass([this.inputWrapper.clearButton], dropDownListClasses.clearIconHide);
1659 }
1660 this.trigger('blur');
1661 }
1662 onFocus(e) {
1663 if (!this.isInteracted) {
1664 this.isInteracted = true;
1665 let args = { isInteracted: e ? true : false, event: e };
1666 this.trigger('focus', args);
1667 }
1668 this.updateIconState();
1669 }
1670 resetValueHandler(e) {
1671 let formElement = closest(this.inputElement, 'form');
1672 if (formElement && e.target === formElement) {
1673 let val = (this.element.tagName === this.getNgDirective()) ? null : this.inputElement.getAttribute('value');
1674 this.text = val;
1675 }
1676 }
1677 wireEvent() {
1678 EventHandler.add(this.inputWrapper.container, 'mousedown', this.dropDownClick, this);
1679 EventHandler.add(this.inputWrapper.container, 'focus', this.focusIn, this);
1680 EventHandler.add(this.inputWrapper.container, 'keypress', this.onSearch, this);
1681 this.bindCommonEvent();
1682 }
1683 bindCommonEvent() {
1684 EventHandler.add(this.targetElement(), 'blur', this.onBlur, this);
1685 let formElement = closest(this.inputElement, 'form');
1686 if (formElement) {
1687 EventHandler.add(formElement, 'reset', this.resetValueHandler, this);
1688 }
1689 if (!Browser.isDevice) {
1690 this.keyboardModule = new KeyboardEvents(this.targetElement(), {
1691 keyAction: this.keyActionHandler.bind(this), keyConfigs: this.keyConfigure, eventName: 'keydown'
1692 });
1693 }
1694 else {
1695 this.keyboardModule = new KeyboardEvents(this.targetElement(), {
1696 keyAction: this.mobileKeyActionHandler.bind(this), keyConfigs: this.keyConfigure, eventName: 'keydown'
1697 });
1698 }
1699 this.bindClearEvent();
1700 }
1701 bindClearEvent() {
1702 if (this.showClearButton) {
1703 EventHandler.add(this.inputWrapper.clearButton, 'mousedown', this.resetHandler, this);
1704 }
1705 }
1706 unBindCommonEvent() {
1707 EventHandler.remove(this.targetElement(), 'blur', this.onBlur);
1708 let formElement = closest(this.inputElement, 'form');
1709 if (formElement) {
1710 EventHandler.remove(formElement, 'reset', this.resetValueHandler);
1711 }
1712 if (!Browser.isDevice) {
1713 this.keyboardModule.destroy();
1714 }
1715 if (this.showClearButton) {
1716 EventHandler.remove(this.inputWrapper.clearButton, 'mousedown', this.resetHandler);
1717 }
1718 }
1719 updateIconState() {
1720 if (this.showClearButton) {
1721 if (this.inputElement.value !== '' && !this.readonly) {
1722 removeClass([this.inputWrapper.clearButton], dropDownListClasses.clearIconHide);
1723 }
1724 else {
1725 addClass([this.inputWrapper.clearButton], dropDownListClasses.clearIconHide);
1726 }
1727 }
1728 }
1729 /**
1730 * Event binding for list
1731 */
1732 wireListEvents() {
1733 EventHandler.add(this.list, 'click', this.onMouseClick, this);
1734 EventHandler.add(this.list, 'mouseover', this.onMouseOver, this);
1735 EventHandler.add(this.list, 'mouseout', this.onMouseLeave, this);
1736 }
1737 ;
1738 onSearch(e) {
1739 if (e.charCode !== 32 && e.charCode !== 13) {
1740 if (this.list === undefined) {
1741 if (!this.isServerBlazor) {
1742 this.renderList();
1743 }
1744 else {
1745 this.isServerIncrementalSearch = true;
1746 // tslint:disable-next-line
1747 this.interopAdaptor.invokeMethodAsync('OnServerRenderList', true);
1748 }
1749 }
1750 this.searchKeyEvent = e;
1751 this.onServerIncrementalSearch(e);
1752 }
1753 }
1754 onServerIncrementalSearch(e) {
1755 if (!this.isRequested && !isNullOrUndefined(this.list) &&
1756 !isNullOrUndefined(this.list.querySelector('li')) && this.enabled && !this.readonly) {
1757 this.incrementalSearch(e);
1758 }
1759 }
1760 onMouseClick(e) {
1761 let target = e.target;
1762 let classList$$1 = target.classList;
1763 let li = closest(target, '.' + dropDownBaseClasses.li);
1764 if (!this.isValidLI(li)) {
1765 return;
1766 }
1767 this.setSelection(li, e);
1768 if (Browser.isDevice && this.isFilterLayout()) {
1769 history.back();
1770 }
1771 else {
1772 let delay = 100;
1773 this.closePopup(delay);
1774 }
1775 }
1776 onMouseOver(e) {
1777 let currentLi = closest(e.target, '.' + dropDownBaseClasses.li);
1778 this.setHover(currentLi);
1779 }
1780 ;
1781 setHover(li) {
1782 if (this.enabled && this.isValidLI(li) && !li.classList.contains(dropDownBaseClasses.hover)) {
1783 this.removeHover();
1784 addClass([li], dropDownBaseClasses.hover);
1785 }
1786 }
1787 ;
1788 onMouseLeave(e) {
1789 this.removeHover();
1790 }
1791 ;
1792 removeHover() {
1793 let hoveredItem = this.list.querySelectorAll('.' + dropDownBaseClasses.hover);
1794 if (hoveredItem && hoveredItem.length) {
1795 removeClass(hoveredItem, dropDownBaseClasses.hover);
1796 }
1797 }
1798 ;
1799 isValidLI(li) {
1800 return (li && li.hasAttribute('role') && li.getAttribute('role') === 'option');
1801 }
1802 ;
1803 incrementalSearch(e) {
1804 if (this.liCollections.length > 0) {
1805 let li = incrementalSearch(e.charCode, this.liCollections, this.activeIndex, true, this.isServerBlazor);
1806 if (!isNullOrUndefined(li)) {
1807 this.setSelection(li, e);
1808 this.setScrollPosition();
1809 }
1810 }
1811 }
1812 ;
1813 /**
1814 * Hides the spinner loader.
1815 * @returns void.
1816 */
1817 hideSpinner() {
1818 if (!isNullOrUndefined(this.spinnerElement)) {
1819 hideSpinner(this.spinnerElement);
1820 removeClass([this.spinnerElement], dropDownListClasses.disableIcon);
1821 this.spinnerElement.innerHTML = '';
1822 this.spinnerElement = null;
1823 }
1824 }
1825 /**
1826 * Shows the spinner loader.
1827 * @returns void.
1828 */
1829 showSpinner() {
1830 if (isNullOrUndefined(this.spinnerElement)) {
1831 this.spinnerElement = Browser.isDevice && !isNullOrUndefined(this.filterInputObj) && this.filterInputObj.buttons[1] ||
1832 !isNullOrUndefined(this.filterInputObj) && this.filterInputObj.buttons[0] || this.inputWrapper.buttons[0];
1833 addClass([this.spinnerElement], dropDownListClasses.disableIcon);
1834 createSpinner({
1835 target: this.spinnerElement,
1836 width: Browser.isDevice ? '16px' : '14px'
1837 }, this.createElement);
1838 showSpinner(this.spinnerElement);
1839 }
1840 }
1841 keyActionHandler(e) {
1842 if (!this.enabled) {
1843 return;
1844 }
1845 let preventAction = e.action === 'pageUp' || e.action === 'pageDown';
1846 let preventHomeEnd = this.getModuleName() !== 'dropdownlist' && (e.action === 'home' || e.action === 'end');
1847 this.isEscapeKey = e.action === 'escape';
1848 this.isTabKey = !this.isPopupOpen && e.action === 'tab';
1849 let isNavigation = (e.action === 'down' || e.action === 'up' || e.action === 'pageUp' || e.action === 'pageDown'
1850 || e.action === 'home' || e.action === 'end');
1851 if ((this.isEditTextBox() || preventAction || preventHomeEnd) && !this.isPopupOpen) {
1852 return;
1853 }
1854 if (!this.readonly) {
1855 let isTabAction = e.action === 'tab' || e.action === 'close';
1856 if (this.list === undefined && !this.isRequested && !isTabAction && e.action !== 'escape') {
1857 this.searchKeyEvent = e;
1858 this.renderList();
1859 }
1860 if (isNullOrUndefined(this.list) || (!isNullOrUndefined(this.liCollections) &&
1861 isNavigation && this.liCollections.length === 0) || this.isRequested) {
1862 return;
1863 }
1864 if (isTabAction && this.isPopupOpen || e.action === 'escape') {
1865 e.preventDefault();
1866 }
1867 this.isSelected = e.action === 'escape' ? false : this.isSelected;
1868 this.isTyped = (isNavigation || e.action === 'escape') ? false : this.isTyped;
1869 switch (e.action) {
1870 case 'down':
1871 case 'up':
1872 let focusEle = this.list.querySelector('.' + dropDownListClasses.focus);
1873 if (this.isSelectFocusItem(focusEle)) {
1874 this.setSelection(focusEle, e);
1875 }
1876 else {
1877 let nextItem;
1878 let index = e.action === 'down' ? this.activeIndex + 1 : this.activeIndex - 1;
1879 let startIndex = 0;
1880 if (this.getModuleName() === 'autocomplete') {
1881 startIndex = e.action === 'down' && isNullOrUndefined(this.activeIndex) ? 0 : this.liCollections.length - 1;
1882 index = index < 0 ? this.liCollections.length - 1 : index === this.liCollections.length ? 0 : index;
1883 }
1884 nextItem = isNullOrUndefined(this.activeIndex) ? this.liCollections[startIndex] : this.liCollections[index];
1885 this.setSelection(nextItem, e);
1886 }
1887 e.preventDefault();
1888 break;
1889 case 'pageUp':
1890 this.pageUpSelection(this.activeIndex - this.getPageCount(), e);
1891 e.preventDefault();
1892 break;
1893 case 'pageDown':
1894 this.pageDownSelection(this.activeIndex + this.getPageCount(), e);
1895 e.preventDefault();
1896 break;
1897 case 'home':
1898 if (this.getModuleName() === 'dropdownlist') {
1899 e.preventDefault();
1900 if (this.activeIndex === 0) {
1901 return;
1902 }
1903 this.setSelection(this.liCollections[0], e);
1904 }
1905 break;
1906 case 'end':
1907 if (this.getModuleName() === 'dropdownlist') {
1908 e.preventDefault();
1909 let lastLi = this.getItems().length - 1;
1910 if (this.activeIndex === lastLi) {
1911 return;
1912 }
1913 this.setSelection(this.liCollections[lastLi], e);
1914 }
1915 break;
1916 case 'space':
1917 if (this.getModuleName() === 'dropdownlist') {
1918 if (!this.beforePopupOpen) {
1919 this.showPopup();
1920 }
1921 }
1922 break;
1923 case 'open':
1924 this.showPopup();
1925 break;
1926 case 'hide':
1927 this.preventAltUp = this.isPopupOpen;
1928 this.hidePopup();
1929 this.focusDropDown(e);
1930 break;
1931 case 'enter':
1932 this.selectCurrentItem(e);
1933 break;
1934 case 'escape':
1935 case 'tab':
1936 case 'close':
1937 if (this.isPopupOpen) {
1938 this.hidePopup();
1939 this.focusDropDown(e);
1940 }
1941 break;
1942 }
1943 }
1944 }
1945 mobileKeyActionHandler(e) {
1946 if (!this.enabled) {
1947 return;
1948 }
1949 if ((this.isEditTextBox()) && !this.isPopupOpen) {
1950 return;
1951 }
1952 if (!this.readonly) {
1953 if (this.list === undefined && !this.isRequested) {
1954 this.searchKeyEvent = e;
1955 this.renderList();
1956 }
1957 if (isNullOrUndefined(this.list) || (!isNullOrUndefined(this.liCollections) &&
1958 this.liCollections.length === 0) || this.isRequested) {
1959 return;
1960 }
1961 if (e.action === 'enter') {
1962 this.selectCurrentItem(e);
1963 }
1964 }
1965 }
1966 selectCurrentItem(e) {
1967 if (this.isPopupOpen) {
1968 let li = this.list.querySelector('.' + dropDownListClasses.focus);
1969 if (li) {
1970 this.setSelection(li, e);
1971 this.isTyped = false;
1972 }
1973 if (this.isSelected) {
1974 this.isSelectCustom = false;
1975 this.onChangeEvent(e);
1976 }
1977 this.hidePopup();
1978 this.focusDropDown(e);
1979 }
1980 else {
1981 this.showPopup();
1982 }
1983 }
1984 isSelectFocusItem(element) {
1985 return !isNullOrUndefined(element);
1986 }
1987 getPageCount() {
1988 let liHeight = this.list.classList.contains(dropDownBaseClasses.noData) ? null :
1989 getComputedStyle(this.getItems()[0], null).getPropertyValue('height');
1990 return Math.round(this.list.getBoundingClientRect().height / parseInt(liHeight, 10));
1991 }
1992 pageUpSelection(steps, event) {
1993 let previousItem = steps >= 0 ? this.liCollections[steps + 1] : this.liCollections[0];
1994 this.setSelection(previousItem, event);
1995 }
1996 ;
1997 pageDownSelection(steps, event) {
1998 let list = this.getItems();
1999 let previousItem = steps <= list.length ? this.liCollections[steps - 1] : this.liCollections[list.length - 1];
2000 this.setSelection(previousItem, event);
2001 }
2002 ;
2003 unWireEvent() {
2004 EventHandler.remove(this.inputWrapper.container, 'mousedown', this.dropDownClick);
2005 EventHandler.remove(this.inputWrapper.container, 'keypress', this.onSearch);
2006 EventHandler.remove(this.inputWrapper.container, 'focus', this.focusIn);
2007 this.unBindCommonEvent();
2008 }
2009 /**
2010 * Event un binding for list items.
2011 */
2012 unWireListEvents() {
2013 EventHandler.remove(this.list, 'click', this.onMouseClick);
2014 EventHandler.remove(this.list, 'mouseover', this.onMouseOver);
2015 EventHandler.remove(this.list, 'mouseout', this.onMouseLeave);
2016 }
2017 ;
2018 checkSelector(id) {
2019 return '#' + id.replace(/(:|\.|\[|\]|,|=|@|\\|\/|#)/g, '\\$1');
2020 }
2021 onDocumentClick(e) {
2022 let target = e.target;
2023 if (!(!isNullOrUndefined(this.popupObj) && closest(target, this.checkSelector(this.popupObj.element.id))) &&
2024 !this.inputWrapper.container.contains(e.target)) {
2025 if (this.inputWrapper.container.classList.contains(dropDownListClasses.inputFocus) || this.isPopupOpen) {
2026 this.isDocumentClick = true;
2027 let isActive = this.isRequested;
2028 this.isInteracted = false;
2029 this.hidePopup();
2030 if (!isActive) {
2031 this.onFocusOut();
2032 this.inputWrapper.container.classList.remove(dropDownListClasses.inputFocus);
2033 }
2034 }
2035 }
2036 else if (target !== this.inputElement && !(this.allowFiltering && target === this.filterInput)
2037 && !(this.getModuleName() === 'combobox' &&
2038 !this.allowFiltering && Browser.isDevice && target === this.inputWrapper.buttons[0])) {
2039 this.isPreventBlur = (Browser.isIE || Browser.info.name === 'edge') && (document.activeElement === this.targetElement() ||
2040 document.activeElement === this.filterInput);
2041 e.preventDefault();
2042 }
2043 }
2044 activeStateChange() {
2045 if (this.isDocumentClick) {
2046 this.hidePopup();
2047 this.onFocusOut();
2048 this.inputWrapper.container.classList.remove(dropDownListClasses.inputFocus);
2049 }
2050 }
2051 focusDropDown(e) {
2052 if (!this.initial && this.isFilterLayout()) {
2053 this.focusIn(e);
2054 }
2055 }
2056 dropDownClick(e) {
2057 if (e.which === 3 || e.button === 2) {
2058 return;
2059 }
2060 if (this.targetElement().classList.contains(dropDownListClasses.disable) || this.inputWrapper.clearButton === e.target) {
2061 return;
2062 }
2063 let target = e.target;
2064 if (target !== this.inputElement && !(this.allowFiltering && target === this.filterInput) && this.getModuleName() !== 'combobox') {
2065 e.preventDefault();
2066 }
2067 if (!this.readonly) {
2068 if (this.isPopupOpen) {
2069 this.hidePopup();
2070 if (this.isFilterLayout()) {
2071 this.focusDropDown(e);
2072 }
2073 }
2074 else {
2075 this.focusIn(e);
2076 this.floatLabelChange();
2077 this.queryString = this.inputElement.value.trim() === '' ? null : this.inputElement.value;
2078 this.isDropDownClick = true;
2079 this.showPopup();
2080 }
2081 let proxy = this;
2082 let duration = (isBlazor()) ? 1000 : 100;
2083 if (!this.isSecondClick) {
2084 setTimeout(() => { proxy.cloneElements(); proxy.isSecondClick = true; }, duration);
2085 }
2086 }
2087 else {
2088 this.focusIn(e);
2089 }
2090 }
2091 cloneElements() {
2092 if (this.list) {
2093 let ulElement = this.list.querySelector('ul');
2094 if (ulElement) {
2095 ulElement = ulElement.cloneNode ? ulElement.cloneNode(true) : ulElement;
2096 this.actionCompleteData.ulElement = ulElement;
2097 }
2098 }
2099 }
2100 updateSelectedItem(li, e, preventSelect, isSelection) {
2101 this.removeSelection();
2102 li.classList.add(dropDownBaseClasses.selected);
2103 this.removeHover();
2104 let value = this.getFormattedValue(li.getAttribute('data-value'));
2105 let selectedData = this.getDataByValue(value);
2106 if (!this.initial && !preventSelect && !isNullOrUndefined(e)) {
2107 let items = this.detachChanges(selectedData);
2108 this.isSelected = true;
2109 let eventArgs = {
2110 e: e,
2111 item: li,
2112 itemData: items,
2113 isInteracted: e ? true : false,
2114 cancel: false
2115 };
2116 this.trigger('select', eventArgs, (eventArgs) => {
2117 if (eventArgs.cancel) {
2118 li.classList.remove(dropDownBaseClasses.selected);
2119 }
2120 else {
2121 this.selectEventCallback(li, e, preventSelect, selectedData, value);
2122 if (this.isServerBlazor) {
2123 // tslint:disable-next-line
2124 this.interopAdaptor.invokeMethodAsync('OnServerItemData', this.itemData);
2125 }
2126 if (isSelection) {
2127 this.setSelectOptions(li, e);
2128 }
2129 }
2130 });
2131 }
2132 else {
2133 this.selectEventCallback(li, e, preventSelect, selectedData, value);
2134 if (this.isServerBlazor) {
2135 // tslint:disable-next-line
2136 this.interopAdaptor.invokeMethodAsync('OnServerItemData', this.itemData);
2137 }
2138 if (isSelection) {
2139 this.setSelectOptions(li, e);
2140 }
2141 }
2142 }
2143 selectEventCallback(li, e, preventSelect, selectedData, value) {
2144 this.previousItemData = (!isNullOrUndefined(this.itemData)) ? this.itemData : null;
2145 this.item = li;
2146 this.itemData = selectedData;
2147 let focusedItem = this.list.querySelector('.' + dropDownBaseClasses.focus);
2148 if (focusedItem) {
2149 removeClass([focusedItem], dropDownBaseClasses.focus);
2150 }
2151 li.setAttribute('aria-selected', 'true');
2152 this.activeIndex = this.getIndexByValue(value);
2153 }
2154 activeItem(li) {
2155 if (this.isValidLI(li) && !li.classList.contains(dropDownBaseClasses.selected)) {
2156 this.removeSelection();
2157 li.classList.add(dropDownBaseClasses.selected);
2158 this.removeHover();
2159 li.setAttribute('aria-selected', 'true');
2160 }
2161 }
2162 setValue(e) {
2163 let dataItem = this.getItemData();
2164 if (dataItem.value === null) {
2165 if (isBlazor() && dataItem.text !== null || dataItem.text !== '') {
2166 Input.setValue(dataItem.text, this.inputElement, this.floatLabelType, this.showClearButton);
2167 }
2168 else {
2169 Input.setValue(null, this.inputElement, this.floatLabelType, this.showClearButton);
2170 }
2171 }
2172 else {
2173 Input.setValue(dataItem.text, this.inputElement, this.floatLabelType, this.showClearButton);
2174 }
2175 if (this.isServerBlazor) {
2176 // tslint:disable-next-line
2177 this.interopAdaptor.invokeMethodAsync('OnServerValueTemplate', dataItem);
2178 }
2179 if (this.valueTemplate && this.itemData !== null && !this.isServerBlazor) {
2180 this.DropDownBaseresetBlazorTemplates(false, false, false, false, true);
2181 this.setValueTemplate();
2182 }
2183 else if (this.inputElement.previousSibling === this.valueTempElement) {
2184 detach(this.valueTempElement);
2185 this.inputElement.style.display = 'block';
2186 }
2187 if (this.previousValue === dataItem.value) {
2188 this.isSelected = false;
2189 return true;
2190 }
2191 else {
2192 this.isSelected = !this.initial ? true : false;
2193 this.isSelectCustom = false;
2194 if (this.getModuleName() === 'dropdownlist') {
2195 this.updateIconState();
2196 }
2197 return false;
2198 }
2199 }
2200 setSelection(li, e) {
2201 if (this.isValidLI(li) && !li.classList.contains(dropDownBaseClasses.selected)) {
2202 this.updateSelectedItem(li, e, false, true);
2203 }
2204 else {
2205 this.setSelectOptions(li, e);
2206 }
2207 }
2208 setSelectOptions(li, e) {
2209 if (this.list) {
2210 this.removeHover();
2211 }
2212 this.previousSelectedLI = (!isNullOrUndefined(this.selectedLI)) ? this.selectedLI : null;
2213 this.selectedLI = li;
2214 if (this.setValue(e)) {
2215 return;
2216 }
2217 if (this.isPopupOpen) {
2218 attributes(this.targetElement(), { 'aria-activedescendant': this.selectedLI ? this.selectedLI.id : null });
2219 if (this.isFilterLayout()) {
2220 attributes(this.filterInput, { 'aria-activedescendant': this.selectedLI ? this.selectedLI.id : null });
2221 }
2222 }
2223 if ((!this.isPopupOpen && !isNullOrUndefined(li)) || (this.isPopupOpen && !isNullOrUndefined(e) &&
2224 (e.type !== 'keydown' || e.type === 'keydown' && e.action === 'enter'))) {
2225 this.isSelectCustom = false;
2226 this.onChangeEvent(e);
2227 }
2228 if (this.isPopupOpen && !isNullOrUndefined(this.selectedLI) && this.itemData !== null && (!e || e.type !== 'click')) {
2229 this.setScrollPosition(e);
2230 }
2231 if (Browser.info.name !== 'mozilla') {
2232 attributes(this.inputElement, { 'aria-label': this.inputElement.value });
2233 attributes(this.targetElement(), { 'aria-describedby': this.inputElement.id });
2234 this.targetElement().removeAttribute('aria-live');
2235 }
2236 }
2237 setValueTemplate() {
2238 let compiledString;
2239 if (!this.valueTempElement) {
2240 this.valueTempElement = this.createElement('span', { className: dropDownListClasses.value });
2241 this.inputElement.parentElement.insertBefore(this.valueTempElement, this.inputElement);
2242 this.inputElement.style.display = 'none';
2243 }
2244 this.valueTempElement.innerHTML = '';
2245 let templateData = (isBlazor()) ? JSON.parse(JSON.stringify(this.itemData)) : this.itemData;
2246 compiledString = compile(this.valueTemplate);
2247 for (let item of compiledString(templateData, null, null, this.valueTemplateId, this.isStringTemplate)) {
2248 this.valueTempElement.appendChild(item);
2249 }
2250 this.DropDownBaseupdateBlazorTemplates(false, false, false, false, true, true, true);
2251 }
2252 removeSelection() {
2253 let selectedItems = this.list.querySelectorAll('.' + dropDownBaseClasses.selected);
2254 if (selectedItems.length) {
2255 removeClass(selectedItems, dropDownBaseClasses.selected);
2256 selectedItems[0].removeAttribute('aria-selected');
2257 }
2258 }
2259 ;
2260 getItemData() {
2261 let fields = this.fields;
2262 let dataItem = null;
2263 dataItem = this.itemData;
2264 let dataValue;
2265 let dataText;
2266 if (!isNullOrUndefined(dataItem)) {
2267 dataValue = getValue(fields.value, dataItem);
2268 dataText = getValue(fields.text, dataItem);
2269 }
2270 let value = (!isNullOrUndefined(dataItem) &&
2271 !isUndefined(dataValue) ? dataValue : dataItem);
2272 let text = (!isNullOrUndefined(dataItem) &&
2273 !isUndefined(dataValue) ? dataText : dataItem);
2274 return { value: value, text: text };
2275 }
2276 /**
2277 * To trigger the change event for list.
2278 */
2279 onChangeEvent(eve) {
2280 let dataItem = this.getItemData();
2281 let index = this.isSelectCustom ? null : this.activeIndex;
2282 this.setProperties({ 'index': index, 'text': dataItem.text, 'value': dataItem.value }, true);
2283 this.detachChangeEvent(eve);
2284 }
2285 ;
2286 detachChanges(value) {
2287 let items;
2288 if (typeof value === 'string' ||
2289 typeof value === 'boolean' ||
2290 typeof value === 'number') {
2291 items = Object.defineProperties({}, {
2292 value: {
2293 value: value,
2294 enumerable: true
2295 },
2296 text: {
2297 value: value,
2298 enumerable: true
2299 }
2300 });
2301 }
2302 else {
2303 items = value;
2304 }
2305 return items;
2306 }
2307 detachChangeEvent(eve) {
2308 this.isSelected = false;
2309 this.previousValue = this.value;
2310 this.activeIndex = this.index;
2311 this.typedString = !isNullOrUndefined(this.text) ? this.text : '';
2312 if (!this.initial) {
2313 let items = this.detachChanges(this.itemData);
2314 let preItems;
2315 if (typeof this.previousItemData === 'string' ||
2316 typeof this.previousItemData === 'boolean' ||
2317 typeof this.previousItemData === 'number') {
2318 preItems = Object.defineProperties({}, {
2319 value: {
2320 value: this.previousItemData,
2321 enumerable: true
2322 },
2323 text: {
2324 value: this.previousItemData,
2325 enumerable: true
2326 }
2327 });
2328 }
2329 else {
2330 preItems = this.previousItemData;
2331 }
2332 this.setHiddenValue();
2333 let eventArgs = {
2334 e: eve,
2335 item: this.item,
2336 itemData: items,
2337 previousItem: this.previousSelectedLI,
2338 previousItemData: preItems,
2339 isInteracted: eve ? true : false,
2340 value: this.value,
2341 element: this.element
2342 };
2343 this.trigger('change', eventArgs);
2344 }
2345 if ((isNullOrUndefined(this.value) || this.value === '') && this.floatLabelType !== 'Always') {
2346 removeClass([this.inputWrapper.container], 'e-valid-input');
2347 }
2348 }
2349 setHiddenValue() {
2350 if (!isNullOrUndefined(this.value)) {
2351 this.hiddenElement.innerHTML = '<option selected>' + this.text + '</option>';
2352 let selectedElement = this.hiddenElement.querySelector('option');
2353 selectedElement.setAttribute('value', this.value.toString());
2354 }
2355 else {
2356 this.hiddenElement.innerHTML = '';
2357 }
2358 }
2359 /**
2360 * Filter bar implementation
2361 */
2362 onFilterUp(e) {
2363 if (this.isValidKey || e.keyCode === 40 || e.keyCode === 38) {
2364 this.isValidKey = false;
2365 switch (e.keyCode) {
2366 case 38: //up arrow
2367 case 40: //down arrow
2368 if (this.getModuleName() === 'autocomplete' && !this.isPopupOpen && !this.preventAltUp && !this.isRequested) {
2369 this.preventAutoFill = true;
2370 this.searchLists(e);
2371 }
2372 else {
2373 this.preventAutoFill = false;
2374 }
2375 this.preventAltUp = false;
2376 e.preventDefault();
2377 break;
2378 case 46: //delete
2379 case 8: //backspace
2380 this.typedString = this.filterInput.value;
2381 if (!this.isPopupOpen && this.typedString !== '' || this.isPopupOpen && this.queryString.length > 0) {
2382 this.preventAutoFill = true;
2383 this.searchLists(e);
2384 }
2385 else if (this.typedString === '' && this.queryString === '' && this.getModuleName() !== 'autocomplete') {
2386 this.preventAutoFill = true;
2387 this.searchLists(e);
2388 }
2389 else if (this.typedString === '') {
2390 this.resetFocusElement();
2391 this.activeIndex = null;
2392 if (this.getModuleName() === 'autocomplete') {
2393 this.hidePopup();
2394 }
2395 }
2396 e.preventDefault();
2397 break;
2398 default:
2399 this.typedString = this.filterInput.value;
2400 this.preventAutoFill = false;
2401 this.searchLists(e);
2402 break;
2403 }
2404 }
2405 else {
2406 this.isValidKey = false;
2407 }
2408 }
2409 onFilterDown(e) {
2410 switch (e.keyCode) {
2411 case 13: //enter
2412 break;
2413 case 40: //down arrow
2414 case 38: //up arrow
2415 this.queryString = this.filterInput.value;
2416 e.preventDefault();
2417 break;
2418 case 9: //tab
2419 if (this.isPopupOpen) {
2420 e.preventDefault();
2421 }
2422 break;
2423 default:
2424 this.prevSelectPoints = this.getSelectionPoints();
2425 this.queryString = this.filterInput.value;
2426 break;
2427 }
2428 }
2429 removeFillSelection() {
2430 if (this.isInteracted) {
2431 let selection = this.getSelectionPoints();
2432 this.inputElement.setSelectionRange(selection.end, selection.end);
2433 }
2434 }
2435 getQuery(query) {
2436 let filterQuery;
2437 if (!this.isCustomFilter && this.allowFiltering && this.filterInput) {
2438 filterQuery = query ? query.clone() : this.query ? this.query.clone() : new Query();
2439 let filterType = this.typedString === '' ? 'contains' : this.filterType;
2440 let dataType = this.typeOfData(this.dataSource).typeof;
2441 if (!(this.dataSource instanceof DataManager) && dataType === 'string' || dataType === 'number') {
2442 filterQuery.where('', filterType, this.typedString, this.ignoreCase, this.ignoreAccent);
2443 }
2444 else {
2445 let fields = (this.fields.text) ? this.fields.text : '';
2446 filterQuery.where(fields, filterType, this.typedString, this.ignoreCase, this.ignoreAccent);
2447 }
2448 }
2449 else {
2450 filterQuery = query ? query : this.query ? this.query : new Query();
2451 }
2452 return filterQuery;
2453 }
2454 getSelectionPoints() {
2455 let input = this.inputElement;
2456 return { start: Math.abs(input.selectionStart), end: Math.abs(input.selectionEnd) };
2457 }
2458 searchLists(e) {
2459 this.isTyped = true;
2460 this.activeIndex = null;
2461 if (this.filterInput.parentElement.querySelector('.' + dropDownListClasses.clearIcon)) {
2462 let clearElement = this.filterInput.parentElement.querySelector('.' + dropDownListClasses.clearIcon);
2463 clearElement.style.visibility = this.filterInput.value === '' ? 'hidden' : 'visible';
2464 }
2465 this.isDataFetched = false;
2466 if (this.isFiltering()) {
2467 if (this.isServerBlazor) {
2468 // tslint:disable-next-line
2469 this.interopAdaptor.invokeMethodAsync('OnServerFilter', this.filterInput.value);
2470 }
2471 else {
2472 let eventArgs = {
2473 preventDefaultAction: false,
2474 text: this.filterInput.value,
2475 updateData: (dataSource, query, fields) => {
2476 if (eventArgs.cancel) {
2477 return;
2478 }
2479 this.isCustomFilter = true;
2480 this.filteringAction(dataSource, query, fields);
2481 },
2482 baseEventArgs: e,
2483 cancel: false
2484 };
2485 this.trigger('filtering', eventArgs, (eventArgs) => {
2486 if (!eventArgs.cancel && !this.isCustomFilter && !eventArgs.preventDefaultAction) {
2487 this.filteringAction(this.dataSource, null, this.fields);
2488 }
2489 });
2490 }
2491 }
2492 }
2493 /**
2494 * To filter the data from given data source by using query
2495 * @param {Object[] | DataManager } dataSource - Set the data source to filter.
2496 * @param {Query} query - Specify the query to filter the data.
2497 * @param {FieldSettingsModel} fields - Specify the fields to map the column in the data table.
2498 * @return {void}.
2499 * @deprecated
2500 */
2501 filter(dataSource, query, fields) {
2502 this.isCustomFilter = true;
2503 this.filteringAction(dataSource, query, fields);
2504 }
2505 filteringAction(dataSource, query, fields) {
2506 if (!isNullOrUndefined(this.filterInput)) {
2507 this.beforePopupOpen = true;
2508 if (this.filterInput.value.trim() === '' && !this.itemTemplate) {
2509 this.actionCompleteData.isUpdated = false;
2510 this.isTyped = false;
2511 if (!isNullOrUndefined(this.actionCompleteData.ulElement) && !isNullOrUndefined(this.actionCompleteData.list)) {
2512 this.onActionComplete(this.actionCompleteData.ulElement, this.actionCompleteData.list);
2513 }
2514 this.isTyped = true;
2515 if (!isNullOrUndefined(this.itemData) && this.getModuleName() === 'dropdownlist') {
2516 this.focusIndexItem();
2517 this.setScrollPosition();
2518 }
2519 this.isNotSearchList = true;
2520 }
2521 else {
2522 this.isNotSearchList = false;
2523 query = (this.filterInput.value.trim() === '') ? null : query;
2524 this.resetList(dataSource, fields, query);
2525 }
2526 }
2527 }
2528 setSearchBox(popupElement) {
2529 if (this.isFiltering()) {
2530 let parentElement = popupElement.querySelector('.' + dropDownListClasses.filterParent) ?
2531 popupElement.querySelector('.' + dropDownListClasses.filterParent) : this.createElement('span', {
2532 className: dropDownListClasses.filterParent
2533 });
2534 if (this.isServerBlazor) {
2535 parentElement.innerHTML = '';
2536 }
2537 this.filterInput = this.createElement('input', {
2538 attrs: { type: 'text' },
2539 className: dropDownListClasses.filterInput
2540 });
2541 this.element.parentNode.insertBefore(this.filterInput, this.element);
2542 let backIcon = false;
2543 if (Browser.isDevice) {
2544 backIcon = true;
2545 }
2546 this.filterInputObj = Input.createInput({
2547 element: this.filterInput,
2548 buttons: backIcon ?
2549 [dropDownListClasses.backIcon, dropDownListClasses.filterBarClearIcon] : [dropDownListClasses.filterBarClearIcon],
2550 properties: { placeholder: this.filterBarPlaceholder }
2551 }, this.createElement);
2552 append([this.filterInputObj.container], parentElement);
2553 prepend([parentElement], popupElement);
2554 attributes(this.filterInput, {
2555 'aria-disabled': 'false',
2556 'aria-owns': this.element.id + '_options',
2557 'role': 'listbox',
2558 'aria-activedescendant': this.selectedLI ? this.selectedLI.id : null,
2559 'autocomplete': 'off',
2560 'autocorrect': 'off',
2561 'autocapitalize': 'off',
2562 'spellcheck': 'false'
2563 });
2564 this.clearIconElement = this.filterInput.parentElement.querySelector('.' + dropDownListClasses.clearIcon);
2565 if (!Browser.isDevice && this.clearIconElement) {
2566 EventHandler.add(this.clearIconElement, 'click', this.clearText, this);
2567 this.clearIconElement.style.visibility = 'hidden';
2568 }
2569 if (!Browser.isDevice) {
2570 this.searchKeyModule = new KeyboardEvents(this.filterInput, {
2571 keyAction: this.keyActionHandler.bind(this),
2572 keyConfigs: this.keyConfigure,
2573 eventName: 'keydown'
2574 });
2575 }
2576 else {
2577 this.searchKeyModule = new KeyboardEvents(this.filterInput, {
2578 keyAction: this.mobileKeyActionHandler.bind(this),
2579 keyConfigs: this.keyConfigure,
2580 eventName: 'keydown'
2581 });
2582 }
2583 EventHandler.add(this.filterInput, 'input', this.onInput, this);
2584 EventHandler.add(this.filterInput, 'keyup', this.onFilterUp, this);
2585 EventHandler.add(this.filterInput, 'keydown', this.onFilterDown, this);
2586 EventHandler.add(this.filterInput, 'blur', this.onBlur, this);
2587 return this.filterInputObj;
2588 }
2589 else {
2590 return inputObject;
2591 }
2592 }
2593 ;
2594 onInput(e) {
2595 this.isValidKey = true;
2596 // For filtering works in mobile firefox.
2597 if (Browser.isDevice && Browser.info.name === 'mozilla') {
2598 this.typedString = this.filterInput.value;
2599 this.preventAutoFill = true;
2600 this.searchLists(e);
2601 }
2602 }
2603 onActionFailure(e) {
2604 super.onActionFailure(e);
2605 if (this.beforePopupOpen) {
2606 this.renderPopup();
2607 }
2608 }
2609 onActionComplete(ulElement, list, e, isUpdated) {
2610 if (this.isNotSearchList) {
2611 this.isNotSearchList = false;
2612 return;
2613 }
2614 if (this.isActive) {
2615 let selectedItem = this.selectedLI ? this.selectedLI.cloneNode(true) : null;
2616 super.onActionComplete(ulElement, list, e);
2617 this.updateSelectElementData(this.allowFiltering);
2618 if (this.isRequested && !isNullOrUndefined(this.searchKeyEvent) && this.searchKeyEvent.type === 'keydown') {
2619 this.isRequested = false;
2620 this.keyActionHandler(this.searchKeyEvent);
2621 this.searchKeyEvent = null;
2622 }
2623 if (this.isRequested && !isNullOrUndefined(this.searchKeyEvent)) {
2624 this.incrementalSearch(this.searchKeyEvent);
2625 this.searchKeyEvent = null;
2626 }
2627 this.list.scrollTop = 0;
2628 if (!isNullOrUndefined(ulElement)) {
2629 attributes(ulElement, { 'id': this.element.id + '_options', 'role': 'listbox', 'aria-hidden': 'false' });
2630 }
2631 if (this.initRemoteRender) {
2632 this.initial = true;
2633 this.activeIndex = this.index;
2634 this.updateValues();
2635 this.initRemoteRender = false;
2636 this.initial = false;
2637 if (this.value && this.dataSource instanceof DataManager) {
2638 let checkField = isNullOrUndefined(this.fields.value) ? this.fields.text : this.fields.value;
2639 let checkVal = list.some((x) => x[checkField] === this.value);
2640 if (!checkVal) {
2641 this.dataSource.executeQuery(this.getQuery(this.query).where(new Predicate(checkField, 'equal', this.value)))
2642 .then((e) => {
2643 if (e.result.length > 0) {
2644 this.addItem(e.result, list.length);
2645 this.updateValues();
2646 }
2647 });
2648 }
2649 }
2650 }
2651 if (this.getModuleName() !== 'autocomplete' && this.isFiltering() && !this.isTyped) {
2652 if (!this.actionCompleteData.isUpdated || ((!this.isCustomFilter
2653 && !this.isFilterFocus)
2654 && ((this.dataSource instanceof DataManager)
2655 || (!isNullOrUndefined(this.dataSource) && !isNullOrUndefined(this.dataSource.length) &&
2656 this.dataSource.length !== 0)))) {
2657 this.actionCompleteData = { ulElement: ulElement.cloneNode(true), list: list, isUpdated: true };
2658 }
2659 this.addNewItem(list, selectedItem);
2660 if (!isNullOrUndefined(this.itemData)) {
2661 this.focusIndexItem();
2662 }
2663 }
2664 if (this.beforePopupOpen) {
2665 this.renderPopup();
2666 }
2667 }
2668 }
2669 addNewItem(listData, newElement) {
2670 if (!isNullOrUndefined(this.itemData) && !isNullOrUndefined(newElement)) {
2671 let value = this.getItemData().value;
2672 let isExist = listData.some((data) => {
2673 return (((typeof data === 'string' || typeof data === 'number') && data === value) ||
2674 (getValue(this.fields.value, data) === value));
2675 });
2676 if (!isExist) {
2677 this.addItem(this.itemData);
2678 }
2679 }
2680 }
2681 updateActionCompleteData(li, item) {
2682 if (this.getModuleName() !== 'autocomplete' && this.actionCompleteData.ulElement) {
2683 this.actionCompleteData.ulElement.appendChild(li.cloneNode(true));
2684 if (this.isFiltering() && this.actionCompleteData.list.indexOf(item) < 0) {
2685 this.actionCompleteData.list.push(item);
2686 }
2687 }
2688 }
2689 focusIndexItem() {
2690 let value = this.getItemData().value;
2691 this.activeIndex = this.getIndexByValue(value);
2692 let element = this.findListElement(this.list, 'li', 'data-value', value);
2693 this.selectedLI = element;
2694 this.activeItem(element);
2695 this.removeFocus();
2696 }
2697 updateSelection() {
2698 let selectedItem = this.list.querySelector('.' + dropDownBaseClasses.selected);
2699 if (selectedItem) {
2700 this.setProperties({ 'index': this.getIndexByValue(selectedItem.getAttribute('data-value')) });
2701 this.activeIndex = this.index;
2702 }
2703 else {
2704 this.removeFocus();
2705 this.list.querySelector('.' + dropDownBaseClasses.li).classList.add(dropDownListClasses.focus);
2706 }
2707 }
2708 removeFocus() {
2709 let highlightedItem = this.list.querySelectorAll('.' + dropDownListClasses.focus);
2710 if (highlightedItem && highlightedItem.length) {
2711 removeClass(highlightedItem, dropDownListClasses.focus);
2712 }
2713 }
2714 ;
2715 renderPopup() {
2716 if (this.popupObj && document.body.contains(this.popupObj.element)) {
2717 this.refreshPopup();
2718 return;
2719 }
2720 let args = { cancel: false };
2721 this.trigger('beforeOpen', args, (args) => {
2722 if (!args.cancel) {
2723 let popupEle = (this.serverPopupEle) ? this.serverPopupEle : this.createElement('div', {
2724 id: this.element.id + '_popup', className: 'e-ddl e-popup ' + (this.cssClass != null ? this.cssClass : '')
2725 });
2726 let searchBox = this.setSearchBox(popupEle);
2727 this.listHeight = formatUnit(this.popupHeight);
2728 if (this.headerTemplate && !this.isServerBlazor) {
2729 this.setHeaderTemplate(popupEle);
2730 }
2731 append([this.list], popupEle);
2732 if (this.footerTemplate && !this.isServerBlazor) {
2733 this.setFooterTemplate(popupEle);
2734 }
2735 if (this.isServerRendered && popupEle && popupEle.querySelector('.e-ddl-footer')) {
2736 popupEle.appendChild(popupEle.querySelector('.e-ddl-footer'));
2737 }
2738 document.body.appendChild(popupEle);
2739 this.updateServerPopup(popupEle);
2740 popupEle.style.visibility = 'hidden';
2741 if (this.popupHeight !== 'auto') {
2742 this.searchBoxHeight = 0;
2743 if (!isNullOrUndefined(searchBox.container)) {
2744 this.searchBoxHeight = (searchBox.container.parentElement).getBoundingClientRect().height;
2745 this.listHeight = (parseInt(this.listHeight, 10) - (this.searchBoxHeight)).toString() + 'px';
2746 }
2747 if (this.headerTemplate || (this.isServerRendered && popupEle && popupEle.querySelector('.e-ddl-header'))) {
2748 this.header = this.header ? this.header : popupEle.querySelector('.e-ddl-header');
2749 let height = Math.round(this.header.getBoundingClientRect().height);
2750 this.listHeight = (parseInt(this.listHeight, 10) - (height + this.searchBoxHeight)).toString() + 'px';
2751 }
2752 if (this.footerTemplate || (this.isServerRendered && popupEle && popupEle.querySelector('.e-ddl-footer'))) {
2753 this.footer = this.footer ? this.footer : popupEle.querySelector('.e-ddl-footer');
2754 let height = Math.round(this.footer.getBoundingClientRect().height);
2755 this.listHeight = (parseInt(this.listHeight, 10) - (height + this.searchBoxHeight)).toString() + 'px';
2756 }
2757 this.list.style.maxHeight = (parseInt(this.listHeight, 10) - 2).toString() + 'px'; // due to box-sizing property
2758 popupEle.style.maxHeight = formatUnit(this.popupHeight);
2759 }
2760 else {
2761 popupEle.style.height = 'auto';
2762 }
2763 let offsetValue = 0;
2764 let left;
2765 if (!isNullOrUndefined(this.selectedLI) && (!isNullOrUndefined(this.activeIndex) && this.activeIndex >= 0)) {
2766 this.setScrollPosition();
2767 }
2768 else {
2769 this.list.scrollTop = 0;
2770 }
2771 if (Browser.isDevice && (!this.allowFiltering && (this.getModuleName() === 'dropdownlist' ||
2772 (this.isDropDownClick && this.getModuleName() === 'combobox')))) {
2773 offsetValue = this.getOffsetValue(popupEle);
2774 let firstItem = this.isEmptyList() ? this.list : this.liCollections[0];
2775 left = -(parseInt(getComputedStyle(firstItem).textIndent, 10) -
2776 parseInt(getComputedStyle(this.inputElement).paddingLeft, 10) +
2777 parseInt(getComputedStyle(this.inputElement.parentElement).borderLeftWidth, 10));
2778 }
2779 this.getFocusElement();
2780 this.createPopup(popupEle, offsetValue, left);
2781 this.checkCollision(popupEle);
2782 if (Browser.isDevice) {
2783 this.popupObj.element.classList.add(dropDownListClasses.device);
2784 if (this.getModuleName() === 'dropdownlist' || (this.getModuleName() === 'combobox'
2785 && !this.allowFiltering && this.isDropDownClick)) {
2786 this.popupObj.collision = { X: 'fit', Y: 'fit' };
2787 }
2788 if (this.isFilterLayout()) {
2789 this.popupObj.element.classList.add(dropDownListClasses.mobileFilter);
2790 this.popupObj.position = { X: 0, Y: 0 };
2791 this.popupObj.dataBind();
2792 attributes(this.popupObj.element, { style: 'left:0px;right:0px;top:0px;bottom:0px;' });
2793 addClass([document.body, this.popupObj.element], dropDownListClasses.popupFullScreen);
2794 this.setSearchBoxPosition();
2795 this.backIconElement = searchBox.container.querySelector('.e-back-icon');
2796 this.clearIconElement = searchBox.container.querySelector('.' + dropDownListClasses.clearIcon);
2797 EventHandler.add(this.backIconElement, 'click', this.clickOnBackIcon, this);
2798 EventHandler.add(this.clearIconElement, 'click', this.clearText, this);
2799 }
2800 }
2801 popupEle.style.visibility = 'visible';
2802 addClass([popupEle], 'e-popup-close');
2803 let scrollParentElements = this.popupObj.getScrollableParent(this.inputWrapper.container);
2804 for (let element of scrollParentElements) {
2805 EventHandler.add(element, 'scroll', this.scrollHandler, this);
2806 }
2807 if (Browser.isDevice && this.isFilterLayout()) {
2808 EventHandler.add(this.list, 'scroll', this.listScroll, this);
2809 }
2810 attributes(this.targetElement(), { 'aria-expanded': 'true' });
2811 let inputParent = this.isFiltering() ? this.filterInput.parentElement : this.inputWrapper.container;
2812 addClass([inputParent], [dropDownListClasses.inputFocus]);
2813 let animModel = { name: 'FadeIn', duration: 100 };
2814 this.beforePopupOpen = true;
2815 let popupInstance = (isBlazor() && this.isServerRendered) ? null : this.popupObj;
2816 let eventArgs = { popup: popupInstance, cancel: false, animation: animModel };
2817 this.trigger('open', eventArgs, (eventArgs) => {
2818 if (!eventArgs.cancel) {
2819 this.serverBlazorUpdateSelection();
2820 this.bindServerScrollEvent();
2821 addClass([this.inputWrapper.container], [dropDownListClasses.iconAnimation]);
2822 this.popupObj.show(new Animation(eventArgs.animation), (this.zIndex === 1000) ? this.element : null);
2823 }
2824 else {
2825 this.beforePopupOpen = false;
2826 this.destroyPopup();
2827 }
2828 });
2829 }
2830 else {
2831 this.beforePopupOpen = false;
2832 }
2833 });
2834 }
2835 checkCollision(popupEle) {
2836 if (!Browser.isDevice || (Browser.isDevice && !(this.getModuleName() === 'dropdownlist' || this.isDropDownClick))) {
2837 let collision = isCollide(popupEle);
2838 if (collision.length > 0) {
2839 popupEle.style.marginTop = -parseInt(getComputedStyle(popupEle).marginTop, 10) + 'px';
2840 }
2841 }
2842 }
2843 serverBlazorUpdateSelection() {
2844 if (this.isServerBlazor && (this.value !== null || this.index !== null || this.text !== null)) {
2845 this.removeSelection();
2846 this.removeFocus();
2847 this.removeHover();
2848 this.updateValues();
2849 }
2850 }
2851 bindServerScrollEvent() {
2852 if (this.isServerBlazor && this.list) {
2853 if ((this.fields.groupBy) && !this.isGroupChecking) {
2854 EventHandler.remove(this.list, 'scroll', this.setFloatingHeader);
2855 EventHandler.add(this.list, 'scroll', this.setFloatingHeader, this);
2856 }
2857 }
2858 }
2859 updateServerPopup(popupEle) {
2860 if (this.isServerBlazor) {
2861 if (popupEle && popupEle.querySelector('li')) {
2862 removeClass([this.list], ['e-nodata']);
2863 }
2864 this.initial = false;
2865 popupEle.removeAttribute('style');
2866 }
2867 }
2868 getOffsetValue(popupEle) {
2869 let popupStyles = getComputedStyle(popupEle);
2870 let borderTop = parseInt(popupStyles.borderTopWidth, 10);
2871 let borderBottom = parseInt(popupStyles.borderBottomWidth, 10);
2872 return this.setPopupPosition(borderTop + borderBottom);
2873 }
2874 createPopup(element, offsetValue, left) {
2875 this.popupObj = new Popup(element, {
2876 width: this.setWidth(), targetType: 'relative',
2877 relateTo: this.inputWrapper.container, collision: { X: 'flip', Y: 'flip' }, offsetY: offsetValue,
2878 enableRtl: this.enableRtl, offsetX: left, position: { X: 'left', Y: 'bottom' },
2879 zIndex: this.zIndex,
2880 close: () => {
2881 if (!this.isDocumentClick) {
2882 this.focusDropDown();
2883 }
2884 let isResetItem = (this.getModuleName() === 'autocomplete') ? true : false;
2885 this.DropDownBaseresetBlazorTemplates(isResetItem, isResetItem, true, true, false, true, true);
2886 this.isNotSearchList = false;
2887 this.isDocumentClick = false;
2888 this.destroyPopup();
2889 let formElement = closest(this.inputElement, 'form');
2890 if (this.isFiltering() && formElement && this.actionCompleteData.list && this.actionCompleteData.list[0]) {
2891 this.isActive = true;
2892 this.onActionComplete(this.actionCompleteData.ulElement, this.actionCompleteData.list, null, true);
2893 }
2894 },
2895 open: () => {
2896 EventHandler.add(document, 'mousedown', this.onDocumentClick, this);
2897 this.isPopupOpen = true;
2898 let actionList = this.actionCompleteData && this.actionCompleteData.ulElement &&
2899 this.actionCompleteData.ulElement.querySelector('li');
2900 let ulElement = this.list.querySelector('ul li');
2901 if (this.isFiltering() && this.itemTemplate && (this.element.tagName === this.getNgDirective()) &&
2902 (actionList && ulElement && actionList.textContent !== ulElement.textContent)) {
2903 this.cloneElements();
2904 }
2905 if (this.isFilterLayout()) {
2906 removeClass([this.inputWrapper.container], [dropDownListClasses.inputFocus]);
2907 this.isFilterFocus = true;
2908 this.filterInput.focus();
2909 if (this.inputWrapper.clearButton) {
2910 addClass([this.inputWrapper.clearButton], dropDownListClasses.clearIconHide);
2911 }
2912 }
2913 this.activeStateChange();
2914 },
2915 targetExitViewport: () => {
2916 if (!Browser.isDevice) {
2917 this.hidePopup();
2918 }
2919 }
2920 });
2921 }
2922 isEmptyList() {
2923 return !isNullOrUndefined(this.liCollections) && this.liCollections.length === 0;
2924 }
2925 getFocusElement() {
2926 // combo-box used this method
2927 }
2928 isFilterLayout() {
2929 return this.getModuleName() === 'dropdownlist' && this.allowFiltering;
2930 }
2931 scrollHandler() {
2932 if (Browser.isDevice && ((this.getModuleName() === 'dropdownlist' &&
2933 !this.isFilterLayout()) || (this.getModuleName() === 'combobox' && !this.allowFiltering && this.isDropDownClick))) {
2934 this.hidePopup();
2935 }
2936 }
2937 setSearchBoxPosition() {
2938 let searchBoxHeight = this.filterInput.parentElement.getBoundingClientRect().height;
2939 this.popupObj.element.style.maxHeight = '100%';
2940 this.popupObj.element.style.width = '100%';
2941 this.list.style.maxHeight = (window.innerHeight - searchBoxHeight) + 'px';
2942 this.list.style.height = (window.innerHeight - searchBoxHeight) + 'px';
2943 let clearElement = this.filterInput.parentElement.querySelector('.' + dropDownListClasses.clearIcon);
2944 detach(this.filterInput);
2945 clearElement.parentElement.insertBefore(this.filterInput, clearElement);
2946 }
2947 setPopupPosition(border) {
2948 let offsetValue;
2949 let popupOffset = border;
2950 let selectedLI = this.list.querySelector('.' + dropDownListClasses.focus) || this.selectedLI;
2951 let firstItem = this.isEmptyList() ? this.list : this.liCollections[0];
2952 let lastItem = this.isEmptyList() ? this.list : this.liCollections[this.getItems().length - 1];
2953 let liHeight = firstItem.getBoundingClientRect().height;
2954 let listHeight = this.list.offsetHeight / 2;
2955 let height = isNullOrUndefined(selectedLI) ? firstItem.offsetTop : selectedLI.offsetTop;
2956 let lastItemOffsetValue = lastItem.offsetTop;
2957 if (lastItemOffsetValue - listHeight < height && !isNullOrUndefined(this.liCollections) &&
2958 this.liCollections.length > 0 && !isNullOrUndefined(selectedLI)) {
2959 let count = this.list.offsetHeight / liHeight;
2960 let paddingBottom = parseInt(getComputedStyle(this.list).paddingBottom, 10);
2961 offsetValue = (count - (this.liCollections.length - this.activeIndex)) * liHeight - popupOffset + paddingBottom;
2962 this.list.scrollTop = selectedLI.offsetTop;
2963 }
2964 else if (height > listHeight) {
2965 offsetValue = listHeight - liHeight / 2;
2966 this.list.scrollTop = height - listHeight + liHeight / 2;
2967 }
2968 else {
2969 offsetValue = height;
2970 }
2971 let inputHeight = this.inputWrapper.container.offsetHeight;
2972 offsetValue = offsetValue + liHeight + popupOffset - ((liHeight - inputHeight) / 2);
2973 return -offsetValue;
2974 }
2975 setWidth() {
2976 let width = formatUnit(this.popupWidth);
2977 if (width.indexOf('%') > -1) {
2978 let inputWidth = this.inputWrapper.container.offsetWidth * parseFloat(width) / 100;
2979 width = inputWidth.toString() + 'px';
2980 }
2981 if (Browser.isDevice && (!this.allowFiltering && (this.getModuleName() === 'dropdownlist' ||
2982 (this.isDropDownClick && this.getModuleName() === 'combobox')))) {
2983 let firstItem = this.isEmptyList() ? this.list : this.liCollections[0];
2984 width = (parseInt(width, 10) + (parseInt(getComputedStyle(firstItem).textIndent, 10) -
2985 parseInt(getComputedStyle(this.inputElement).paddingLeft, 10) +
2986 parseInt(getComputedStyle(this.inputElement.parentElement).borderLeftWidth, 10)) * 2) + 'px';
2987 }
2988 return width;
2989 }
2990 scrollBottom(isInitial) {
2991 if (!isNullOrUndefined(this.selectedLI)) {
2992 let currentOffset = this.list.offsetHeight;
2993 let nextBottom = this.selectedLI.offsetTop + this.selectedLI.offsetHeight - this.list.scrollTop;
2994 let nextOffset = this.list.scrollTop + nextBottom - currentOffset;
2995 nextOffset = isInitial ? nextOffset + parseInt(getComputedStyle(this.list).paddingTop, 10) * 2 : nextOffset;
2996 let boxRange = this.selectedLI.offsetTop + this.selectedLI.offsetHeight - this.list.scrollTop;
2997 boxRange = this.fields.groupBy && !isNullOrUndefined(this.fixedHeaderElement) ?
2998 boxRange - this.fixedHeaderElement.offsetHeight : boxRange;
2999 if (this.activeIndex === 0) {
3000 this.list.scrollTop = 0;
3001 }
3002 else if (nextBottom > currentOffset || !(boxRange > 0 && this.list.offsetHeight > boxRange)) {
3003 this.list.scrollTop = nextOffset;
3004 }
3005 }
3006 }
3007 scrollTop() {
3008 if (!isNullOrUndefined(this.selectedLI)) {
3009 let nextOffset = this.selectedLI.offsetTop - this.list.scrollTop;
3010 let nextBottom = this.selectedLI.offsetTop + this.selectedLI.offsetHeight - this.list.scrollTop;
3011 nextOffset = this.fields.groupBy && !isNullOrUndefined(this.fixedHeaderElement) ?
3012 nextOffset - this.fixedHeaderElement.offsetHeight : nextOffset;
3013 let boxRange = (this.selectedLI.offsetTop + this.selectedLI.offsetHeight - this.list.scrollTop);
3014 if (this.activeIndex === 0) {
3015 this.list.scrollTop = 0;
3016 }
3017 else if (nextOffset < 0) {
3018 this.list.scrollTop = this.list.scrollTop + nextOffset;
3019 }
3020 else if (!(boxRange > 0 && this.list.offsetHeight > boxRange)) {
3021 this.list.scrollTop = this.selectedLI.offsetTop - (this.fields.groupBy && !isNullOrUndefined(this.fixedHeaderElement) ?
3022 this.fixedHeaderElement.offsetHeight : 0);
3023 }
3024 }
3025 }
3026 isEditTextBox() {
3027 return false;
3028 }
3029 isFiltering() {
3030 return this.allowFiltering;
3031 }
3032 isPopupButton() {
3033 return true;
3034 }
3035 setScrollPosition(e) {
3036 if (!isNullOrUndefined(e)) {
3037 switch (e.action) {
3038 case 'pageDown':
3039 case 'down':
3040 case 'end':
3041 this.scrollBottom();
3042 break;
3043 default:
3044 this.scrollTop();
3045 break;
3046 }
3047 }
3048 else {
3049 this.scrollBottom(true);
3050 }
3051 }
3052 clearText() {
3053 this.filterInput.value = '';
3054 this.searchLists(null);
3055 }
3056 listScroll() {
3057 this.filterInput.blur();
3058 }
3059 setEleWidth(width) {
3060 if (!isNullOrUndefined(width)) {
3061 if (typeof width === 'number') {
3062 this.inputWrapper.container.style.width = formatUnit(width);
3063 }
3064 else if (typeof width === 'string') {
3065 this.inputWrapper.container.style.width = (width.match(/px|%|em/)) ? (width) : (formatUnit(width));
3066 }
3067 }
3068 }
3069 closePopup(delay) {
3070 this.isTyped = false;
3071 if (!(this.popupObj && document.body.contains(this.popupObj.element) && this.beforePopupOpen)) {
3072 return;
3073 }
3074 EventHandler.remove(document, 'mousedown', this.onDocumentClick);
3075 this.isActive = false;
3076 this.filterInputObj = null;
3077 this.isDropDownClick = false;
3078 this.preventAutoFill = false;
3079 let scrollableParentElements = this.popupObj.getScrollableParent(this.inputWrapper.container);
3080 for (let element of scrollableParentElements) {
3081 EventHandler.remove(element, 'scroll', this.scrollHandler);
3082 }
3083 if (Browser.isDevice && this.isFilterLayout()) {
3084 removeClass([document.body, this.popupObj.element], dropDownListClasses.popupFullScreen);
3085 EventHandler.remove(this.list, 'scroll', this.listScroll);
3086 }
3087 if (this.isFilterLayout()) {
3088 if (!Browser.isDevice) {
3089 this.searchKeyModule.destroy();
3090 if (this.clearIconElement) {
3091 EventHandler.remove(this.clearIconElement, 'click', this.clearText);
3092 }
3093 }
3094 if (this.backIconElement) {
3095 EventHandler.remove(this.backIconElement, 'click', this.clickOnBackIcon);
3096 EventHandler.remove(this.clearIconElement, 'click', this.clearText);
3097 }
3098 EventHandler.remove(this.filterInput, 'input', this.onInput);
3099 EventHandler.remove(this.filterInput, 'keyup', this.onFilterUp);
3100 EventHandler.remove(this.filterInput, 'keydown', this.onFilterDown);
3101 EventHandler.remove(this.filterInput, 'blur', this.onBlur);
3102 this.filterInput = null;
3103 }
3104 attributes(this.targetElement(), { 'aria-expanded': 'false', 'aria-activedescendant': null });
3105 this.inputWrapper.container.classList.remove(dropDownListClasses.iconAnimation);
3106 if (this.isFiltering()) {
3107 this.actionCompleteData.isUpdated = false;
3108 }
3109 this.beforePopupOpen = false;
3110 let animModel = {
3111 name: 'FadeOut',
3112 duration: 100,
3113 delay: delay ? delay : 0
3114 };
3115 let popupInstance = (isBlazor() && this.isServerRendered) ? null : this.popupObj;
3116 let eventArgs = { popup: popupInstance, cancel: false, animation: animModel };
3117 this.trigger('close', eventArgs, (eventArgs) => {
3118 if (!this.isServerBlazor && !isNullOrUndefined(this.popupObj) &&
3119 !isNullOrUndefined(this.popupObj.element.querySelector('.e-fixed-head'))) {
3120 let fixedHeader = this.popupObj.element.querySelector('.e-fixed-head');
3121 fixedHeader.parentNode.removeChild(fixedHeader);
3122 this.fixedHeaderElement = null;
3123 }
3124 if (!eventArgs.cancel) {
3125 if (this.getModuleName() === 'autocomplete') {
3126 this.rippleFun();
3127 }
3128 if (this.isPopupOpen) {
3129 this.popupObj.hide(new Animation(eventArgs.animation));
3130 }
3131 else {
3132 this.destroyPopup();
3133 }
3134 }
3135 });
3136 }
3137 destroyPopup() {
3138 if (this.isServerBlazor && this.serverPopupEle) {
3139 document.querySelector('#' + this.element.id + '_popup_holder').appendChild(this.serverPopupEle);
3140 }
3141 if (this.isServerBlazor) {
3142 // tslint:disable-next-line
3143 this.interopAdaptor.invokeMethodAsync('OnServerClosePopup');
3144 }
3145 this.isPopupOpen = false;
3146 this.isFilterFocus = false;
3147 this.popupObj.destroy();
3148 detach(this.popupObj.element);
3149 }
3150 clickOnBackIcon() {
3151 this.hidePopup();
3152 this.focusIn();
3153 }
3154 /**
3155 * To Initialize the control rendering
3156 * @private
3157 */
3158 // tslint:disable-next-line
3159 render() {
3160 if (this.isServerBlazor) {
3161 this.inputElement = this.element;
3162 this.inputWrapper = { container: this.element.parentElement };
3163 this.hiddenElement = this.inputWrapper.container.querySelector('select');
3164 this.inputWrapper.buttons = [this.inputWrapper.container.querySelector('.e-input-group-icon.e-ddl-icon')];
3165 if (this.showClearButton) {
3166 this.inputWrapper.clearButton = this.inputWrapper.container.querySelector('.e-clear-icon');
3167 Input.wireClearBtnEvents(this.element, this.inputWrapper.clearButton, this.inputWrapper.container);
3168 }
3169 Input.bindInitialEvent({
3170 element: this.element,
3171 buttons: null, customTag: null,
3172 floatLabelType: this.floatLabelType,
3173 properties: this.properties
3174 });
3175 this.setFields();
3176 this.wireEvent();
3177 this.tabIndex = this.element.hasAttribute('tabindex') ? this.element.getAttribute('tabindex') : '0';
3178 if (!this.enabled) {
3179 this.targetElement().tabIndex = -1;
3180 }
3181 if (this.element.hasAttribute('autofocus')) {
3182 this.focusIn();
3183 }
3184 }
3185 else {
3186 if (this.element.tagName === 'INPUT') {
3187 this.inputElement = this.element;
3188 if (isNullOrUndefined(this.inputElement.getAttribute('role'))) {
3189 this.inputElement.setAttribute('role', 'textbox');
3190 }
3191 if (isNullOrUndefined(this.inputElement.getAttribute('type'))) {
3192 this.inputElement.setAttribute('type', 'text');
3193 }
3194 }
3195 else {
3196 this.inputElement = this.createElement('input', { attrs: { role: 'textbox', type: 'text' } });
3197 if (this.element.tagName !== this.getNgDirective()) {
3198 this.element.style.display = 'none';
3199 }
3200 this.element.parentElement.insertBefore(this.inputElement, this.element);
3201 this.preventTabIndex(this.inputElement);
3202 }
3203 this.inputWrapper = Input.createInput({
3204 element: this.inputElement,
3205 buttons: this.isPopupButton() ? [dropDownListClasses.icon] : null,
3206 floatLabelType: this.floatLabelType,
3207 properties: {
3208 readonly: this.getModuleName() === 'dropdownlist' ? true : this.readonly,
3209 placeholder: this.placeholder,
3210 cssClass: this.cssClass,
3211 enabled: this.enabled,
3212 enableRtl: this.enableRtl,
3213 showClearButton: this.showClearButton
3214 },
3215 }, this.createElement);
3216 if (this.element.tagName === this.getNgDirective()) {
3217 this.element.appendChild(this.inputWrapper.container);
3218 }
3219 else {
3220 this.inputElement.parentElement.insertBefore(this.element, this.inputElement);
3221 }
3222 this.hiddenElement = this.createElement('select', {
3223 attrs: { 'aria-hidden': 'true', 'tabindex': '-1', 'class': dropDownListClasses.hiddenElement }
3224 });
3225 prepend([this.hiddenElement], this.inputWrapper.container);
3226 this.validationAttribute(this.element, this.hiddenElement);
3227 this.setFields();
3228 this.inputWrapper.container.style.width = formatUnit(this.width);
3229 this.inputWrapper.container.classList.add('e-ddl');
3230 this.wireEvent();
3231 this.tabIndex = this.element.hasAttribute('tabindex') ? this.element.getAttribute('tabindex') : '0';
3232 this.element.removeAttribute('tabindex');
3233 let id = this.element.getAttribute('id') ? this.element.getAttribute('id') : getUniqueID('ej2_dropdownlist');
3234 this.element.id = id;
3235 this.hiddenElement.id = id + '_hidden';
3236 this.targetElement().setAttribute('tabindex', this.tabIndex);
3237 attributes(this.targetElement(), this.getAriaAttributes());
3238 this.updateDataAttribute(this.htmlAttributes);
3239 this.setHTMLAttributes();
3240 if (this.value !== null || this.activeIndex !== null || this.text !== null) {
3241 this.initValue();
3242 }
3243 else if (this.element.tagName === 'SELECT' && this.element.options[0]) {
3244 let selectElement = this.element;
3245 this.value = selectElement.options[selectElement.selectedIndex].value;
3246 this.text = isNullOrUndefined(this.value) ? null : selectElement.options[selectElement.selectedIndex].textContent;
3247 this.initValue();
3248 }
3249 this.preventTabIndex(this.element);
3250 if (!this.enabled) {
3251 this.targetElement().tabIndex = -1;
3252 }
3253 this.initial = false;
3254 this.element.style.opacity = '';
3255 this.inputElement.onselect = (e) => { e.stopImmediatePropagation(); };
3256 this.inputElement.onchange = (e) => { e.stopImmediatePropagation(); };
3257 if (this.element.hasAttribute('autofocus')) {
3258 this.focusIn();
3259 }
3260 if (!isNullOrUndefined(this.text)) {
3261 this.inputElement.setAttribute('value', this.text);
3262 }
3263 }
3264 this.renderComplete();
3265 }
3266 ;
3267 setFooterTemplate(popupEle) {
3268 let compiledString;
3269 if (this.footer) {
3270 this.footer.innerHTML = '';
3271 }
3272 else {
3273 this.footer = this.createElement('div');
3274 addClass([this.footer], dropDownListClasses.footer);
3275 }
3276 compiledString = compile(this.footerTemplate);
3277 for (let item of compiledString({}, null, null, this.footerTemplateId, this.isStringTemplate)) {
3278 this.footer.appendChild(item);
3279 }
3280 this.DropDownBaseupdateBlazorTemplates(false, false, false, false, false, false, true);
3281 append([this.footer], popupEle);
3282 }
3283 setHeaderTemplate(popupEle) {
3284 let compiledString;
3285 if (this.header) {
3286 this.header.innerHTML = '';
3287 }
3288 else {
3289 this.header = this.createElement('div');
3290 addClass([this.header], dropDownListClasses.header);
3291 }
3292 compiledString = compile(this.headerTemplate);
3293 for (let item of compiledString({}, null, null, this.headerTemplateId, this.isStringTemplate)) {
3294 this.header.appendChild(item);
3295 }
3296 this.DropDownBaseupdateBlazorTemplates(false, false, false, false, false, true, false);
3297 let contentEle = popupEle.querySelector('div.e-content');
3298 popupEle.insertBefore(this.header, contentEle);
3299 }
3300 setOldText(text) {
3301 this.text = text;
3302 }
3303 setOldValue(value) {
3304 this.value = value;
3305 }
3306 refreshPopup() {
3307 if (!isNullOrUndefined(this.popupObj) && document.body.contains(this.popupObj.element) &&
3308 ((this.allowFiltering && !(Browser.isDevice && this.isFilterLayout())) || this.getModuleName() === 'autocomplete')) {
3309 removeClass([this.popupObj.element], 'e-popup-close');
3310 this.popupObj.refreshPosition(this.inputWrapper.container);
3311 }
3312 }
3313 checkDatasource(newProp) {
3314 if (newProp.dataSource && !isNullOrUndefined(Object.keys(newProp.dataSource)) && this.itemTemplate && this.allowFiltering) {
3315 this.list = null;
3316 this.actionCompleteData = { ulElement: null, list: null, isUpdated: false };
3317 }
3318 }
3319 updateDataSource(props) {
3320 if (this.inputElement.value !== '' || (!isNullOrUndefined(props) && (isNullOrUndefined(props.dataSource)
3321 || (!(props.dataSource instanceof DataManager) && props.dataSource.length === 0)))) {
3322 this.clearAll(null, props);
3323 }
3324 if (!(!isNullOrUndefined(props) && (isNullOrUndefined(props.dataSource)
3325 || (!(props.dataSource instanceof DataManager) && props.dataSource.length === 0)))) {
3326 this.resetList(this.dataSource);
3327 }
3328 if (!this.isCustomFilter && !this.isFilterFocus && document.activeElement !== this.filterInput) {
3329 this.checkCustomValue();
3330 }
3331 }
3332 checkCustomValue() {
3333 this.itemData = this.getDataByValue(this.value);
3334 let dataItem = this.getItemData();
3335 this.setProperties({ 'value': dataItem.value, 'text': dataItem.text });
3336 }
3337 updateInputFields() {
3338 if (this.getModuleName() === 'dropdownlist') {
3339 Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
3340 }
3341 }
3342 /**
3343 * Dynamically change the value of properties.
3344 * @private
3345 */
3346 onPropertyChanged(newProp, oldProp) {
3347 if (this.getModuleName() === 'dropdownlist') {
3348 if (!this.isServerBlazor) {
3349 this.checkDatasource(newProp);
3350 this.setUpdateInitial(['fields', 'query', 'dataSource'], newProp);
3351 }
3352 }
3353 for (let prop of Object.keys(newProp)) {
3354 switch (prop) {
3355 case 'query':
3356 case 'dataSource':
3357 break;
3358 case 'htmlAttributes':
3359 this.setHTMLAttributes();
3360 break;
3361 case 'width':
3362 this.setEleWidth(newProp.width);
3363 break;
3364 case 'placeholder':
3365 Input.setPlaceholder(newProp.placeholder, this.inputElement);
3366 break;
3367 case 'filterBarPlaceholder':
3368 if (this.filterInput) {
3369 Input.setPlaceholder(newProp.filterBarPlaceholder, this.filterInput);
3370 }
3371 break;
3372 case 'readonly':
3373 if (this.getModuleName() !== 'dropdownlist') {
3374 Input.setReadonly(newProp.readonly, this.inputElement);
3375 }
3376 break;
3377 case 'cssClass':
3378 this.setCssClass(newProp, oldProp);
3379 break;
3380 case 'enableRtl':
3381 this.setEnableRtl();
3382 break;
3383 case 'enabled':
3384 this.setEnable();
3385 break;
3386 case 'text':
3387 if (newProp.text === null) {
3388 this.clearAll();
3389 break;
3390 }
3391 if (!this.list) {
3392 if (this.dataSource instanceof DataManager) {
3393 this.initRemoteRender = true;
3394 }
3395 this.renderList();
3396 }
3397 if (!this.initRemoteRender) {
3398 let li = this.getElementByText(newProp.text);
3399 if (!this.checkValidLi(li)) {
3400 if (this.liCollections && this.liCollections.length === 100 &&
3401 this.getModuleName() === 'autocomplete' && this.listData.length > 100) {
3402 this.setSelectionData(newProp.text, oldProp.text, 'text');
3403 }
3404 else {
3405 this.setOldText(oldProp.text);
3406 }
3407 }
3408 this.updateInputFields();
3409 }
3410 break;
3411 case 'value':
3412 if (newProp.value === null) {
3413 this.clearAll();
3414 break;
3415 }
3416 this.notify('beforeValueChange', { newProp: newProp }); // gird component value type change
3417 if (!this.list) {
3418 if (this.dataSource instanceof DataManager) {
3419 this.initRemoteRender = true;
3420 }
3421 this.renderList();
3422 }
3423 if (!this.initRemoteRender) {
3424 let item = this.getElementByValue(newProp.value);
3425 if (!this.checkValidLi(item)) {
3426 if (this.liCollections && this.liCollections.length === 100 &&
3427 this.getModuleName() === 'autocomplete' && this.listData.length > 100) {
3428 this.setSelectionData(newProp.value, oldProp.value, 'value');
3429 }
3430 else {
3431 this.setOldValue(oldProp.value);
3432 }
3433 }
3434 this.updateInputFields();
3435 }
3436 break;
3437 case 'index':
3438 if (newProp.index === null) {
3439 this.clearAll();
3440 break;
3441 }
3442 if (!this.list) {
3443 if (this.dataSource instanceof DataManager) {
3444 this.initRemoteRender = true;
3445 }
3446 this.renderList();
3447 }
3448 if (!this.initRemoteRender) {
3449 let element = this.liCollections[newProp.index];
3450 if (!this.checkValidLi(element)) {
3451 if (this.liCollections && this.liCollections.length === 100 &&
3452 this.getModuleName() === 'autocomplete' && this.listData.length > 100) {
3453 this.setSelectionData(newProp.index, oldProp.index, 'index');
3454 }
3455 else {
3456 this.index = oldProp.index;
3457 }
3458 }
3459 this.updateInputFields();
3460 }
3461 break;
3462 case 'footerTemplate':
3463 if (this.popupObj) {
3464 this.setFooterTemplate(this.popupObj.element);
3465 }
3466 break;
3467 case 'headerTemplate':
3468 if (this.popupObj) {
3469 this.setHeaderTemplate(this.popupObj.element);
3470 }
3471 break;
3472 case 'valueTemplate':
3473 if (!isNullOrUndefined(this.itemData) && this.valueTemplate != null) {
3474 this.setValueTemplate();
3475 }
3476 break;
3477 case 'allowFiltering':
3478 if (this.allowFiltering) {
3479 this.actionCompleteData = { ulElement: this.ulElement,
3480 list: this.listData, isUpdated: true };
3481 this.updateSelectElementData(this.allowFiltering);
3482 }
3483 break;
3484 case 'floatLabelType':
3485 Input.removeFloating(this.inputWrapper);
3486 Input.addFloating(this.inputElement, newProp.floatLabelType, this.placeholder, this.createElement);
3487 break;
3488 case 'showClearButton':
3489 Input.setClearButton(newProp.showClearButton, this.inputElement, this.inputWrapper, null, this.createElement);
3490 this.bindClearEvent();
3491 break;
3492 default:
3493 let ddlProps;
3494 ddlProps = this.getPropObject(prop, newProp, oldProp);
3495 super.onPropertyChanged(ddlProps.newProperty, ddlProps.oldProperty);
3496 break;
3497 }
3498 }
3499 }
3500 checkValidLi(element) {
3501 if (this.isValidLI(element)) {
3502 this.setSelection(element, null);
3503 return true;
3504 }
3505 return false;
3506 }
3507 setSelectionData(newProp, oldProp, prop) {
3508 let li;
3509 this.updateListValues = () => {
3510 if (prop === 'text') {
3511 li = this.getElementByText(newProp);
3512 if (!this.checkValidLi(li)) {
3513 this.setOldText(oldProp);
3514 }
3515 }
3516 else if (prop === 'value') {
3517 li = this.getElementByValue(newProp);
3518 if (!this.checkValidLi(li)) {
3519 this.setOldValue(oldProp);
3520 }
3521 }
3522 else if (prop === 'index') {
3523 li = this.liCollections[newProp];
3524 if (!this.checkValidLi(li)) {
3525 this.index = oldProp;
3526 }
3527 }
3528 };
3529 }
3530 setCssClass(newProp, oldProp) {
3531 if (!isNullOrUndefined(oldProp.cssClass) && oldProp.cssClass !== '') {
3532 removeClass([this.inputWrapper.container], oldProp.cssClass.split(' '));
3533 }
3534 Input.setCssClass(newProp.cssClass, [this.inputWrapper.container]);
3535 if (this.popupObj) {
3536 if (!isNullOrUndefined(oldProp.cssClass) && oldProp.cssClass !== '') {
3537 removeClass([this.popupObj.element], oldProp.cssClass.split(' '));
3538 }
3539 if (!isNullOrUndefined(newProp.cssClass) && newProp.cssClass !== '') {
3540 addClass([this.popupObj.element], newProp.cssClass.split(' '));
3541 }
3542 }
3543 }
3544 /**
3545 * Return the module name.
3546 * @private
3547 */
3548 getModuleName() {
3549 return 'dropdownlist';
3550 }
3551 /**
3552 * Opens the popup that displays the list of items.
3553 * @returns void.
3554 */
3555 showPopup() {
3556 if (!this.enabled) {
3557 return;
3558 }
3559 if (isBlazor() && this.itemTemplate) {
3560 this.DropDownBaseupdateBlazorTemplates(true, false, false, false);
3561 }
3562 if (this.beforePopupOpen) {
3563 this.refreshPopup();
3564 return;
3565 }
3566 this.beforePopupOpen = true;
3567 if (this.isFiltering() && !this.isActive && this.actionCompleteData.list && this.actionCompleteData.list[0]) {
3568 this.isActive = true;
3569 this.onActionComplete(this.actionCompleteData.ulElement, this.actionCompleteData.list, null, true);
3570 }
3571 else if (isNullOrUndefined(this.list) || !isUndefined(this.list) && this.list.classList.contains(dropDownBaseClasses.noData)) {
3572 this.renderList();
3573 }
3574 else if (this.isFiltering() && this.isServerBlazor) {
3575 this.renderList();
3576 }
3577 if (!this.isServerBlazor) {
3578 this.invokeRenderPopup();
3579 }
3580 if (this.isServerBlazor && !isNullOrUndefined(this.list)) {
3581 this.invokeRenderPopup();
3582 }
3583 }
3584 invokeRenderPopup() {
3585 if (Browser.isDevice && this.isFilterLayout()) {
3586 let proxy = this;
3587 window.onpopstate = () => {
3588 proxy.hidePopup();
3589 };
3590 history.pushState({}, '');
3591 }
3592 if (!isNullOrUndefined(this.list.children[0]) || this.list.classList.contains(dropDownBaseClasses.noData)) {
3593 this.renderPopup();
3594 }
3595 attributes(this.targetElement(), { 'aria-activedescendant': this.selectedLI ? this.selectedLI.id : null });
3596 }
3597 clientRenderPopup(data, popupEle) {
3598 if (popupEle) {
3599 this.serverPopupEle = popupEle;
3600 this.list = popupEle.querySelector('.e-dropdownbase.e-content') ?
3601 popupEle.querySelector('.e-dropdownbase.e-content') : this.list;
3602 this.ulElement = this.list.querySelector('ul');
3603 this.liCollections = this.ulElement ?
3604 this.ulElement.querySelectorAll('.' + dropDownBaseClasses.li) : [];
3605 this.listData = data;
3606 this.initRemoteRender = false;
3607 this.serverBlazorUpdateSelection();
3608 this.wireListEvents();
3609 if (this.isServerIncrementalSearch && this.searchKeyEvent) {
3610 this.isServerIncrementalSearch = false;
3611 this.initial = false;
3612 this.onServerIncrementalSearch(this.searchKeyEvent);
3613 }
3614 if (this.beforePopupOpen) {
3615 this.invokeRenderPopup();
3616 }
3617 }
3618 else if (data != null && this.listData !== data) {
3619 this.listData = data;
3620 this.initRemoteRender = false;
3621 }
3622 }
3623 updateclientItemData(data) {
3624 this.listData = data;
3625 }
3626 serverUpdateListElement(data, popupEle) {
3627 this.listData = data;
3628 if (this.ulElement) {
3629 this.liCollections = this.ulElement.querySelectorAll('.' + dropDownBaseClasses.li);
3630 }
3631 }
3632 /**
3633 * Hides the popup if it is in an open state.
3634 * @returns void.
3635 */
3636 hidePopup() {
3637 let isHeader = (this.headerTemplate) ? true : false;
3638 let isFooter = (this.headerTemplate) ? true : false;
3639 this.DropDownBaseresetBlazorTemplates(false, false, false, false, false, isHeader, isFooter);
3640 if (this.isEscapeKey && this.getModuleName() === 'dropdownlist') {
3641 Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
3642 this.isEscapeKey = false;
3643 if (!isNullOrUndefined(this.index)) {
3644 let element = this.findListElement(this.ulElement, 'li', 'data-value', this.value);
3645 this.selectedLI = this.liCollections[this.index] || element;
3646 if (this.selectedLI) {
3647 this.updateSelectedItem(this.selectedLI, null, true);
3648 if (this.valueTemplate && this.itemData !== null) {
3649 this.setValueTemplate();
3650 }
3651 }
3652 }
3653 else {
3654 this.resetSelection();
3655 }
3656 }
3657 this.closePopup();
3658 let dataItem = this.getItemData();
3659 if (this.inputElement.value.trim() === '' && !this.isInteracted && (this.isSelectCustom ||
3660 !isNullOrUndefined(this.selectedLI) && this.inputElement.value !== dataItem.text)) {
3661 this.isSelectCustom = false;
3662 this.clearAll();
3663 }
3664 }
3665 /**
3666 * Sets the focus on the component for interaction.
3667 * @returns void.
3668 */
3669 focusIn(e) {
3670 if (!this.enabled) {
3671 return;
3672 }
3673 if (this.targetElement().classList.contains(dropDownListClasses.disable)) {
3674 return;
3675 }
3676 let isFocused = false;
3677 if (this.preventFocus && Browser.isDevice) {
3678 this.inputWrapper.container.tabIndex = 1;
3679 this.inputWrapper.container.focus();
3680 this.preventFocus = false;
3681 isFocused = true;
3682 }
3683 if (!isFocused) {
3684 this.targetElement().focus();
3685 }
3686 addClass([this.inputWrapper.container], [dropDownListClasses.inputFocus]);
3687 this.onFocus(e);
3688 }
3689 /**
3690 * Moves the focus from the component if the component is already focused.
3691 * @returns void.
3692 */
3693 focusOut() {
3694 if (!this.enabled) {
3695 return;
3696 }
3697 this.isTyped = true;
3698 this.hidePopup();
3699 this.targetElement().blur();
3700 removeClass([this.inputWrapper.container], [dropDownListClasses.inputFocus]);
3701 }
3702 /**
3703 * Removes the component from the DOM and detaches all its related event handlers. Also it removes the attributes and classes.
3704 * @method destroy
3705 * @return {void}.
3706 */
3707 destroy() {
3708 this.isActive = false;
3709 this.hidePopup();
3710 this.unWireEvent();
3711 if (this.list) {
3712 this.unWireListEvents();
3713 if (this.isServerBlazor) {
3714 if ((this.fields.groupBy) && !this.isGroupChecking) {
3715 EventHandler.remove(this.list, 'scroll', this.setFloatingHeader);
3716 }
3717 }
3718 }
3719 if (!this.isServerBlazor) {
3720 if (this.element && !this.element.classList.contains('e-' + this.getModuleName())) {
3721 return;
3722 }
3723 let attrArray = ['readonly', 'aria-disabled', 'aria-placeholder',
3724 'placeholder', 'aria-owns', 'aria-labelledby', 'aria-haspopup', 'aria-expanded',
3725 'aria-activedescendant', 'autocomplete', 'aria-readonly', 'autocorrect',
3726 'autocapitalize', 'spellcheck', 'aria-autocomplete', 'aria-live', 'aria-describedby', 'aria-label'];
3727 attrArray.forEach((value) => {
3728 this.inputElement.removeAttribute(value);
3729 });
3730 this.inputElement.setAttribute('tabindex', this.tabIndex);
3731 this.inputElement.classList.remove('e-input');
3732 Input.setValue('', this.inputElement, this.floatLabelType, this.showClearButton);
3733 this.element.style.display = 'block';
3734 if (this.inputWrapper.container.parentElement.tagName === this.getNgDirective()) {
3735 detach(this.inputWrapper.container);
3736 }
3737 else {
3738 this.inputWrapper.container.parentElement.insertBefore(this.element, this.inputWrapper.container);
3739 detach(this.inputWrapper.container);
3740 }
3741 super.destroy();
3742 }
3743 }
3744 ;
3745 /**
3746 * Gets all the list items bound on this component.
3747 * @returns Element[].
3748 */
3749 getItems() {
3750 if (!this.list) {
3751 if (this.dataSource instanceof DataManager) {
3752 this.initRemoteRender = true;
3753 }
3754 this.renderList();
3755 }
3756 return this.ulElement ? super.getItems() : [];
3757 }
3758 /**
3759 * Allows you to clear the selected values from the component.
3760 * @returns void.
3761 */
3762 clear() {
3763 this.value = null;
3764 }
3765};
3766__decorate$1([
3767 Property(null)
3768], DropDownList.prototype, "cssClass", void 0);
3769__decorate$1([
3770 Property('100%')
3771], DropDownList.prototype, "width", void 0);
3772__decorate$1([
3773 Property('300px')
3774], DropDownList.prototype, "popupHeight", void 0);
3775__decorate$1([
3776 Property('100%')
3777], DropDownList.prototype, "popupWidth", void 0);
3778__decorate$1([
3779 Property(null)
3780], DropDownList.prototype, "placeholder", void 0);
3781__decorate$1([
3782 Property(null)
3783], DropDownList.prototype, "filterBarPlaceholder", void 0);
3784__decorate$1([
3785 Property({})
3786], DropDownList.prototype, "htmlAttributes", void 0);
3787__decorate$1([
3788 Property(null)
3789], DropDownList.prototype, "query", void 0);
3790__decorate$1([
3791 Property(null)
3792], DropDownList.prototype, "valueTemplate", void 0);
3793__decorate$1([
3794 Property(null)
3795], DropDownList.prototype, "headerTemplate", void 0);
3796__decorate$1([
3797 Property(null)
3798], DropDownList.prototype, "footerTemplate", void 0);
3799__decorate$1([
3800 Property(false)
3801], DropDownList.prototype, "allowFiltering", void 0);
3802__decorate$1([
3803 Property(false)
3804], DropDownList.prototype, "readonly", void 0);
3805__decorate$1([
3806 Property(null)
3807], DropDownList.prototype, "text", void 0);
3808__decorate$1([
3809 Property(null)
3810], DropDownList.prototype, "value", void 0);
3811__decorate$1([
3812 Property(null)
3813], DropDownList.prototype, "index", void 0);
3814__decorate$1([
3815 Property('Never')
3816], DropDownList.prototype, "floatLabelType", void 0);
3817__decorate$1([
3818 Property(false)
3819], DropDownList.prototype, "showClearButton", void 0);
3820__decorate$1([
3821 Event()
3822], DropDownList.prototype, "filtering", void 0);
3823__decorate$1([
3824 Event()
3825], DropDownList.prototype, "change", void 0);
3826__decorate$1([
3827 Event()
3828], DropDownList.prototype, "beforeOpen", void 0);
3829__decorate$1([
3830 Event()
3831], DropDownList.prototype, "open", void 0);
3832__decorate$1([
3833 Event()
3834], DropDownList.prototype, "close", void 0);
3835__decorate$1([
3836 Event()
3837], DropDownList.prototype, "blur", void 0);
3838__decorate$1([
3839 Event()
3840], DropDownList.prototype, "focus", void 0);
3841DropDownList = __decorate$1([
3842 NotifyPropertyChanges
3843], DropDownList);
3844
3845/**
3846 * export all modules from current location
3847 */
3848
3849var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
3850 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3851 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3852 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3853 return c > 3 && r && Object.defineProperty(target, key, r), r;
3854};
3855/// <reference path='../drop-down-list/drop-down-list-model.d.ts'/>
3856/* tslint:disable */
3857/* tslint:enable */
3858const SPINNER_CLASS = 'e-atc-spinner-icon';
3859dropDownListClasses.root = 'e-combobox';
3860let inputObject$1 = {
3861 container: null,
3862 buttons: []
3863};
3864/**
3865 * The ComboBox component allows the user to type a value or choose an option from the list of predefined options.
3866 * ```html
3867 * <select id="list">
3868 * <option value='1'>Badminton</option>
3869 * <option value='2'>Basketball</option>
3870 * <option value='3'>Cricket</option>
3871 * <option value='4'>Football</option>
3872 * <option value='5'>Tennis</option>
3873 * </select>
3874 * ```
3875 * ```typescript
3876 * let games:ComboBox = new ComboBox();
3877 * games.appendTo("#list");
3878 * ```
3879 */
3880let ComboBox = class ComboBox extends DropDownList {
3881 /**
3882 * *Constructor for creating the component
3883 */
3884 constructor(options, element) {
3885 super(options, element);
3886 }
3887 ;
3888 /**
3889 * Initialize the event handler
3890 * @private
3891 */
3892 preRender() {
3893 super.preRender();
3894 }
3895 getLocaleName() {
3896 return 'combo-box';
3897 }
3898 ;
3899 wireEvent() {
3900 if (this.getModuleName() === 'combobox') {
3901 EventHandler.add(this.inputWrapper.buttons[0], 'mousedown', this.preventBlur, this);
3902 EventHandler.add(this.inputWrapper.container, 'blur', this.onBlur, this);
3903 }
3904 if (!isNullOrUndefined(this.inputWrapper.buttons[0])) {
3905 EventHandler.add(this.inputWrapper.buttons[0], 'mousedown', this.dropDownClick, this);
3906 }
3907 EventHandler.add(this.inputElement, 'focus', this.targetFocus, this);
3908 if (!this.readonly) {
3909 EventHandler.add(this.inputElement, 'input', this.onInput, this);
3910 EventHandler.add(this.inputElement, 'keyup', this.onFilterUp, this);
3911 EventHandler.add(this.inputElement, 'keydown', this.onFilterDown, this);
3912 }
3913 this.bindCommonEvent();
3914 }
3915 preventBlur(e) {
3916 if ((!this.allowFiltering && document.activeElement !== this.inputElement &&
3917 !document.activeElement.classList.contains(dropDownListClasses.input) && Browser.isDevice || !Browser.isDevice)) {
3918 e.preventDefault();
3919 }
3920 }
3921 onBlur(e) {
3922 let inputValue = this.inputElement.value === '' ? null : this.inputElement.value;
3923 if (!isNullOrUndefined(this.listData) && !isNullOrUndefined(inputValue) && inputValue !== this.text) {
3924 this.customValue();
3925 }
3926 super.onBlur(e);
3927 }
3928 targetElement() {
3929 return this.inputElement;
3930 }
3931 setOldText(text) {
3932 Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
3933 this.customValue();
3934 this.removeSelection();
3935 }
3936 setOldValue(value) {
3937 if (this.allowCustom) {
3938 this.valueMuteChange(this.value);
3939 }
3940 else {
3941 this.valueMuteChange(null);
3942 }
3943 this.removeSelection();
3944 this.setHiddenValue();
3945 }
3946 valueMuteChange(value) {
3947 let inputValue = isNullOrUndefined(value) ? null : value.toString();
3948 Input.setValue(inputValue, this.inputElement, this.floatLabelType, this.showClearButton);
3949 this.setProperties({ value: value, text: value, index: null }, true);
3950 this.activeIndex = this.index;
3951 let fields = this.fields;
3952 let dataItem = {};
3953 dataItem[fields.text] = isNullOrUndefined(value) ? null : value.toString();
3954 dataItem[fields.value] = isNullOrUndefined(value) ? null : value.toString();
3955 this.itemData = dataItem;
3956 this.item = null;
3957 if (this.previousValue !== this.value) {
3958 this.detachChangeEvent(null);
3959 }
3960 }
3961 updateValues() {
3962 if (!isNullOrUndefined(this.value)) {
3963 let li = this.getElementByValue(this.value);
3964 if (li) {
3965 this.setSelection(li, null);
3966 }
3967 else if (this.allowCustom) {
3968 this.valueMuteChange(this.value);
3969 }
3970 else {
3971 this.valueMuteChange(null);
3972 }
3973 }
3974 else if (this.text && isNullOrUndefined(this.value)) {
3975 let li = this.getElementByText(this.text);
3976 if (li) {
3977 this.setSelection(li, null);
3978 }
3979 else {
3980 Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
3981 this.customValue();
3982 }
3983 }
3984 else {
3985 this.setSelection(this.liCollections[this.activeIndex], null);
3986 }
3987 this.setHiddenValue();
3988 Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
3989 }
3990 updateIconState() {
3991 if (this.showClearButton) {
3992 if (this.inputElement.value !== '' && !this.readonly) {
3993 removeClass([this.inputWrapper.clearButton], dropDownListClasses.clearIconHide);
3994 }
3995 else {
3996 addClass([this.inputWrapper.clearButton], dropDownListClasses.clearIconHide);
3997 }
3998 }
3999 }
4000 getAriaAttributes() {
4001 let ariaAttributes = {
4002 'aria-owns': this.element.id + '_options',
4003 'role': 'combobox',
4004 'aria-autocomplete': 'both',
4005 'aria-labelledby': this.hiddenElement.id,
4006 'aria-hasPopup': 'true',
4007 'aria-expanded': 'false',
4008 'aria-readonly': this.readonly.toString(),
4009 'autocomplete': 'off',
4010 'autocorrect': 'off',
4011 'autocapitalize': 'off',
4012 'spellcheck': 'false'
4013 };
4014 return ariaAttributes;
4015 }
4016 searchLists(e) {
4017 this.isTyped = true;
4018 if (this.isFiltering()) {
4019 super.searchLists(e);
4020 if (this.filterInput.value.trim() === '') {
4021 this.setHoverList(this.ulElement.querySelector('.' + dropDownListClasses.li));
4022 }
4023 }
4024 else {
4025 if (this.ulElement && this.inputElement.value === '' && this.preventAutoFill) {
4026 this.setHoverList(this.ulElement.querySelector('.' + dropDownListClasses.li));
4027 }
4028 this.incrementalSearch(e);
4029 }
4030 }
4031 getNgDirective() {
4032 return 'EJS-COMBOBOX';
4033 }
4034 setSearchBox() {
4035 this.filterInput = this.inputElement;
4036 return (this.isFiltering() ? this.inputWrapper : inputObject$1);
4037 }
4038 onActionComplete(ulElement, list, e, isUpdated) {
4039 super.onActionComplete(ulElement, list, e);
4040 if (this.isSelectCustom) {
4041 this.removeSelection();
4042 }
4043 if (!this.preventAutoFill && this.getModuleName() === 'combobox' && this.isTyped) {
4044 this.inlineSearch();
4045 }
4046 }
4047 getFocusElement() {
4048 let dataItem = this.isSelectCustom ? { text: '' } : this.getItemData();
4049 let selected = this.list.querySelector('.' + dropDownListClasses.selected);
4050 let isSelected = dataItem.text === this.inputElement.value && !isNullOrUndefined(selected);
4051 if (isSelected) {
4052 return selected;
4053 }
4054 if ((Browser.isDevice && !this.isDropDownClick || !Browser.isDevice) &&
4055 !isNullOrUndefined(this.liCollections) && this.liCollections.length > 0) {
4056 let inputValue = this.inputElement.value;
4057 let activeItem = Search(inputValue, this.liCollections, 'StartsWith', true);
4058 let activeElement = activeItem.item;
4059 if (!isNullOrUndefined(activeElement)) {
4060 let count = this.getIndexByValue(activeElement.getAttribute('data-value')) - 1;
4061 let height = parseInt(getComputedStyle(this.liCollections[0], null).getPropertyValue('height'), 10);
4062 if (!isNaN(height) && this.getModuleName() !== 'autocomplete') {
4063 this.removeFocus();
4064 let fixedHead = this.fields.groupBy ? this.liCollections[0].offsetHeight : 0;
4065 this.list.scrollTop = count * height + fixedHead;
4066 addClass([activeElement], dropDownListClasses.focus);
4067 }
4068 }
4069 else {
4070 if (this.isSelectCustom && this.inputElement.value.trim() !== '') {
4071 this.removeFocus();
4072 this.list.scrollTop = 0;
4073 }
4074 }
4075 return activeElement;
4076 }
4077 else {
4078 return null;
4079 }
4080 }
4081 setValue(e) {
4082 if (e && e.type === 'keydown' && e.action === 'enter') {
4083 this.removeFillSelection();
4084 }
4085 if (this.autofill && this.getModuleName() === 'combobox' && e && e.type === 'keydown' && e.action !== 'enter') {
4086 this.preventAutoFill = false;
4087 this.inlineSearch(e);
4088 return false;
4089 }
4090 else {
4091 return super.setValue(e);
4092 }
4093 }
4094 checkCustomValue() {
4095 this.itemData = this.getDataByValue(this.value);
4096 let dataItem = this.getItemData();
4097 if (!(this.allowCustom && isNullOrUndefined(dataItem.value) && isNullOrUndefined(dataItem.text))) {
4098 this.setProperties({ 'value': dataItem.value, 'text': dataItem.text });
4099 }
4100 }
4101 /**
4102 * Shows the spinner loader.
4103 * @returns void.
4104 */
4105 showSpinner() {
4106 if (isNullOrUndefined(this.spinnerElement)) {
4107 this.spinnerElement = (this.getModuleName() === 'autocomplete') ? (this.inputWrapper.buttons[0] ||
4108 this.inputWrapper.clearButton ||
4109 Input.appendSpan('e-input-group-icon ' + SPINNER_CLASS, this.inputWrapper.container, this.createElement)) :
4110 (this.inputWrapper.buttons[0] || this.inputWrapper.clearButton);
4111 addClass([this.spinnerElement], dropDownListClasses.disableIcon);
4112 createSpinner({
4113 target: this.spinnerElement,
4114 width: Browser.isDevice ? '16px' : '14px'
4115 }, this.createElement);
4116 showSpinner(this.spinnerElement);
4117 }
4118 }
4119 /**
4120 * Hides the spinner loader.
4121 * @returns void.
4122 */
4123 hideSpinner() {
4124 if (!isNullOrUndefined(this.spinnerElement)) {
4125 hideSpinner(this.spinnerElement);
4126 removeClass([this.spinnerElement], dropDownListClasses.disableIcon);
4127 if (this.spinnerElement.classList.contains(SPINNER_CLASS)) {
4128 detach(this.spinnerElement);
4129 }
4130 else {
4131 this.spinnerElement.innerHTML = '';
4132 }
4133 this.spinnerElement = null;
4134 }
4135 }
4136 setAutoFill(activeElement, isHover) {
4137 if (!isHover) {
4138 this.setHoverList(activeElement);
4139 }
4140 if (this.autofill && !this.preventAutoFill) {
4141 let currentValue = this.getTextByValue(activeElement.getAttribute('data-value')).toString();
4142 let currentFillValue = this.getFormattedValue(activeElement.getAttribute('data-value'));
4143 if (this.getModuleName() === 'combobox') {
4144 if (!this.isSelected && this.previousValue !== currentFillValue) {
4145 this.updateSelectedItem(activeElement, null);
4146 this.isSelected = true;
4147 this.previousValue = this.getFormattedValue(activeElement.getAttribute('data-value'));
4148 }
4149 else {
4150 this.updateSelectedItem(activeElement, null, true);
4151 }
4152 }
4153 if (!this.isAndroidAutoFill(currentValue)) {
4154 this.setAutoFillSelection(currentValue);
4155 }
4156 }
4157 }
4158 isAndroidAutoFill(value) {
4159 if (Browser.isAndroid) {
4160 let currentPoints = this.getSelectionPoints();
4161 let prevEnd = this.prevSelectPoints.end;
4162 let curEnd = currentPoints.end;
4163 let prevStart = this.prevSelectPoints.start;
4164 let curStart = currentPoints.start;
4165 if (prevEnd !== 0 && ((prevEnd === value.length && prevStart === value.length) ||
4166 (prevStart > curStart && prevEnd > curEnd) || (prevEnd === curEnd && prevStart === curStart))) {
4167 return true;
4168 }
4169 else {
4170 return false;
4171 }
4172 }
4173 else {
4174 return false;
4175 }
4176 }
4177 clearAll(e, property) {
4178 if (isNullOrUndefined(property) || (!isNullOrUndefined(property) && isNullOrUndefined(property.dataSource))) {
4179 super.clearAll(e);
4180 }
4181 }
4182 isSelectFocusItem(element) {
4183 return !isNullOrUndefined(element);
4184 }
4185 inlineSearch(e) {
4186 let isKeyNavigate = (e && (e.action === 'down' || e.action === 'up' ||
4187 e.action === 'home' || e.action === 'end' || e.action === 'pageUp' || e.action === 'pageDown'));
4188 let activeElement = isKeyNavigate ? this.liCollections[this.activeIndex] : this.getFocusElement();
4189 if (!isNullOrUndefined(activeElement)) {
4190 if (!isKeyNavigate) {
4191 let value = this.getFormattedValue(activeElement.getAttribute('data-value'));
4192 this.activeIndex = this.getIndexByValue(value);
4193 this.activeIndex = !isNullOrUndefined(this.activeIndex) ? this.activeIndex : null;
4194 }
4195 this.preventAutoFill = this.inputElement.value === '' ? false : this.preventAutoFill;
4196 this.setAutoFill(activeElement, isKeyNavigate);
4197 }
4198 else if (this.inputElement.value === '') {
4199 this.activeIndex = null;
4200 this.list.scrollTop = 0;
4201 let focusItem = this.list.querySelector('.' + dropDownListClasses.li);
4202 this.setHoverList(focusItem);
4203 }
4204 else {
4205 this.activeIndex = null;
4206 this.removeSelection();
4207 if (this.liCollections && this.liCollections.length < 0) {
4208 this.removeFocus();
4209 }
4210 }
4211 }
4212 incrementalSearch(e) {
4213 this.showPopup();
4214 if (!isNullOrUndefined(this.listData)) {
4215 this.inlineSearch(e);
4216 e.preventDefault();
4217 }
4218 }
4219 ;
4220 setAutoFillSelection(currentValue) {
4221 let selection = this.getSelectionPoints();
4222 let value = this.inputElement.value.substr(0, selection.start);
4223 if (value && (value.toLowerCase() === currentValue.substr(0, selection.start).toLowerCase())) {
4224 let inputValue = value + currentValue.substr(value.length, currentValue.length);
4225 Input.setValue(inputValue, this.inputElement, this.floatLabelType, this.showClearButton);
4226 this.inputElement.setSelectionRange(selection.start, this.inputElement.value.length);
4227 }
4228 else {
4229 Input.setValue(currentValue, this.inputElement, this.floatLabelType, this.showClearButton);
4230 this.inputElement.setSelectionRange(0, this.inputElement.value.length);
4231 }
4232 }
4233 ;
4234 getValueByText(text) {
4235 return super.getValueByText(text, true, this.ignoreAccent);
4236 }
4237 unWireEvent() {
4238 if (this.getModuleName() === 'combobox') {
4239 EventHandler.remove(this.inputWrapper.buttons[0], 'mousedown', this.preventBlur);
4240 EventHandler.remove(this.inputWrapper.container, 'blur', this.onBlur);
4241 }
4242 if (!isNullOrUndefined(this.inputWrapper.buttons[0])) {
4243 EventHandler.remove(this.inputWrapper.buttons[0], 'mousedown', this.dropDownClick);
4244 }
4245 EventHandler.remove(this.inputElement, 'focus', this.targetFocus);
4246 if (!this.readonly) {
4247 EventHandler.remove(this.inputElement, 'input', this.onInput);
4248 EventHandler.remove(this.inputElement, 'keyup', this.onFilterUp);
4249 EventHandler.remove(this.inputElement, 'keydown', this.onFilterDown);
4250 }
4251 this.unBindCommonEvent();
4252 }
4253 setSelection(li, e) {
4254 super.setSelection(li, e);
4255 if (!isNullOrUndefined(li) && !this.autofill && !this.isDropDownClick) {
4256 this.removeFocus();
4257 }
4258 }
4259 selectCurrentItem(e) {
4260 let li;
4261 if (this.isPopupOpen) {
4262 li = this.list.querySelector('.' + dropDownListClasses.focus);
4263 if (li) {
4264 this.setSelection(li, e);
4265 this.isTyped = false;
4266 }
4267 if (this.isSelected) {
4268 this.isSelectCustom = false;
4269 this.onChangeEvent(e);
4270 }
4271 }
4272 if (e.action === 'enter' && this.inputElement.value.trim() === '') {
4273 this.clearAll(e);
4274 }
4275 else if (this.isTyped && !this.isSelected && isNullOrUndefined(li)) {
4276 this.customValue();
4277 }
4278 this.hidePopup();
4279 }
4280 setHoverList(li) {
4281 this.removeSelection();
4282 if (this.isValidLI(li) && !li.classList.contains(dropDownListClasses.selected)) {
4283 this.removeFocus();
4284 li.classList.add(dropDownListClasses.focus);
4285 }
4286 }
4287 ;
4288 targetFocus(e) {
4289 if (Browser.isDevice && !this.allowFiltering) {
4290 this.preventFocus = false;
4291 }
4292 this.onFocus();
4293 }
4294 dropDownClick(e) {
4295 e.preventDefault();
4296 if (Browser.isDevice && !this.allowFiltering) {
4297 this.preventFocus = true;
4298 }
4299 super.dropDownClick(e);
4300 }
4301 customValue() {
4302 let value = this.getValueByText(this.inputElement.value);
4303 if (!this.allowCustom && this.inputElement.value !== '') {
4304 let previousValue = this.previousValue;
4305 let currentValue = this.value;
4306 this.setProperties({ value: value });
4307 if (isNullOrUndefined(this.value)) {
4308 Input.setValue('', this.inputElement, this.floatLabelType, this.showClearButton);
4309 }
4310 if (this.autofill && previousValue === this.value && currentValue !== this.value) {
4311 this.onChangeEvent(null);
4312 }
4313 }
4314 else if (this.inputElement.value.trim() !== '') {
4315 let previousValue = this.value;
4316 if (isNullOrUndefined(value)) {
4317 let value = this.inputElement.value === '' ? null : this.inputElement.value;
4318 let eventArgs;
4319 eventArgs = { text: value, item: {} };
4320 if (!this.initial) {
4321 this.trigger('customValueSpecifier', eventArgs, (eventArgs) => {
4322 this.updateCustomValueCallback(value, eventArgs, previousValue);
4323 });
4324 }
4325 else {
4326 this.updateCustomValueCallback(value, eventArgs, previousValue);
4327 }
4328 }
4329 else {
4330 this.isSelectCustom = false;
4331 this.setProperties({ value: value });
4332 if (previousValue !== this.value) {
4333 this.onChangeEvent(null);
4334 }
4335 }
4336 }
4337 else if (this.allowCustom) {
4338 this.isSelectCustom = true;
4339 }
4340 }
4341 updateCustomValueCallback(value, eventArgs, previousValue) {
4342 let fields = this.fields;
4343 let item = eventArgs.item;
4344 let dataItem = {};
4345 if (item && getValue(fields.text, item) && getValue(fields.value, item)) {
4346 dataItem = item;
4347 }
4348 else {
4349 setValue(fields.text, value, dataItem);
4350 setValue(fields.value, value, dataItem);
4351 }
4352 this.itemData = dataItem;
4353 let changeData = {
4354 text: getValue(fields.text, this.itemData),
4355 value: getValue(fields.value, this.itemData),
4356 index: null
4357 };
4358 this.setProperties(changeData, true);
4359 this.setSelection(null, null);
4360 this.isSelectCustom = true;
4361 if (previousValue !== this.value) {
4362 this.onChangeEvent(null);
4363 }
4364 }
4365 /**
4366 * Dynamically change the value of properties.
4367 * @private
4368 */
4369 onPropertyChanged(newProp, oldProp) {
4370 if (this.getModuleName() === 'combobox') {
4371 this.setUpdateInitial(['fields', 'query', 'dataSource'], newProp);
4372 }
4373 for (let prop of Object.keys(newProp)) {
4374 switch (prop) {
4375 case 'readonly':
4376 Input.setReadonly(this.readonly, this.inputElement);
4377 if (this.readonly) {
4378 EventHandler.remove(this.inputElement, 'input', this.onInput);
4379 EventHandler.remove(this.inputElement, 'keyup', this.onFilterUp);
4380 EventHandler.remove(this.inputElement, 'keydown', this.onFilterDown);
4381 }
4382 else {
4383 EventHandler.add(this.inputElement, 'input', this.onInput, this);
4384 EventHandler.add(this.inputElement, 'keyup', this.onFilterUp, this);
4385 EventHandler.add(this.inputElement, 'keydown', this.onFilterDown, this);
4386 }
4387 break;
4388 case 'allowFiltering':
4389 this.setSearchBox();
4390 if (this.isFiltering() && this.getModuleName() === 'combobox' && isNullOrUndefined(this.list)) {
4391 super.renderList();
4392 }
4393 break;
4394 case 'allowCustom':
4395 break;
4396 default:
4397 let comboProps;
4398 comboProps = this.getPropObject(prop, newProp, oldProp);
4399 super.onPropertyChanged(comboProps.newProperty, comboProps.oldProperty);
4400 break;
4401 }
4402 }
4403 }
4404 /**
4405 * To initialize the control rendering.
4406 * @private
4407 */
4408 render() {
4409 super.render();
4410 this.setSearchBox();
4411 if (this.isFiltering() && this.getModuleName() === 'combobox' && isNullOrUndefined(this.list)) {
4412 super.renderList();
4413 }
4414 this.renderComplete();
4415 }
4416 ;
4417 /**
4418 * Return the module name of this component.
4419 * @private
4420 */
4421 getModuleName() {
4422 return 'combobox';
4423 }
4424 /**
4425 * Adds a new item to the combobox popup list. By default, new item appends to the list as the last item,
4426 * but you can insert based on the index parameter.
4427 * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
4428 * @param { number } itemIndex - Specifies the index to place the newly added item in the popup list.
4429 * @return {void}.
4430 */
4431 addItem(items, itemIndex) {
4432 super.addItem(items, itemIndex);
4433 }
4434 /**
4435 * To filter the data from given data source by using query
4436 * @param {Object[] | DataManager } dataSource - Set the data source to filter.
4437 * @param {Query} query - Specify the query to filter the data.
4438 * @param {FieldSettingsModel} fields - Specify the fields to map the column in the data table.
4439 * @return {void}.
4440 */
4441 filter(dataSource, query, fields) {
4442 super.filter(dataSource, query, fields);
4443 }
4444 /**
4445 * Hides the popup if it is in open state.
4446 * @returns void.
4447 */
4448 hidePopup() {
4449 let inputValue = this.inputElement.value === '' ? null : this.inputElement.value;
4450 if (!isNullOrUndefined(this.listData)) {
4451 let isEscape = this.isEscapeKey;
4452 if (this.isEscapeKey) {
4453 Input.setValue(this.typedString, this.inputElement, this.floatLabelType, this.showClearButton);
4454 this.isEscapeKey = false;
4455 }
4456 if (this.autofill) {
4457 this.removeFillSelection();
4458 }
4459 let dataItem = this.isSelectCustom ? { text: '' } : this.getItemData();
4460 let selected = this.list.querySelector('.' + dropDownListClasses.selected);
4461 if (dataItem.text === this.inputElement.value && !isNullOrUndefined(selected)) {
4462 if (this.isSelected) {
4463 this.onChangeEvent(null);
4464 this.isSelectCustom = false;
4465 }
4466 super.hidePopup();
4467 return;
4468 }
4469 if (this.getModuleName() === 'combobox' && this.inputElement.value.trim() !== '') {
4470 let searchItem = Search(this.inputElement.value, this.liCollections, 'Equal', true);
4471 this.selectedLI = searchItem.item;
4472 if (isNullOrUndefined(searchItem.index)) {
4473 searchItem.index = Search(this.inputElement.value, this.liCollections, 'StartsWith', true).index;
4474 }
4475 this.activeIndex = searchItem.index;
4476 if (!isNullOrUndefined(this.selectedLI)) {
4477 this.updateSelectedItem(this.selectedLI, null, true);
4478 }
4479 else if (isEscape) {
4480 this.isSelectCustom = true;
4481 this.removeSelection();
4482 }
4483 }
4484 if (!this.isEscapeKey && this.isTyped && !this.isInteracted) {
4485 this.customValue();
4486 }
4487 }
4488 if (isNullOrUndefined(this.listData) && this.allowCustom && !isNullOrUndefined(inputValue) && inputValue !== this.value) {
4489 this.customValue();
4490 }
4491 super.hidePopup();
4492 }
4493 /**
4494 * Sets the focus to the component for interaction.
4495 * @returns void.
4496 */
4497 focusIn() {
4498 if (!this.enabled) {
4499 return;
4500 }
4501 if (Browser.isDevice && !this.allowFiltering) {
4502 this.preventFocus = true;
4503 }
4504 super.focusIn();
4505 }
4506};
4507__decorate$2([
4508 Property(false)
4509], ComboBox.prototype, "autofill", void 0);
4510__decorate$2([
4511 Property(true)
4512], ComboBox.prototype, "allowCustom", void 0);
4513__decorate$2([
4514 Property({})
4515], ComboBox.prototype, "htmlAttributes", void 0);
4516__decorate$2([
4517 Property(false)
4518], ComboBox.prototype, "allowFiltering", void 0);
4519__decorate$2([
4520 Property(null)
4521], ComboBox.prototype, "query", void 0);
4522__decorate$2([
4523 Property(null)
4524], ComboBox.prototype, "index", void 0);
4525__decorate$2([
4526 Property(true)
4527], ComboBox.prototype, "showClearButton", void 0);
4528__decorate$2([
4529 Event()
4530], ComboBox.prototype, "customValueSpecifier", void 0);
4531__decorate$2([
4532 Event()
4533], ComboBox.prototype, "filtering", void 0);
4534__decorate$2([
4535 Property(null)
4536], ComboBox.prototype, "valueTemplate", void 0);
4537__decorate$2([
4538 Property('Never')
4539], ComboBox.prototype, "floatLabelType", void 0);
4540__decorate$2([
4541 Property(null)
4542], ComboBox.prototype, "filterBarPlaceholder", void 0);
4543__decorate$2([
4544 Complex({ text: null, value: null, iconCss: null, groupBy: null }, FieldSettings)
4545], ComboBox.prototype, "fields", void 0);
4546__decorate$2([
4547 Property(false)
4548], ComboBox.prototype, "enablePersistence", void 0);
4549__decorate$2([
4550 Property(null)
4551], ComboBox.prototype, "itemTemplate", void 0);
4552__decorate$2([
4553 Property(null)
4554], ComboBox.prototype, "groupTemplate", void 0);
4555__decorate$2([
4556 Property('No Records Found')
4557], ComboBox.prototype, "noRecordsTemplate", void 0);
4558__decorate$2([
4559 Property('The Request Failed')
4560], ComboBox.prototype, "actionFailureTemplate", void 0);
4561__decorate$2([
4562 Property('None')
4563], ComboBox.prototype, "sortOrder", void 0);
4564__decorate$2([
4565 Property(true)
4566], ComboBox.prototype, "enabled", void 0);
4567__decorate$2([
4568 Property([])
4569], ComboBox.prototype, "dataSource", void 0);
4570__decorate$2([
4571 Property('StartsWith')
4572], ComboBox.prototype, "filterType", void 0);
4573__decorate$2([
4574 Property(true)
4575], ComboBox.prototype, "ignoreCase", void 0);
4576__decorate$2([
4577 Property(1000)
4578], ComboBox.prototype, "zIndex", void 0);
4579__decorate$2([
4580 Property(false)
4581], ComboBox.prototype, "ignoreAccent", void 0);
4582__decorate$2([
4583 Property()
4584], ComboBox.prototype, "locale", void 0);
4585ComboBox = __decorate$2([
4586 NotifyPropertyChanges
4587], ComboBox);
4588
4589/**
4590 * export all modules from current location
4591 */
4592
4593var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
4594 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4595 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4596 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4597 return c > 3 && r && Object.defineProperty(target, key, r), r;
4598};
4599/// <reference path='../combo-box/combo-box-model.d.ts'/>
4600/* tslint:disable */
4601/* tslint:enable */
4602dropDownListClasses.root = 'e-autocomplete';
4603dropDownListClasses.icon = 'e-input-group-icon e-ddl-icon e-search-icon';
4604/**
4605 * The AutoComplete component provides the matched suggestion list when type into the input,
4606 * from which the user can select one.
4607 * ```html
4608 * <input id="list" type="text"/>
4609 * ```
4610 * ```typescript
4611 * let atcObj:AutoComplete = new AutoComplete();
4612 * atcObj.appendTo("#list");
4613 * ```
4614 */
4615let AutoComplete = class AutoComplete extends ComboBox {
4616 /**
4617 * * Constructor for creating the widget
4618 */
4619 constructor(options, element) {
4620 super(options, element);
4621 this.isFiltered = false;
4622 }
4623 ;
4624 /**
4625 * Initialize the event handler
4626 * @private
4627 */
4628 preRender() {
4629 super.preRender();
4630 }
4631 getLocaleName() {
4632 return 'auto-complete';
4633 }
4634 ;
4635 getNgDirective() {
4636 return 'EJS-AUTOCOMPLETE';
4637 }
4638 getQuery(query) {
4639 let filterQuery = query ? query.clone() : this.query ? this.query.clone() : new Query();
4640 let filterType = (this.queryString === '' && !isNullOrUndefined(this.value)) ? 'equal' : this.filterType;
4641 let queryString = (this.queryString === '' && !isNullOrUndefined(this.value)) ? this.value : this.queryString;
4642 if (this.isFiltered) {
4643 return filterQuery;
4644 }
4645 if (this.queryString !== null) {
4646 let dataType = this.typeOfData(this.dataSource).typeof;
4647 if (!(this.dataSource instanceof DataManager) && dataType === 'string' || dataType === 'number') {
4648 filterQuery.where('', filterType, queryString, this.ignoreCase, this.ignoreAccent);
4649 }
4650 else {
4651 let mapping = !isNullOrUndefined(this.fields.value) ? this.fields.value : '';
4652 filterQuery.where(mapping, filterType, queryString, this.ignoreCase, this.ignoreAccent);
4653 }
4654 }
4655 if (!isNullOrUndefined(this.suggestionCount)) {
4656 filterQuery.take(this.suggestionCount);
4657 }
4658 return filterQuery;
4659 }
4660 searchLists(e) {
4661 this.isTyped = true;
4662 this.isDataFetched = this.isSelectCustom = false;
4663 if (isNullOrUndefined(this.list)) {
4664 super.renderList(true);
4665 }
4666 this.queryString = this.filterInput.value;
4667 if (e.keyCode === 40 || e.keyCode === 38) {
4668 this.queryString = this.queryString === '' ? null : this.queryString;
4669 this.beforePopupOpen = true;
4670 this.resetList(this.dataSource, this.fields);
4671 return;
4672 }
4673 this.isSelected = false;
4674 this.activeIndex = null;
4675 let eventArgs = {
4676 preventDefaultAction: false,
4677 text: this.filterInput.value,
4678 updateData: (dataSource, query, fields) => {
4679 if (eventArgs.cancel) {
4680 return;
4681 }
4682 this.isFiltered = true;
4683 this.filterAction(dataSource, query, fields);
4684 },
4685 cancel: false
4686 };
4687 this.trigger('filtering', eventArgs, (eventArgs) => {
4688 if (!eventArgs.cancel && !this.isFiltered && !eventArgs.preventDefaultAction) {
4689 this.filterAction(this.dataSource, null, this.fields);
4690 }
4691 });
4692 }
4693 /**
4694 * To filter the data from given data source by using query
4695 * @param {Object[] | DataManager } dataSource - Set the data source to filter.
4696 * @param {Query} query - Specify the query to filter the data.
4697 * @param {FieldSettingsModel} fields - Specify the fields to map the column in the data table.
4698 * @return {void}.
4699 */
4700 filter(dataSource, query, fields) {
4701 this.isFiltered = true;
4702 this.filterAction(dataSource, query, fields);
4703 }
4704 filterAction(dataSource, query, fields) {
4705 this.beforePopupOpen = true;
4706 if (this.queryString !== '' && (this.queryString.length >= this.minLength)) {
4707 this.resetList(dataSource, fields, query);
4708 }
4709 else {
4710 this.hidePopup();
4711 }
4712 }
4713 clearAll(e, property) {
4714 if (isNullOrUndefined(property) || (!isNullOrUndefined(property) && isNullOrUndefined(property.dataSource))) {
4715 super.clearAll(e);
4716 }
4717 if (this.beforePopupOpen) {
4718 this.hidePopup();
4719 }
4720 }
4721 onActionComplete(ulElement, list, e, isUpdated) {
4722 this.fixedHeaderElement = null;
4723 super.onActionComplete(ulElement, list, e);
4724 let item = this.list.querySelector('.' + dropDownListClasses.li);
4725 if (!isNullOrUndefined(item)) {
4726 removeClass([item], dropDownListClasses.focus);
4727 }
4728 this.postBackAction();
4729 }
4730 postBackAction() {
4731 if (this.autofill && !isNullOrUndefined(this.liCollections[0])) {
4732 let items = [this.liCollections[0]];
4733 let searchItem = Search(this.inputElement.value, items, 'StartsWith', this.ignoreCase);
4734 if (!isNullOrUndefined(searchItem.item)) {
4735 super.setAutoFill(this.liCollections[0], true);
4736 }
4737 }
4738 }
4739 setSelection(li, e) {
4740 if (!this.isValidLI(li)) {
4741 return;
4742 }
4743 if (!isNullOrUndefined(e) && e.type === 'keydown' && e.action !== 'enter' && this.isValidLI(li)) {
4744 let value = this.getFormattedValue(li.getAttribute('data-value'));
4745 this.activeIndex = this.getIndexByValue(value);
4746 this.setHoverList(li);
4747 this.selectedLI = li;
4748 this.setScrollPosition(e);
4749 if (this.autofill) {
4750 this.preventAutoFill = false;
4751 super.setAutoFill(li);
4752 }
4753 attributes(this.inputElement, { 'aria-activedescendant': this.selectedLI ? this.selectedLI.id : null });
4754 }
4755 else {
4756 super.setSelection(li, e);
4757 }
4758 }
4759 listOption(dataSource, fieldsSettings) {
4760 let fields = super.listOption(dataSource, fieldsSettings);
4761 if (isNullOrUndefined(fields.itemCreated)) {
4762 fields.itemCreated = (e) => {
4763 if (this.highlight) {
4764 highlightSearch(e.item, this.queryString, this.ignoreCase, this.filterType);
4765 }
4766 };
4767 }
4768 else {
4769 let itemCreated = fields.itemCreated;
4770 fields.itemCreated = (e) => {
4771 if (this.highlight) {
4772 highlightSearch(e.item, this.queryString, this.ignoreCase, this.filterType);
4773 }
4774 itemCreated.apply(this, [e]);
4775 };
4776 }
4777 return fields;
4778 }
4779 ;
4780 isFiltering() {
4781 return true;
4782 }
4783 renderPopup() {
4784 this.list.scrollTop = 0;
4785 super.renderPopup();
4786 }
4787 isEditTextBox() {
4788 return true && this.inputElement.value.trim() !== '';
4789 }
4790 isPopupButton() {
4791 return this.showPopupButton;
4792 }
4793 isSelectFocusItem(element) {
4794 return false;
4795 }
4796 /**
4797 * Search the entered text and show it in the suggestion list if available.
4798 * @returns void.
4799 */
4800 showPopup() {
4801 if (!this.enabled) {
4802 return;
4803 }
4804 if (this.beforePopupOpen) {
4805 this.refreshPopup();
4806 return;
4807 }
4808 this.beforePopupOpen = true;
4809 this.preventAutoFill = true;
4810 if (isNullOrUndefined(this.list)) {
4811 this.renderList();
4812 }
4813 else {
4814 this.resetList(this.dataSource, this.fields);
4815 }
4816 }
4817 /**
4818 * Hides the popup if it is in open state.
4819 * @returns void.
4820 */
4821 hidePopup() {
4822 this.DropDownBaseresetBlazorTemplates(true, false, false, false);
4823 super.hidePopup();
4824 this.activeIndex = -1;
4825 }
4826 /**
4827 * Dynamically change the value of properties.
4828 * @private
4829 */
4830 onPropertyChanged(newProp, oldProp) {
4831 if (this.getModuleName() === 'autocomplete') {
4832 this.setUpdateInitial(['fields', 'query', 'dataSource'], newProp);
4833 }
4834 for (let prop of Object.keys(newProp)) {
4835 switch (prop) {
4836 case 'showPopupButton':
4837 if (this.showPopupButton) {
4838 let button = Input.appendSpan(dropDownListClasses.icon, this.inputWrapper.container, this.createElement);
4839 this.inputWrapper.buttons[0] = button;
4840 EventHandler.add(this.inputWrapper.buttons[0], 'click', this.dropDownClick, this);
4841 }
4842 else {
4843 detach(this.inputWrapper.buttons[0]);
4844 this.inputWrapper.buttons[0] = null;
4845 }
4846 break;
4847 default:
4848 let atcProps;
4849 atcProps = this.getPropObject(prop, newProp, oldProp);
4850 super.onPropertyChanged(atcProps.newProperty, atcProps.oldProperty);
4851 break;
4852 }
4853 }
4854 }
4855 /**
4856 * Return the module name of this component.
4857 * @private
4858 */
4859 getModuleName() {
4860 return 'autocomplete';
4861 }
4862 /**
4863 * To initialize the control rendering
4864 * @private
4865 */
4866 render() {
4867 super.render();
4868 }
4869 ;
4870};
4871__decorate$3([
4872 Complex({ value: null, iconCss: null, groupBy: null }, FieldSettings)
4873], AutoComplete.prototype, "fields", void 0);
4874__decorate$3([
4875 Property(true)
4876], AutoComplete.prototype, "ignoreCase", void 0);
4877__decorate$3([
4878 Property(false)
4879], AutoComplete.prototype, "showPopupButton", void 0);
4880__decorate$3([
4881 Property(false)
4882], AutoComplete.prototype, "highlight", void 0);
4883__decorate$3([
4884 Property(20)
4885], AutoComplete.prototype, "suggestionCount", void 0);
4886__decorate$3([
4887 Property({})
4888], AutoComplete.prototype, "htmlAttributes", void 0);
4889__decorate$3([
4890 Property(null)
4891], AutoComplete.prototype, "query", void 0);
4892__decorate$3([
4893 Property(1)
4894], AutoComplete.prototype, "minLength", void 0);
4895__decorate$3([
4896 Property('Contains')
4897], AutoComplete.prototype, "filterType", void 0);
4898__decorate$3([
4899 Event()
4900], AutoComplete.prototype, "filtering", void 0);
4901__decorate$3([
4902 Property(null)
4903], AutoComplete.prototype, "index", void 0);
4904__decorate$3([
4905 Property('Never')
4906], AutoComplete.prototype, "floatLabelType", void 0);
4907__decorate$3([
4908 Property(null)
4909], AutoComplete.prototype, "valueTemplate", void 0);
4910__decorate$3([
4911 Property(null)
4912], AutoComplete.prototype, "filterBarPlaceholder", void 0);
4913__decorate$3([
4914 Property(false)
4915], AutoComplete.prototype, "allowFiltering", void 0);
4916__decorate$3([
4917 Property(null)
4918], AutoComplete.prototype, "text", void 0);
4919AutoComplete = __decorate$3([
4920 NotifyPropertyChanges
4921], AutoComplete);
4922
4923/**
4924 * export all modules from current location
4925 */
4926
4927/**
4928 * FloatLable Moduel
4929 * Specifies whether to display the floating label above the input element.
4930 */
4931const FLOATLINE = 'e-float-line';
4932const FLOATTEXT = 'e-float-text';
4933const LABELTOP = 'e-label-top';
4934const LABELBOTTOM = 'e-label-bottom';
4935/**
4936 * Function to create Float Label element.
4937 * @param overAllWrapper - overall wrapper of multiselect.
4938 * @param element - the given html element.
4939 * @param inputElement - specify the input wrapper.
4940 * @param value - Value of the MultiSelect.
4941 * @param floatLabelType - Specify the FloatLabel Type.
4942 * @param placeholder - Specify the PlaceHolder text.
4943 */
4944function createFloatLabel(overAllWrapper, searchWrapper, element, inputElement, value, floatLabelType, placeholder) {
4945 let floatLinelement;
4946 let floatLabelElement;
4947 floatLinelement = createElement('span', { className: FLOATLINE });
4948 floatLabelElement = createElement('label', { className: FLOATTEXT });
4949 if (!isNullOrUndefined(element.id) && element.id !== '') {
4950 floatLabelElement.id = 'label_' + element.id.replace(/ /g, '_');
4951 attributes(element, { 'aria-labelledby': floatLabelElement.id });
4952 }
4953 if (!isNullOrUndefined(inputElement.placeholder) && inputElement.placeholder !== '') {
4954 floatLabelElement.innerHTML = inputElement.placeholder;
4955 inputElement.removeAttribute('placeholder');
4956 }
4957 floatLabelElement.innerHTML = placeholder;
4958 searchWrapper.appendChild(floatLinelement);
4959 searchWrapper.appendChild(floatLabelElement);
4960 overAllWrapper.classList.add('e-float-input');
4961 updateFloatLabelState(value, floatLabelElement);
4962 if (floatLabelType === 'Always') {
4963 if (floatLabelElement.classList.contains(LABELBOTTOM)) {
4964 removeClass([floatLabelElement], LABELBOTTOM);
4965 }
4966 addClass([floatLabelElement], LABELTOP);
4967 }
4968}
4969/**
4970 * Function to update status of the Float Label element.
4971 * @param value - Value of the MultiSelect.
4972 * @param label - float label element.
4973 */
4974function updateFloatLabelState(value, label) {
4975 if (value && value.length > 0) {
4976 addClass([label], LABELTOP);
4977 removeClass([label], LABELBOTTOM);
4978 }
4979 else {
4980 removeClass([label], LABELTOP);
4981 addClass([label], LABELBOTTOM);
4982 }
4983}
4984/**
4985 * Function to remove Float Label element.
4986 * @param overAllWrapper - overall wrapper of multiselect.
4987 * @param componentWrapper - wrapper element of multiselect.
4988 * @param searchWrapper - search wrapper of multiselect.
4989 * @param inputElement - specify the input wrapper.
4990 * @param value - Value of the MultiSelect.
4991 * @param floatLabelType - Specify the FloatLabel Type.
4992 * @param placeholder - Specify the PlaceHolder text.
4993 */
4994function removeFloating(overAllWrapper, componentWrapper, searchWrapper, inputElement, value, floatLabelType, placeholder) {
4995 let placeholderElement = componentWrapper.querySelector('.' + FLOATTEXT);
4996 let floatLine = componentWrapper.querySelector('.' + FLOATLINE);
4997 let placeholderText;
4998 if (!isNullOrUndefined(placeholderElement)) {
4999 placeholderText = placeholderElement.innerText;
5000 detach(searchWrapper.querySelector('.' + FLOATTEXT));
5001 setPlaceHolder(value, inputElement, placeholderText);
5002 if (!isNullOrUndefined(floatLine)) {
5003 detach(searchWrapper.querySelector('.' + FLOATLINE));
5004 }
5005 }
5006 else {
5007 placeholderText = (placeholder !== null) ? placeholder : '';
5008 setPlaceHolder(value, inputElement, placeholderText);
5009 }
5010 overAllWrapper.classList.remove('e-float-input');
5011}
5012/**
5013 * Function to set the placeholder to the element.
5014 * @param value - Value of the MultiSelect.
5015 * @param inputElement - specify the input wrapper.
5016 * @param placeholder - Specify the PlaceHolder text.
5017 */
5018function setPlaceHolder(value, inputElement, placeholder) {
5019 if (value && value.length) {
5020 inputElement.placeholder = '';
5021 }
5022 else {
5023 inputElement.placeholder = placeholder;
5024 }
5025}
5026/**
5027 * Function for focusing the Float Element.
5028 * @param overAllWrapper - overall wrapper of multiselect.
5029 * @param componentWrapper - wrapper element of multiselect.
5030 */
5031function floatLabelFocus(overAllWrapper, componentWrapper) {
5032 overAllWrapper.classList.add('e-input-focus');
5033 let label = componentWrapper.querySelector('.' + FLOATTEXT);
5034 if (!isNullOrUndefined(label)) {
5035 addClass([label], LABELTOP);
5036 if (label.classList.contains(LABELBOTTOM)) {
5037 removeClass([label], LABELBOTTOM);
5038 }
5039 }
5040}
5041/**
5042 * Function to focus the Float Label element.
5043 * @param overAllWrapper - overall wrapper of multiselect.
5044 * @param componentWrapper - wrapper element of multiselect.
5045 * @param value - Value of the MultiSelect.
5046 * @param floatLabelType - Specify the FloatLabel Type.
5047 * @param placeholder - Specify the PlaceHolder text.
5048 */
5049function floatLabelBlur(overAllWrapper, componentWrapper, value, floatLabelType, placeholder) {
5050 overAllWrapper.classList.remove('e-input-focus');
5051 let label = componentWrapper.querySelector('.' + FLOATTEXT);
5052 if (value && value.length <= 0 && floatLabelType === 'Auto' && !isNullOrUndefined(label)) {
5053 if (label.classList.contains(LABELTOP)) {
5054 removeClass([label], LABELTOP);
5055 }
5056 addClass([label], LABELBOTTOM);
5057 }
5058}
5059
5060var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
5061 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5062 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5063 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5064 return c > 3 && r && Object.defineProperty(target, key, r), r;
5065};
5066/// <reference path='../drop-down-base/drop-down-base-model.d.ts'/>
5067/* tslint:disable */
5068/* tslint:enable */
5069const FOCUS = 'e-input-focus';
5070const DISABLED = 'e-disabled';
5071const OVER_ALL_WRAPPER = 'e-multiselect e-input-group e-control-wrapper';
5072const ELEMENT_WRAPPER = 'e-multi-select-wrapper';
5073const ELEMENT_MOBILE_WRAPPER = 'e-mob-wrapper';
5074const HIDE_LIST = 'e-hide-listitem';
5075const DELIMITER_VIEW = 'e-delim-view';
5076const CHIP_WRAPPER = 'e-chips-collection';
5077const CHIP = 'e-chips';
5078const CHIP_CONTENT = 'e-chipcontent';
5079const CHIP_CLOSE = 'e-chips-close';
5080const CHIP_SELECTED = 'e-chip-selected';
5081const SEARCHBOX_WRAPPER = 'e-searcher';
5082const DELIMITER_VIEW_WRAPPER = 'e-delimiter';
5083const ZERO_SIZE = 'e-zero-size';
5084const REMAIN_WRAPPER = 'e-remain';
5085const CLOSEICON_CLASS = 'e-chips-close e-close-hooker';
5086const DELIMITER_WRAPPER = 'e-delim-values';
5087const POPUP_WRAPPER = 'e-ddl e-popup e-multi-select-list-wrapper';
5088const INPUT_ELEMENT = 'e-dropdownbase';
5089const RTL_CLASS = 'e-rtl';
5090const CLOSE_ICON_HIDE = 'e-close-icon-hide';
5091const MOBILE_CHIP = 'e-mob-chip';
5092const FOOTER = 'e-ddl-footer';
5093const HEADER = 'e-ddl-header';
5094const DISABLE_ICON = 'e-ddl-disable-icon';
5095const SPINNER_CLASS$1 = 'e-ms-spinner-icon';
5096const HIDDEN_ELEMENT = 'e-multi-hidden';
5097const destroy = 'destroy';
5098const dropdownIcon = 'e-input-group-icon e-ddl-icon';
5099const iconAnimation = 'e-icon-anim';
5100const TOTAL_COUNT_WRAPPER = 'e-delim-total';
5101const BOX_ELEMENT = 'e-multiselect-box';
5102const FILTERPARENT = 'e-filter-parent';
5103const CUSTOM_WIDTH = 'e-search-custom-width';
5104/**
5105 * The Multiselect allows the user to pick a more than one value from list of predefined values.
5106 * ```html
5107 * <select id="list">
5108 * <option value='1'>Badminton</option>
5109 * <option value='2'>Basketball</option>
5110 * <option value='3'>Cricket</option>
5111 * <option value='4'>Football</option>
5112 * <option value='5'>Tennis</option>
5113 * </select>
5114 * ```
5115 * ```typescript
5116 * <script>
5117 * var multiselectObj = new Multiselect();
5118 * multiselectObj.appendTo("#list");
5119 * </script>
5120 * ```
5121 */
5122let MultiSelect = class MultiSelect extends DropDownBase {
5123 /**
5124 * Constructor for creating the DropDownList widget.
5125 */
5126 constructor(option, element) {
5127 super(option, element);
5128 this.isValidKey = false;
5129 this.selectAllEventData = [];
5130 this.selectAllEventEle = [];
5131 this.scrollFocusStatus = false;
5132 this.keyDownStatus = false;
5133 }
5134 ;
5135 enableRTL(state) {
5136 if (state) {
5137 this.overAllWrapper.classList.add(RTL_CLASS);
5138 }
5139 else {
5140 this.overAllWrapper.classList.remove(RTL_CLASS);
5141 }
5142 if (this.popupObj) {
5143 this.popupObj.enableRtl = state;
5144 this.popupObj.dataBind();
5145 }
5146 }
5147 requiredModules() {
5148 let modules = [];
5149 if (this.mode === 'CheckBox') {
5150 this.isGroupChecking = this.enableGroupCheckBox;
5151 if (this.enableGroupCheckBox) {
5152 let prevOnChange = this.isProtectedOnChange;
5153 this.isProtectedOnChange = true;
5154 this.enableSelectionOrder = false;
5155 this.isProtectedOnChange = prevOnChange;
5156 }
5157 this.allowCustomValue = false;
5158 this.hideSelectedItem = false;
5159 this.closePopupOnSelect = false;
5160 modules.push({
5161 member: 'CheckBoxSelection',
5162 args: [this]
5163 });
5164 }
5165 return modules;
5166 }
5167 updateHTMLAttribute() {
5168 if (Object.keys(this.htmlAttributes).length) {
5169 for (let htmlAttr of Object.keys(this.htmlAttributes)) {
5170 switch (htmlAttr) {
5171 case 'class':
5172 this.overAllWrapper.classList.add(this.htmlAttributes[htmlAttr]);
5173 this.popupWrapper.classList.add(this.htmlAttributes[htmlAttr]);
5174 break;
5175 case 'disabled':
5176 this.enable(false);
5177 break;
5178 case 'placeholder':
5179 if (!this.placeholder) {
5180 this.inputElement.setAttribute(htmlAttr, this.htmlAttributes[htmlAttr]);
5181 this.setProperties({ placeholder: this.inputElement.placeholder }, true);
5182 this.refreshPlaceHolder();
5183 }
5184 break;
5185 default:
5186 let defaultAttr = ['id'];
5187 let validateAttr = ['name', 'required', 'aria-required', 'form'];
5188 let containerAttr = ['title', 'role', 'style', 'class'];
5189 if (defaultAttr.indexOf(htmlAttr) > -1) {
5190 this.element.setAttribute(htmlAttr, this.htmlAttributes[htmlAttr]);
5191 }
5192 else if (htmlAttr.indexOf('data') === 0 || validateAttr.indexOf(htmlAttr) > -1) {
5193 this.hiddenElement.setAttribute(htmlAttr, this.htmlAttributes[htmlAttr]);
5194 }
5195 else if (containerAttr.indexOf(htmlAttr) > -1) {
5196 this.overAllWrapper.setAttribute(htmlAttr, this.htmlAttributes[htmlAttr]);
5197 }
5198 else {
5199 this.inputElement.setAttribute(htmlAttr, this.htmlAttributes[htmlAttr]);
5200 }
5201 break;
5202 }
5203 }
5204 }
5205 }
5206 updateReadonly(state) {
5207 if (state || this.mode === 'CheckBox') {
5208 this.inputElement.setAttribute('readonly', 'true');
5209 }
5210 else {
5211 this.inputElement.removeAttribute('readonly');
5212 }
5213 }
5214 updateClearButton(state) {
5215 if (state) {
5216 if (this.overAllClear.parentNode) {
5217 this.overAllClear.style.display = '';
5218 }
5219 else {
5220 this.componentWrapper.appendChild(this.overAllClear);
5221 }
5222 this.componentWrapper.classList.remove(CLOSE_ICON_HIDE);
5223 }
5224 else {
5225 this.overAllClear.style.display = 'none';
5226 this.componentWrapper.classList.add(CLOSE_ICON_HIDE);
5227 }
5228 }
5229 updateCssClass() {
5230 if (!isNullOrUndefined(this.cssClass) && this.cssClass !== '') {
5231 addClass([this.overAllWrapper], this.cssClass.split(' '));
5232 addClass([this.popupWrapper], this.cssClass.split(' '));
5233 }
5234 }
5235 onPopupShown() {
5236 if (Browser.isDevice && (this.mode === 'CheckBox' && this.allowFiltering)) {
5237 let proxy = this;
5238 window.onpopstate = () => {
5239 proxy.hidePopup();
5240 proxy.inputElement.focus();
5241 };
5242 history.pushState({}, '');
5243 }
5244 let animModel = { name: 'FadeIn', duration: 100 };
5245 let eventArgs = { popup: this.popupObj, cancel: false, animation: animModel };
5246 this.trigger('open', eventArgs, (eventArgs) => {
5247 if (!eventArgs.cancel) {
5248 this.focusAtFirstListItem();
5249 document.body.appendChild(this.popupObj.element);
5250 if (this.mode === 'CheckBox' && this.enableGroupCheckBox && !isNullOrUndefined(this.fields.groupBy)) {
5251 this.updateListItems(this.list.querySelectorAll('li.e-list-item'), this.mainList.querySelectorAll('li.e-list-item'));
5252 }
5253 if (this.mode === 'CheckBox' || this.showDropDownIcon) {
5254 addClass([this.overAllWrapper], [iconAnimation]);
5255 }
5256 this.refreshPopup();
5257 this.popupObj.show(eventArgs.animation, (this.zIndex === 1000) ? this.element : null);
5258 attributes(this.inputElement, { 'aria-expanded': 'true' });
5259 if (this.isFirstClick) {
5260 this.loadTemplate();
5261 }
5262 }
5263 });
5264 }
5265 updateListItems(listItems, mainListItems) {
5266 for (let i = 0; i < listItems.length; i++) {
5267 this.findGroupStart(listItems[i]);
5268 this.findGroupStart(mainListItems[i]);
5269 }
5270 this.deselectHeader();
5271 }
5272 loadTemplate() {
5273 this.refreshListItems(null);
5274 if (this.mode === 'CheckBox') {
5275 this.removeFocus();
5276 }
5277 this.notify('reOrder', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', e: this });
5278 }
5279 setScrollPosition() {
5280 if (((!this.hideSelectedItem && this.mode !== 'CheckBox') || (this.mode === 'CheckBox' && !this.enableSelectionOrder)) &&
5281 (!isNullOrUndefined(this.value) && (this.value.length > 0))) {
5282 let valueEle = this.findListElement((this.hideSelectedItem ? this.ulElement : this.list), 'li', 'data-value', this.value[this.value.length - 1]);
5283 if (!isNullOrUndefined(valueEle)) {
5284 this.scrollBottom(valueEle);
5285 }
5286 }
5287 }
5288 focusAtFirstListItem() {
5289 if (this.ulElement && this.ulElement.querySelector('li.'
5290 + dropDownBaseClasses.li)) {
5291 let element;
5292 if (this.mode === 'CheckBox') {
5293 this.removeFocus();
5294 return;
5295 }
5296 else {
5297 element = this.ulElement.querySelector('li.'
5298 + dropDownBaseClasses.li + ':not(.'
5299 + HIDE_LIST + ')');
5300 }
5301 if (element !== null) {
5302 this.removeFocus();
5303 this.addListFocus(element);
5304 }
5305 }
5306 }
5307 focusAtLastListItem(data) {
5308 let activeElement;
5309 if (data) {
5310 activeElement = Search(data, this.liCollections, 'StartsWith', this.ignoreCase);
5311 }
5312 else {
5313 if (this.value && this.value.length) {
5314 Search(this.value[this.value.length - 1], this.liCollections, 'StartsWith', this.ignoreCase);
5315 }
5316 else {
5317 activeElement = null;
5318 }
5319 }
5320 if (activeElement && activeElement.item !== null) {
5321 this.addListFocus(activeElement.item);
5322 this.scrollBottom(activeElement.item, activeElement.index);
5323 }
5324 }
5325 getAriaAttributes() {
5326 let ariaAttributes = {
5327 'aria-disabled': 'false',
5328 'aria-owns': this.element.id + '_options',
5329 'role': 'listbox',
5330 'aria-multiselectable': 'true',
5331 'aria-activedescendant': 'null',
5332 'aria-haspopup': 'true',
5333 'aria-expanded': 'false'
5334 };
5335 return ariaAttributes;
5336 }
5337 updateListARIA() {
5338 attributes(this.ulElement, { 'id': this.element.id + '_options', 'role': 'listbox', 'aria-hidden': 'false' });
5339 let disableStatus = (this.inputElement.disabled) ? true : false;
5340 attributes(this.inputElement, this.getAriaAttributes());
5341 if (disableStatus) {
5342 attributes(this.inputElement, { 'aria-disabled': 'true' });
5343 }
5344 this.ensureAriaDisabled((disableStatus) ? 'true' : 'false');
5345 }
5346 ensureAriaDisabled(status) {
5347 if (this.htmlAttributes && this.htmlAttributes['aria-disabled']) {
5348 let attr = this.htmlAttributes;
5349 extend(attr, { 'aria-disabled': status }, attr);
5350 this.setProperties({ htmlAttributes: attr }, true);
5351 }
5352 }
5353 removelastSelection(e) {
5354 let elements;
5355 elements = this.chipCollectionWrapper.querySelectorAll('span.' + CHIP);
5356 let value = elements[elements.length - 1].getAttribute('data-value');
5357 if (!isNullOrUndefined(this.value)) {
5358 this.tempValues = this.value.slice();
5359 }
5360 this.removeValue(value, e);
5361 this.removeChipSelection();
5362 this.updateDelimeter(this.delimiterChar, e);
5363 this.makeTextBoxEmpty();
5364 if (this.mainList && this.listData) {
5365 this.refreshSelection();
5366 }
5367 this.checkPlaceholderSize();
5368 }
5369 onActionFailure(e) {
5370 super.onActionFailure(e);
5371 this.renderPopup();
5372 this.onPopupShown();
5373 }
5374 targetElement() {
5375 this.targetInputElement = this.inputElement;
5376 if (this.mode === 'CheckBox' && this.allowFiltering) {
5377 this.notify('targetElement', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox' });
5378 }
5379 return this.targetInputElement.value;
5380 }
5381 getForQuery(valuecheck) {
5382 let predicate;
5383 let field = isNullOrUndefined(this.fields.value) ? this.fields.text : this.fields.value;
5384 for (let i = 0; i < valuecheck.length; i++) {
5385 if (i === 0) {
5386 predicate = new Predicate(field, 'equal', valuecheck[i]);
5387 }
5388 else {
5389 predicate = predicate.or(field, 'equal', valuecheck[i]);
5390 }
5391 }
5392 return this.getQuery(this.query).where(predicate);
5393 }
5394 onActionComplete(ulElement, list, e, isUpdated) {
5395 super.onActionComplete(ulElement, list, e);
5396 this.updateSelectElementData(this.allowFiltering);
5397 let proxy = this;
5398 let valuecheck = [];
5399 if (!isNullOrUndefined(this.value) && !this.allowCustomValue) {
5400 for (let i = 0; i < this.value.length; i++) {
5401 let checkEle = this.findListElement(((this.allowFiltering && !isNullOrUndefined(this.mainList)) ? this.mainList : ulElement), 'li', 'data-value', proxy.value[i]);
5402 if (!checkEle) {
5403 valuecheck.push(proxy.value[i]);
5404 }
5405 }
5406 }
5407 if (valuecheck.length > 0 && this.dataSource instanceof DataManager && !isNullOrUndefined(this.value)) {
5408 this.dataSource.executeQuery(this.getForQuery(valuecheck)).then((e) => {
5409 proxy.addItem(e.result, list.length);
5410 proxy.updateActionList(ulElement, list, e);
5411 });
5412 }
5413 else {
5414 this.updateActionList(ulElement, list, e);
5415 }
5416 }
5417 updateActionList(ulElement, list, e, isUpdated) {
5418 if (this.mode === 'CheckBox' && this.showSelectAll) {
5419 this.notify('selectAll', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox' });
5420 }
5421 if (!this.mainList && !this.mainData) {
5422 this.mainList = ulElement.cloneNode ? ulElement.cloneNode(true) : ulElement;
5423 this.mainData = list;
5424 this.mainListCollection = this.liCollections;
5425 }
5426 else if (!isNullOrUndefined(this.mainData) && this.mainData.length === 0) {
5427 this.mainData = list;
5428 }
5429 if ((this.remoteCustomValue || list.length <= 0) && this.allowCustomValue && this.inputFocus && this.allowFiltering) {
5430 this.checkForCustomValue(this.tempQuery, this.fields);
5431 return;
5432 }
5433 if (this.value && this.value.length && ((this.mode !== 'CheckBox' && this.inputElement.value !== '') ||
5434 this.mode === 'CheckBox')) {
5435 this.refreshSelection();
5436 }
5437 this.updateListARIA();
5438 this.unwireListEvents();
5439 this.wireListEvents();
5440 if (!isNullOrUndefined(this.setInitialValue)) {
5441 this.setInitialValue();
5442 }
5443 if (!isNullOrUndefined(this.selectAllAction)) {
5444 this.selectAllAction();
5445 }
5446 if (this.setDynValue) {
5447 if (!isNullOrUndefined(this.text) && (isNullOrUndefined(this.value) || this.value.length === 0)) {
5448 this.initialTextUpdate();
5449 }
5450 this.initialValueUpdate();
5451 this.initialUpdate();
5452 this.refreshPlaceHolder();
5453 if (this.mode !== 'CheckBox' && this.changeOnBlur) {
5454 this.updateValueState(null, this.value, null);
5455 }
5456 }
5457 this.renderPopup();
5458 if (this.beforePopupOpen) {
5459 this.beforePopupOpen = false;
5460 this.onPopupShown();
5461 }
5462 }
5463 refreshSelection() {
5464 let value;
5465 let element;
5466 let className = this.hideSelectedItem ?
5467 HIDE_LIST :
5468 dropDownBaseClasses.selected;
5469 if (!isNullOrUndefined(this.value)) {
5470 for (let index = 0; !isNullOrUndefined(this.value[index]); index++) {
5471 value = this.value[index];
5472 element = this.findListElement(this.list, 'li', 'data-value', value);
5473 if (element) {
5474 addClass([element], className);
5475 if (this.hideSelectedItem && element.previousSibling
5476 && element.previousElementSibling.classList.contains(dropDownBaseClasses.group)
5477 && (!element.nextElementSibling ||
5478 element.nextElementSibling.classList.contains(dropDownBaseClasses.group))) {
5479 addClass([element.previousElementSibling], className);
5480 }
5481 if (this.hideSelectedItem && this.fields.groupBy && !element.previousElementSibling.classList.contains(HIDE_LIST)) {
5482 this.hideGroupItem(value);
5483 }
5484 if (this.hideSelectedItem && element.classList.contains(dropDownBaseClasses.focus)) {
5485 removeClass([element], dropDownBaseClasses.focus);
5486 let listEle = element.parentElement.querySelectorAll('.' +
5487 dropDownBaseClasses.li + ':not(.' + HIDE_LIST + ')');
5488 if (listEle.length > 0) {
5489 addClass([listEle[0]], dropDownBaseClasses.focus);
5490 }
5491 else {
5492 this.ulElement = this.ulElement.cloneNode ? this.ulElement.cloneNode(true) : this.ulElement;
5493 this.l10nUpdate();
5494 addClass([this.list], dropDownBaseClasses.noData);
5495 }
5496 }
5497 element.setAttribute('aria-selected', 'true');
5498 if (this.mode === 'CheckBox' && element.classList.contains('e-active')) {
5499 let ariaValue = element.firstElementChild.getAttribute('aria-checked');
5500 if (isNullOrUndefined(ariaValue) || ariaValue === 'false') {
5501 let args = {
5502 module: 'CheckBoxSelection',
5503 enable: this.mode === 'CheckBox',
5504 li: element,
5505 e: null
5506 };
5507 this.notify('updatelist', args);
5508 }
5509 }
5510 }
5511 }
5512 }
5513 this.checkSelectAll();
5514 this.checkMaxSelection();
5515 }
5516 hideGroupItem(value) {
5517 let element;
5518 let element1;
5519 let className = this.hideSelectedItem ?
5520 HIDE_LIST :
5521 dropDownBaseClasses.selected;
5522 element1 = element = this.findListElement(this.ulElement, 'li', 'data-value', value);
5523 let i = 0;
5524 let j = 0;
5525 let temp = true;
5526 let temp1 = true;
5527 do {
5528 if (element && element.previousElementSibling
5529 && (!element.previousElementSibling.classList.contains(HIDE_LIST) &&
5530 element.previousElementSibling.classList.contains(dropDownBaseClasses.li))) {
5531 temp = false;
5532 }
5533 if (!temp || !element || (element.previousElementSibling
5534 && element.previousElementSibling.classList.contains(dropDownBaseClasses.group))) {
5535 i = 10;
5536 }
5537 else {
5538 element = element.previousElementSibling;
5539 }
5540 if (element1 && element1.nextElementSibling
5541 && (!element1.nextElementSibling.classList.contains(HIDE_LIST) &&
5542 element1.nextElementSibling.classList.contains(dropDownBaseClasses.li))) {
5543 temp1 = false;
5544 }
5545 if (!temp1 || !element1 || (element1.nextElementSibling
5546 && element1.nextElementSibling.classList.contains(dropDownBaseClasses.group))) {
5547 j = 10;
5548 }
5549 else {
5550 element1 = element1.nextElementSibling;
5551 }
5552 } while (i < 10 || j < 10);
5553 if (temp && temp1 && !element.previousElementSibling.classList.contains(HIDE_LIST)) {
5554 addClass([element.previousElementSibling], className);
5555 }
5556 else if (temp && temp1 && element.previousElementSibling.classList.contains(HIDE_LIST)) {
5557 removeClass([element.previousElementSibling], className);
5558 }
5559 }
5560 checkSelectAll() {
5561 let groupItemLength = this.list.querySelectorAll('li.e-list-group-item.e-active').length;
5562 let listItem = this.list.querySelectorAll('li.e-list-item');
5563 let searchCount = this.list.querySelectorAll('li.' + dropDownBaseClasses.li).length;
5564 let searchActiveCount = this.list.querySelectorAll('li.' + dropDownBaseClasses.selected).length;
5565 if (this.enableGroupCheckBox && !isNullOrUndefined(this.fields.groupBy)) {
5566 searchActiveCount = searchActiveCount - groupItemLength;
5567 }
5568 if ((searchCount === searchActiveCount || searchActiveCount === this.maximumSelectionLength)
5569 && (this.mode === 'CheckBox' && this.showSelectAll)) {
5570 this.notify('checkSelectAll', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', value: 'check' });
5571 }
5572 else if ((searchCount !== searchActiveCount) && (this.mode === 'CheckBox' && this.showSelectAll)) {
5573 this.notify('checkSelectAll', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', value: 'uncheck' });
5574 }
5575 if (this.enableGroupCheckBox && this.fields.groupBy && !this.enableSelectionOrder) {
5576 for (let i = 0; i < listItem.length; i++) {
5577 this.findGroupStart(listItem[i]);
5578 }
5579 this.deselectHeader();
5580 }
5581 }
5582 openClick(e) {
5583 if (!this.openOnClick && this.mode !== 'CheckBox') {
5584 if (this.targetElement() !== '') {
5585 this.showPopup();
5586 }
5587 else {
5588 this.hidePopup();
5589 }
5590 }
5591 else if (!this.openOnClick && this.mode === 'CheckBox' && !this.isPopupOpen()) {
5592 this.showPopup();
5593 }
5594 }
5595 KeyUp(e) {
5596 if (this.mode === 'CheckBox' && !this.openOnClick) {
5597 let char = String.fromCharCode(e.keyCode);
5598 let isWordCharacter = char.match(/\w/);
5599 if (!isNullOrUndefined(isWordCharacter)) {
5600 this.isValidKey = true;
5601 }
5602 }
5603 this.isValidKey = (this.isPopupOpen() && e.keyCode === 8) || this.isValidKey;
5604 if (this.isValidKey) {
5605 this.isValidKey = false;
5606 this.expandTextbox();
5607 this.showOverAllClear();
5608 switch (e.keyCode) {
5609 default:
5610 // For filtering works in mobile firefox
5611 this.search(e);
5612 }
5613 }
5614 }
5615 /**
5616 * To filter the multiselect data from given data source by using query
5617 * @param {Object[] | DataManager } dataSource - Set the data source to filter.
5618 * @param {Query} query - Specify the query to filter the data.
5619 * @param {FieldSettingsModel} fields - Specify the fields to map the column in the data table.
5620 * @return {void}.
5621 */
5622 filter(dataSource, query, fields) {
5623 this.isFiltered = true;
5624 this.remoteFilterAction = true;
5625 this.dataUpdater(dataSource, query, fields);
5626 }
5627 getQuery(query) {
5628 let filterQuery = query ? query.clone() : this.query ? this.query.clone() : new Query();
5629 if (this.filterAction) {
5630 if (this.targetElement() !== null) {
5631 let dataType = this.typeOfData(this.dataSource).typeof;
5632 if (!(this.dataSource instanceof DataManager) && dataType === 'string' || dataType === 'number') {
5633 filterQuery.where('', this.filterType, this.targetElement(), this.ignoreCase, this.ignoreAccent);
5634 }
5635 else {
5636 let fields = this.fields;
5637 filterQuery.where(!isNullOrUndefined(fields.text) ? fields.text : '', this.filterType, this.targetElement(), this.ignoreCase, this.ignoreAccent);
5638 }
5639 }
5640 return filterQuery;
5641 }
5642 else {
5643 return query ? query : this.query ? this.query : new Query();
5644 }
5645 }
5646 dataUpdater(dataSource, query, fields) {
5647 this.isDataFetched = false;
5648 if (this.targetElement().trim() === '') {
5649 let list = this.mainList.cloneNode ? this.mainList.cloneNode(true) : this.mainList;
5650 if (this.backCommand) {
5651 this.remoteCustomValue = false;
5652 this.onActionComplete(list, this.mainData);
5653 if (this.value && this.value.length) {
5654 this.refreshSelection();
5655 }
5656 if (this.keyCode !== 8) {
5657 this.focusAtFirstListItem();
5658 }
5659 this.notify('reOrder', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', e: this });
5660 }
5661 }
5662 else {
5663 this.resetList(dataSource, fields, query);
5664 if (this.allowCustomValue) {
5665 if (!(dataSource instanceof DataManager)) {
5666 this.checkForCustomValue(query, fields);
5667 }
5668 else {
5669 this.remoteCustomValue = true;
5670 this.tempQuery = query;
5671 }
5672 }
5673 }
5674 this.refreshPopup();
5675 if (this.mode === 'CheckBox') {
5676 this.removeFocus();
5677 }
5678 }
5679 checkForCustomValue(query, fields) {
5680 let dataChecks = !this.getValueByText(this.inputElement.value, this.ignoreCase);
5681 if (this.allowCustomValue && dataChecks) {
5682 let value = this.inputElement.value;
5683 let field = fields ? fields : this.fields;
5684 let customData = (!isNullOrUndefined(this.mainData) && this.mainData.length > 0) ?
5685 this.mainData[0] : this.mainData;
5686 if (typeof (customData) !== 'string') {
5687 let dataItem = {};
5688 setValue(field.text, value, dataItem);
5689 setValue(field.value, value, dataItem);
5690 let tempData = JSON.parse(JSON.stringify(this.listData));
5691 tempData.splice(0, 0, dataItem);
5692 this.resetList(tempData, field, query);
5693 }
5694 else {
5695 let tempData = [this.inputElement.value];
5696 this.resetList(tempData, field);
5697 }
5698 }
5699 if (this.value && this.value.length) {
5700 this.refreshSelection();
5701 }
5702 }
5703 getNgDirective() {
5704 return 'EJS-MULTISELECT';
5705 }
5706 wrapperClick(e) {
5707 this.setDynValue = false;
5708 if (!this.enabled) {
5709 return;
5710 }
5711 if (e.target === this.overAllClear) {
5712 e.preventDefault();
5713 return;
5714 }
5715 if (!this.inputFocus) {
5716 this.inputElement.focus();
5717 }
5718 if (!this.readonly) {
5719 if (e.target && e.target.classList.toString().indexOf(CHIP_CLOSE) !== -1) {
5720 if (this.isPopupOpen()) {
5721 this.refreshPopup();
5722 }
5723 return;
5724 }
5725 if (!this.isPopupOpen() &&
5726 (this.openOnClick || (this.showDropDownIcon && e.target && e.target.className === dropdownIcon))) {
5727 this.showPopup();
5728 }
5729 else {
5730 this.hidePopup();
5731 if (this.mode === 'CheckBox') {
5732 this.showOverAllClear();
5733 this.inputFocus = true;
5734 if (!this.overAllWrapper.classList.contains(FOCUS)) {
5735 this.overAllWrapper.classList.add(FOCUS);
5736 }
5737 }
5738 }
5739 }
5740 e.preventDefault();
5741 }
5742 enable(state) {
5743 if (state) {
5744 this.overAllWrapper.classList.remove(DISABLED);
5745 this.inputElement.removeAttribute('disabled');
5746 attributes(this.inputElement, { 'aria-disabled': 'false' });
5747 this.ensureAriaDisabled('false');
5748 }
5749 else {
5750 this.overAllWrapper.classList.add(DISABLED);
5751 this.inputElement.setAttribute('disabled', 'true');
5752 attributes(this.inputElement, { 'aria-disabled': 'true' });
5753 this.ensureAriaDisabled('true');
5754 }
5755 if (this.enabled !== state) {
5756 this.enabled = state;
5757 }
5758 this.hidePopup();
5759 }
5760 onBlur(eve) {
5761 let target;
5762 if (!isNullOrUndefined(eve)) {
5763 target = eve.relatedTarget;
5764 }
5765 if (this.popupObj && document.body.contains(this.popupObj.element) && this.popupObj.element.contains(target)) {
5766 if (this.mode !== 'CheckBox') {
5767 this.inputElement.focus();
5768 }
5769 return;
5770 }
5771 if (this.mode === 'CheckBox' && Browser.isIE && !isNullOrUndefined(eve)) {
5772 this.inputFocus = false;
5773 this.overAllWrapper.classList.remove(FOCUS);
5774 return;
5775 }
5776 if (this.scrollFocusStatus) {
5777 if (!isNullOrUndefined(eve)) {
5778 eve.preventDefault();
5779 }
5780 this.inputElement.focus();
5781 this.scrollFocusStatus = false;
5782 return;
5783 }
5784 this.inputFocus = false;
5785 this.overAllWrapper.classList.remove(FOCUS);
5786 if (this.mode !== 'Box' && this.mode !== 'CheckBox') {
5787 this.refreshListItems(null);
5788 this.updateDelimView();
5789 }
5790 if (this.changeOnBlur) {
5791 this.updateValueState(eve, this.value, this.tempValues);
5792 this.dispatchEvent(this.hiddenElement, 'change');
5793 }
5794 this.overAllClear.style.display = 'none';
5795 if (this.isPopupOpen()) {
5796 this.DropDownBaseresetBlazorTemplates(false, false, true, true, false, true, true);
5797 this.hidePopup();
5798 }
5799 this.makeTextBoxEmpty();
5800 this.trigger('blur');
5801 this.focused = true;
5802 if (Browser.isDevice && this.mode !== 'Delimiter' && this.mode !== 'CheckBox') {
5803 this.removeChipFocus();
5804 }
5805 this.removeChipSelection();
5806 this.refreshInputHight();
5807 floatLabelBlur(this.overAllWrapper, this.componentWrapper, this.value, this.floatLabelType, this.placeholder);
5808 this.refreshPlaceHolder();
5809 if ((this.allowFiltering || (this.enableSelectionOrder === true && this.mode === 'CheckBox'))
5810 && !isNullOrUndefined(this.mainList)) {
5811 this.ulElement = this.mainList;
5812 }
5813 this.checkPlaceholderSize();
5814 }
5815 checkPlaceholderSize() {
5816 if (this.showDropDownIcon) {
5817 let downIconWidth = this.dropIcon.offsetWidth +
5818 parseInt(window.getComputedStyle(this.dropIcon).marginRight, 10);
5819 this.setPlaceholderSize(downIconWidth);
5820 }
5821 }
5822 setPlaceholderSize(downIconWidth) {
5823 if (isNullOrUndefined(this.value) || this.value.length === 0) {
5824 if (this.dropIcon.offsetWidth !== 0) {
5825 this.searchWrapper.style.width = ('calc(100% - ' + (downIconWidth + 10)) + 'px';
5826 }
5827 else {
5828 addClass([this.searchWrapper], CUSTOM_WIDTH);
5829 }
5830 }
5831 else if (!isNullOrUndefined(this.value)) {
5832 this.searchWrapper.removeAttribute('style');
5833 removeClass([this.searchWrapper], CUSTOM_WIDTH);
5834 }
5835 }
5836 refreshInputHight() {
5837 if ((!this.value || !this.value.length) && (isNullOrUndefined(this.text) || this.text === '')) {
5838 this.searchWrapper.classList.remove(ZERO_SIZE);
5839 }
5840 else {
5841 this.searchWrapper.classList.add(ZERO_SIZE);
5842 }
5843 }
5844 validateValues(newValue, oldValue) {
5845 return JSON.stringify(newValue.slice().sort()) !== JSON.stringify(oldValue.slice().sort());
5846 }
5847 updateValueState(event, newVal, oldVal) {
5848 let newValue = newVal ? newVal : [];
5849 let oldValue = oldVal ? oldVal : [];
5850 if (this.initStatus && this.validateValues(newValue, oldValue)) {
5851 let eventArgs = {
5852 e: event,
5853 oldValue: oldVal,
5854 value: newVal,
5855 isInteracted: event ? true : false,
5856 element: this.element
5857 };
5858 this.trigger('change', eventArgs);
5859 this.updateTempValue();
5860 if (!this.changeOnBlur) {
5861 this.dispatchEvent(this.hiddenElement, 'change');
5862 }
5863 }
5864 }
5865 updateTempValue() {
5866 if (!this.value) {
5867 this.tempValues = this.value;
5868 }
5869 else {
5870 this.tempValues = this.value.slice();
5871 }
5872 }
5873 getPagingCount() {
5874 let height = this.list.classList.contains(dropDownBaseClasses.noData) ? null :
5875 getComputedStyle(this.getItems()[0], null).getPropertyValue('height');
5876 return Math.round(this.list.offsetHeight / parseInt(height, 10));
5877 }
5878 pageUpSelection(steps) {
5879 let collection = this.list.querySelectorAll('li.'
5880 + dropDownBaseClasses.li + ':not(.' + HIDE_LIST + ')' + ':not(.e-reorder-hide)');
5881 let previousItem;
5882 previousItem = steps >= 0 ? collection[steps + 1] : collection[0];
5883 this.addListFocus(previousItem);
5884 this.scrollBottom(previousItem, this.getIndexByValue(previousItem.getAttribute('data-value')));
5885 }
5886 ;
5887 pageDownSelection(steps) {
5888 let list = this.getItems();
5889 let collection = this.list.querySelectorAll('li.'
5890 + dropDownBaseClasses.li + ':not(.' + HIDE_LIST + ')' + ':not(.e-reorder-hide)');
5891 let previousItem;
5892 previousItem = steps <= collection.length ? collection[steps - 1] : collection[collection.length - 1];
5893 this.addListFocus(previousItem);
5894 this.scrollBottom(previousItem, this.getIndexByValue(previousItem.getAttribute('data-value')));
5895 }
5896 getItems() {
5897 if (!this.list) {
5898 super.render();
5899 }
5900 return this.ulElement ? (this.ulElement.querySelectorAll('.' + dropDownBaseClasses.li).length > 0 &&
5901 this.ulElement.querySelectorAll('.' + dropDownBaseClasses.li
5902 + ':not(.' + HIDE_LIST + ')')) : null;
5903 }
5904 focusInHandler(e) {
5905 if (this.enabled) {
5906 this.showOverAllClear();
5907 this.inputFocus = true;
5908 if (this.value && this.value.length) {
5909 if (this.mode !== 'Delimiter' && this.mode !== 'CheckBox') {
5910 this.chipCollectionWrapper.style.display = '';
5911 }
5912 else {
5913 this.showDelimWrapper();
5914 }
5915 if (this.mode !== 'CheckBox') {
5916 this.viewWrapper.style.display = 'none';
5917 }
5918 }
5919 if (this.mode !== 'CheckBox') {
5920 this.searchWrapper.classList.remove(ZERO_SIZE);
5921 }
5922 this.checkPlaceholderSize();
5923 if (this.focused) {
5924 let args = { isInteracted: e ? true : false, event: e };
5925 this.trigger('focus', args);
5926 this.focused = false;
5927 }
5928 if (!this.overAllWrapper.classList.contains(FOCUS)) {
5929 this.overAllWrapper.classList.add(FOCUS);
5930 }
5931 floatLabelFocus(this.overAllWrapper, this.componentWrapper);
5932 if (this.isPopupOpen()) {
5933 this.refreshPopup();
5934 }
5935 return true;
5936 }
5937 else {
5938 return false;
5939 }
5940 }
5941 showDelimWrapper() {
5942 if (this.mode === 'CheckBox') {
5943 this.viewWrapper.style.display = '';
5944 }
5945 else {
5946 this.delimiterWrapper.style.display = '';
5947 }
5948 this.componentWrapper.classList.add(DELIMITER_VIEW_WRAPPER);
5949 }
5950 hideDelimWrapper() {
5951 this.delimiterWrapper.style.display = 'none';
5952 this.componentWrapper.classList.remove(DELIMITER_VIEW_WRAPPER);
5953 }
5954 expandTextbox() {
5955 let size = 5;
5956 if (this.placeholder) {
5957 size = size > this.inputElement.placeholder.length ? size : this.inputElement.placeholder.length;
5958 }
5959 if (this.inputElement.value.length > size) {
5960 this.inputElement.size = this.inputElement.value.length;
5961 }
5962 else {
5963 this.inputElement.size = size;
5964 }
5965 }
5966 isPopupOpen() {
5967 return ((this.popupWrapper !== null) && (this.popupWrapper.parentElement !== null));
5968 }
5969 refreshPopup() {
5970 if (this.popupObj && this.mobFilter) {
5971 this.popupObj.setProperties({ width: this.calcPopupWidth() });
5972 this.popupObj.refreshPosition(this.overAllWrapper);
5973 }
5974 }
5975 checkTextLength() {
5976 return this.targetElement().length < 1;
5977 }
5978 popupKeyActions(e) {
5979 switch (e.keyCode) {
5980 case 38:
5981 this.hidePopup();
5982 if (this.mode === 'CheckBox') {
5983 this.inputElement.focus();
5984 }
5985 e.preventDefault();
5986 break;
5987 case 40:
5988 if (!this.isPopupOpen()) {
5989 this.showPopup();
5990 e.preventDefault();
5991 }
5992 break;
5993 }
5994 }
5995 updateAriaAttribute() {
5996 let focusedItem = this.list.querySelector('.' + dropDownBaseClasses.focus);
5997 if (!isNullOrUndefined(focusedItem)) {
5998 this.inputElement.setAttribute('aria-activedescendant', focusedItem.id);
5999 }
6000 }
6001 homeNavigation(isHome) {
6002 this.removeFocus();
6003 let scrollEle = this.ulElement.querySelectorAll('li.' + dropDownBaseClasses.li
6004 + ':not(.' + HIDE_LIST + ')' + ':not(.e-reorder-hide)');
6005 if (scrollEle.length > 0) {
6006 let element = scrollEle[(isHome) ? 0 : (scrollEle.length - 1)];
6007 element.classList.add(dropDownBaseClasses.focus);
6008 this.scrollBottom(element);
6009 }
6010 }
6011 onKeyDown(e) {
6012 if (this.readonly || !this.enabled && this.mode !== 'CheckBox') {
6013 return;
6014 }
6015 this.keyDownStatus = true;
6016 if (e.keyCode > 111 && e.keyCode < 124) {
6017 return;
6018 }
6019 if (e.altKey) {
6020 this.popupKeyActions(e);
6021 return;
6022 }
6023 else if (this.isPopupOpen()) {
6024 let focusedItem = this.list.querySelector('.' + dropDownBaseClasses.focus);
6025 let activeIndex;
6026 switch (e.keyCode) {
6027 case 36:
6028 case 35:
6029 this.homeNavigation((e.keyCode === 36) ? true : false);
6030 break;
6031 case 33:
6032 e.preventDefault();
6033 if (focusedItem) {
6034 this.getIndexByValue(focusedItem.getAttribute('data-value'));
6035 this.pageUpSelection(activeIndex - this.getPagingCount());
6036 this.updateAriaAttribute();
6037 }
6038 return;
6039 case 34:
6040 e.preventDefault();
6041 if (focusedItem) {
6042 this.getIndexByValue(focusedItem.getAttribute('data-value'));
6043 this.pageDownSelection(activeIndex + this.getPagingCount());
6044 this.updateAriaAttribute();
6045 }
6046 return;
6047 case 38:
6048 this.arrowUp(e);
6049 break;
6050 case 40:
6051 this.arrowDown(e);
6052 break;
6053 case 27:
6054 e.preventDefault();
6055 this.hidePopup();
6056 if (this.mode === 'CheckBox') {
6057 this.inputElement.focus();
6058 }
6059 return;
6060 case 13:
6061 e.preventDefault();
6062 if (this.mode !== 'CheckBox') {
6063 this.selectByKey(e);
6064 }
6065 this.checkPlaceholderSize();
6066 return;
6067 case 32:
6068 this.spaceKeySelection(e);
6069 return;
6070 case 9:
6071 e.preventDefault();
6072 this.hidePopup();
6073 this.inputElement.focus();
6074 this.overAllWrapper.classList.add(FOCUS);
6075 }
6076 }
6077 else {
6078 switch (e.keyCode) {
6079 case 13:
6080 case 9:
6081 case 16:
6082 case 17:
6083 case 20:
6084 return;
6085 case 40:
6086 if (this.openOnClick) {
6087 this.showPopup();
6088 }
6089 break;
6090 case 27:
6091 e.preventDefault();
6092 this.escapeAction();
6093 return;
6094 }
6095 }
6096 if (this.checkTextLength()) {
6097 this.keyNavigation(e);
6098 }
6099 if (this.mode === 'CheckBox' && this.enableSelectionOrder) {
6100 this.checkBackCommand(e);
6101 }
6102 this.expandTextbox();
6103 this.refreshPopup();
6104 }
6105 arrowDown(e) {
6106 e.preventDefault();
6107 this.moveByList(1);
6108 this.keyAction = true;
6109 if (document.activeElement.classList.contains('e-input-filter')
6110 || (this.mode === 'CheckBox' && !this.allowFiltering && document.activeElement !== this.list)) {
6111 this.list.focus();
6112 EventHandler.add(this.list, 'keydown', this.onKeyDown, this);
6113 }
6114 this.updateAriaAttribute();
6115 }
6116 arrowUp(e) {
6117 e.preventDefault();
6118 this.keyAction = true;
6119 let list = this.list.querySelectorAll('li.'
6120 + dropDownBaseClasses.li
6121 + ':not(.' + HIDE_LIST + ')' + ':not(.e-reorder-hide)');
6122 if (this.enableGroupCheckBox && this.mode === 'CheckBox' && !isNullOrUndefined(this.fields.groupBy)) {
6123 list = this.list.querySelectorAll('li.'
6124 + dropDownBaseClasses.li + ',li.' + dropDownBaseClasses.group
6125 + ':not(.' + HIDE_LIST + ')' + ':not(.e-reorder-hide)');
6126 }
6127 let focuseElem = this.list.querySelector('li.' + dropDownBaseClasses.focus);
6128 let index = Array.prototype.slice.call(list).indexOf(focuseElem);
6129 if (index <= 0 && (this.mode === 'CheckBox' && this.allowFiltering)) {
6130 this.keyAction = false;
6131 this.notify('inputFocus', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', value: 'focus' });
6132 }
6133 else {
6134 this.list.focus();
6135 }
6136 this.moveByList(-1);
6137 this.updateAriaAttribute();
6138 }
6139 spaceKeySelection(e) {
6140 if (this.mode === 'CheckBox') {
6141 if (!document.activeElement.classList.contains('e-input-filter')) {
6142 e.preventDefault();
6143 this.keyAction = true;
6144 this.list.focus();
6145 }
6146 this.selectByKey(e);
6147 }
6148 this.checkPlaceholderSize();
6149 }
6150 checkBackCommand(e) {
6151 if (e.keyCode === 8 && this.targetElement() === '') {
6152 this.backCommand = false;
6153 }
6154 else {
6155 this.backCommand = true;
6156 }
6157 }
6158 keyNavigation(e) {
6159 if ((this.mode !== 'Delimiter' && this.mode !== 'CheckBox') && this.value && this.value.length) {
6160 switch (e.keyCode) {
6161 case 37: //left arrow
6162 e.preventDefault();
6163 this.moveBy(-1, e);
6164 break;
6165 case 39: //right arrow
6166 e.preventDefault();
6167 this.moveBy(1, e);
6168 break;
6169 case 8:
6170 this.removelastSelection(e);
6171 break;
6172 case 46: //del
6173 this.removeSelectedChip(e);
6174 break;
6175 }
6176 }
6177 else if (e.keyCode === 8 && this.mode === 'Delimiter') {
6178 if (this.value && this.value.length) {
6179 e.preventDefault();
6180 let temp = this.value[this.value.length - 1];
6181 this.removeValue(temp, e);
6182 this.updateDelimeter(this.delimiterChar, e);
6183 this.focusAtLastListItem(temp);
6184 }
6185 }
6186 }
6187 selectByKey(e) {
6188 this.removeChipSelection();
6189 this.selectListByKey(e);
6190 if (this.hideSelectedItem) {
6191 this.focusAtFirstListItem();
6192 }
6193 }
6194 escapeAction() {
6195 let temp = this.tempValues ? this.tempValues.slice() : [];
6196 if (this.value && this.validateValues(this.value, temp)) {
6197 if (this.mode !== 'CheckBox') {
6198 this.value = temp;
6199 this.initialValueUpdate();
6200 }
6201 if (this.mode !== 'Delimiter' && this.mode !== 'CheckBox') {
6202 this.chipCollectionWrapper.style.display = '';
6203 }
6204 else {
6205 this.showDelimWrapper();
6206 }
6207 this.refreshPlaceHolder();
6208 if (this.value.length) {
6209 this.showOverAllClear();
6210 }
6211 else {
6212 this.hideOverAllClear();
6213 }
6214 }
6215 this.makeTextBoxEmpty();
6216 }
6217 scrollBottom(selectedLI, activeIndex) {
6218 let currentOffset = this.list.offsetHeight;
6219 let nextBottom = selectedLI.offsetTop + selectedLI.offsetHeight - this.list.scrollTop;
6220 let nextOffset = this.list.scrollTop + nextBottom - currentOffset;
6221 let boxRange = (selectedLI.offsetTop + selectedLI.offsetHeight - this.list.scrollTop);
6222 boxRange = this.fields.groupBy && !isNullOrUndefined(this.fixedHeaderElement) ?
6223 boxRange - this.fixedHeaderElement.offsetHeight : boxRange;
6224 if (activeIndex === 0) {
6225 this.list.scrollTop = 0;
6226 }
6227 else if (nextBottom > currentOffset) {
6228 this.list.scrollTop = nextOffset;
6229 }
6230 else if (!(boxRange > 0 && this.list.offsetHeight > boxRange)) {
6231 this.list.scrollTop = nextOffset;
6232 }
6233 }
6234 scrollTop(selectedLI, activeIndex) {
6235 let nextOffset = selectedLI.offsetTop - this.list.scrollTop;
6236 let nextBottom = selectedLI.offsetTop + selectedLI.offsetHeight - this.list.scrollTop;
6237 nextOffset = this.fields.groupBy && !isUndefined(this.fixedHeaderElement) ?
6238 nextOffset - this.fixedHeaderElement.offsetHeight : nextOffset;
6239 let boxRange = (selectedLI.offsetTop + selectedLI.offsetHeight - this.list.scrollTop);
6240 if (activeIndex === 0) {
6241 this.list.scrollTop = 0;
6242 }
6243 else if (nextOffset < 0) {
6244 this.list.scrollTop = this.list.scrollTop + nextOffset;
6245 }
6246 else if (!(boxRange > 0 && this.list.offsetHeight > boxRange)) {
6247 this.list.scrollTop = selectedLI.offsetTop - (this.fields.groupBy && !isUndefined(this.fixedHeaderElement) ?
6248 this.fixedHeaderElement.offsetHeight : 0);
6249 }
6250 }
6251 selectListByKey(e) {
6252 let li = this.list.querySelector('li.' + dropDownBaseClasses.focus);
6253 let limit = this.value && this.value.length ? this.value.length : 0;
6254 let target;
6255 if (li !== null) {
6256 if (li.classList.contains('e-active')) {
6257 limit = limit - 1;
6258 }
6259 if (this.isValidLI(li) && limit < this.maximumSelectionLength) {
6260 this.updateListSelection(li, e);
6261 this.addListFocus(li);
6262 if (this.mode === 'CheckBox') {
6263 this.updateDelimView();
6264 this.updateDelimeter(this.delimiterChar, e);
6265 this.refreshInputHight();
6266 this.checkPlaceholderSize();
6267 if (this.enableGroupCheckBox && !isNullOrUndefined(this.fields.groupBy)) {
6268 target = li.firstElementChild.lastElementChild;
6269 this.findGroupStart(target);
6270 this.deselectHeader();
6271 }
6272 }
6273 else {
6274 this.updateDelimeter(this.delimiterChar, e);
6275 }
6276 this.makeTextBoxEmpty();
6277 if (this.mode !== 'CheckBox') {
6278 this.refreshListItems(li.textContent);
6279 }
6280 if (!this.changeOnBlur) {
6281 this.updateValueState(e, this.value, this.tempValues);
6282 }
6283 this.refreshPopup();
6284 }
6285 else {
6286 if (!this.isValidLI(li) && limit < this.maximumSelectionLength) {
6287 target = li.firstElementChild.lastElementChild;
6288 target.classList.contains('e-check') ? this.selectAllItem(false, e, li) : this.selectAllItem(true, e, li);
6289 }
6290 }
6291 this.refreshSelection();
6292 if (this.closePopupOnSelect) {
6293 this.hidePopup();
6294 }
6295 }
6296 this.refreshPlaceHolder();
6297 }
6298 refreshListItems(data) {
6299 if ((this.allowFiltering || (this.mode === 'CheckBox' && this.enableSelectionOrder === true)
6300 || this.allowCustomValue) && this.mainList && this.listData) {
6301 let list;
6302 list = this.mainList.cloneNode ? this.mainList.cloneNode(true) : this.mainList;
6303 this.onActionComplete(list, this.mainData);
6304 this.focusAtLastListItem(data);
6305 if (this.value && this.value.length) {
6306 this.refreshSelection();
6307 }
6308 }
6309 }
6310 removeSelectedChip(e) {
6311 let selectedElem = this.chipCollectionWrapper.querySelector('span.' + CHIP_SELECTED);
6312 let temp;
6313 if (selectedElem !== null) {
6314 if (!isNullOrUndefined(this.value)) {
6315 this.tempValues = this.value.slice();
6316 }
6317 temp = selectedElem.nextElementSibling;
6318 if (temp !== null) {
6319 this.removeChipSelection();
6320 this.addChipSelection(temp, e);
6321 }
6322 this.removeValue(selectedElem.getAttribute('data-value'), e);
6323 this.makeTextBoxEmpty();
6324 }
6325 if (this.closePopupOnSelect) {
6326 this.hidePopup();
6327 }
6328 this.checkPlaceholderSize();
6329 }
6330 moveByTop(state) {
6331 let elements = this.list.querySelectorAll('li.' + dropDownBaseClasses.li);
6332 let index;
6333 if (elements.length > 1) {
6334 this.removeFocus();
6335 index = state ? 0 : (elements.length - 1);
6336 this.addListFocus(elements[index]);
6337 this.scrollBottom(elements[index], index);
6338 }
6339 this.updateAriaAttribute();
6340 }
6341 moveByList(position) {
6342 if (this.list) {
6343 let elements = this.list.querySelectorAll('li.'
6344 + dropDownBaseClasses.li
6345 + ':not(.' + HIDE_LIST + ')' + ':not(.e-reorder-hide)');
6346 if (this.mode === 'CheckBox' && this.enableGroupCheckBox && !isNullOrUndefined(this.fields.groupBy)) {
6347 elements = this.list.querySelectorAll('li.'
6348 + dropDownBaseClasses.li + ',li.' + dropDownBaseClasses.group
6349 + ':not(.' + HIDE_LIST + ')' + ':not(.e-reorder-hide)');
6350 }
6351 let selectedElem = this.list.querySelector('li.' + dropDownBaseClasses.focus);
6352 let temp = -1;
6353 if (elements.length) {
6354 for (let index = 0; index < elements.length; index++) {
6355 if (elements[index] === selectedElem) {
6356 temp = index;
6357 break;
6358 }
6359 }
6360 if (position > 0) {
6361 if (temp < (elements.length - 1)) {
6362 this.removeFocus();
6363 this.addListFocus(elements[++temp]);
6364 this.updateCheck(elements[temp]);
6365 this.scrollBottom(elements[temp], temp);
6366 }
6367 }
6368 else {
6369 if (temp > 0) {
6370 this.removeFocus();
6371 this.addListFocus(elements[--temp]);
6372 this.updateCheck(elements[temp]);
6373 this.scrollTop(elements[temp], temp);
6374 }
6375 }
6376 }
6377 }
6378 }
6379 updateCheck(element) {
6380 if (this.mode === 'CheckBox' && this.enableGroupCheckBox &&
6381 !isNullOrUndefined(this.fields.groupBy)) {
6382 let checkElement = element.firstElementChild.lastElementChild;
6383 if (checkElement.classList.contains('e-check')) {
6384 element.classList.add('e-active');
6385 }
6386 else {
6387 element.classList.remove('e-active');
6388 }
6389 }
6390 }
6391 moveBy(position, e) {
6392 let elements;
6393 let selectedElem;
6394 let temp;
6395 elements = this.chipCollectionWrapper.querySelectorAll('span.' + CHIP);
6396 selectedElem = this.chipCollectionWrapper.querySelector('span.' + CHIP_SELECTED);
6397 if (selectedElem === null) {
6398 if (position < 0) {
6399 this.addChipSelection(elements[elements.length - 1], e);
6400 }
6401 }
6402 else {
6403 if (position < 0) {
6404 temp = selectedElem.previousElementSibling;
6405 if (temp !== null) {
6406 this.removeChipSelection();
6407 this.addChipSelection(temp, e);
6408 }
6409 }
6410 else {
6411 temp = selectedElem.nextElementSibling;
6412 this.removeChipSelection();
6413 if (temp !== null) {
6414 this.addChipSelection(temp, e);
6415 }
6416 }
6417 }
6418 }
6419 chipClick(e) {
6420 if (this.enabled) {
6421 let elem = closest(e.target, '.' + CHIP);
6422 this.removeChipSelection();
6423 this.addChipSelection(elem, e);
6424 }
6425 }
6426 removeChipSelection() {
6427 if (this.chipCollectionWrapper) {
6428 this.removeChipFocus();
6429 }
6430 }
6431 addChipSelection(element, e) {
6432 addClass([element], CHIP_SELECTED);
6433 this.trigger('chipSelection', e);
6434 }
6435 onChipRemove(e) {
6436 if (e.which === 3 || e.button === 2) {
6437 return;
6438 }
6439 if (this.enabled && !this.readonly) {
6440 let element = e.target.parentElement;
6441 let customVal = element.getAttribute('data-value');
6442 let value = this.getFormattedValue(customVal);
6443 if (this.allowCustomValue && ((customVal !== 'false' && value === false) ||
6444 (!isNullOrUndefined(value) && value.toString() === 'NaN'))) {
6445 value = customVal;
6446 }
6447 if (this.isPopupOpen() && this.mode !== 'CheckBox') {
6448 this.hidePopup();
6449 }
6450 if (!this.inputFocus) {
6451 this.inputElement.focus();
6452 }
6453 this.removeValue(value, e);
6454 if (isNullOrUndefined(this.findListElement(this.list, 'li', 'data-value', value)) && this.mainList && this.listData) {
6455 let list = this.mainList.cloneNode ? this.mainList.cloneNode(true) : this.mainList;
6456 this.onActionComplete(list, this.mainData);
6457 }
6458 this.updateDelimeter(this.delimiterChar, e);
6459 if (this.placeholder && this.floatLabelType === 'Never') {
6460 this.makeTextBoxEmpty();
6461 this.checkPlaceholderSize();
6462 }
6463 else {
6464 this.inputElement.value = '';
6465 }
6466 e.preventDefault();
6467 }
6468 }
6469 makeTextBoxEmpty() {
6470 this.inputElement.value = '';
6471 this.refreshPlaceHolder();
6472 }
6473 refreshPlaceHolder() {
6474 if (this.placeholder && this.floatLabelType === 'Never') {
6475 if ((this.value && this.value.length) || (!isNullOrUndefined(this.text) && this.text !== '')) {
6476 this.inputElement.placeholder = '';
6477 }
6478 else {
6479 this.inputElement.placeholder = this.placeholder;
6480 }
6481 }
6482 else {
6483 this.setFloatLabelType();
6484 }
6485 this.expandTextbox();
6486 }
6487 removeValue(value, eve, length, isClearAll) {
6488 let index = this.value.indexOf(this.getFormattedValue(value));
6489 if (index === -1 && this.allowCustomValue && !isNullOrUndefined(value)) {
6490 index = this.value.indexOf(value.toString());
6491 }
6492 let targetEle = eve && eve.target;
6493 isClearAll = (isClearAll || targetEle && targetEle.classList.contains('e-close-hooker')) ? true : null;
6494 let className = this.hideSelectedItem ?
6495 HIDE_LIST :
6496 dropDownBaseClasses.selected;
6497 if (index !== -1) {
6498 let element = this.findListElement(this.list, 'li', 'data-value', value);
6499 let val = this.getDataByValue(value);
6500 let eventArgs = {
6501 e: eve,
6502 item: element,
6503 itemData: val,
6504 isInteracted: eve ? true : false,
6505 cancel: false
6506 };
6507 this.trigger('removing', eventArgs, (eventArgs) => {
6508 if (eventArgs.cancel) {
6509 this.removeIndex++;
6510 }
6511 else {
6512 let removeVal = this.value.slice(0);
6513 removeVal.splice(index, 1);
6514 this.setProperties({ value: [].concat([], removeVal) }, true);
6515 if (element !== null) {
6516 let hideElement = this.findListElement(this.mainList, 'li', 'data-value', value);
6517 element.setAttribute('aria-selected', 'false');
6518 removeClass([element], className);
6519 if (hideElement) {
6520 hideElement.setAttribute('aria-selected', 'false');
6521 removeClass([element, hideElement], className);
6522 }
6523 this.notify('activeList', {
6524 module: 'CheckBoxSelection',
6525 enable: this.mode === 'CheckBox', li: element,
6526 e: this, index: index
6527 });
6528 this.notify('updatelist', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', li: element, e: eve });
6529 attributes(this.inputElement, { 'aria-activedescendant': element.id });
6530 if ((this.value.length !== this.mainData.length) && (this.mode === 'CheckBox' && this.showSelectAll)) {
6531 this.notify('checkSelectAll', { module: 'CheckBoxSelection',
6532 enable: this.mode === 'CheckBox',
6533 value: 'uncheck' });
6534 }
6535 }
6536 if (this.hideSelectedItem && this.fields.groupBy) {
6537 this.hideGroupItem(value);
6538 }
6539 this.updateMainList(true, value);
6540 this.removeChip(value);
6541 this.updateChipStatus();
6542 let limit = this.value && this.value.length ? this.value.length : 0;
6543 if (limit < this.maximumSelectionLength) {
6544 let collection = this.list.querySelectorAll('li.'
6545 + dropDownBaseClasses.li + ':not(.e-active)');
6546 removeClass(collection, 'e-disable');
6547 }
6548 this.trigger('removed', eventArgs);
6549 let targetEle = eve && eve.currentTarget;
6550 let isSelectAll = (targetEle && targetEle.classList.contains('e-selectall-parent')) ? true : null;
6551 if (!this.changeOnBlur && !isClearAll && (eve && length && !isSelectAll)) {
6552 this.updateValueState(eve, this.value, this.tempValues);
6553 }
6554 if (length) {
6555 this.selectAllEventData.push(val);
6556 this.selectAllEventEle.push(element);
6557 }
6558 if (length === 1) {
6559 if (!this.changeOnBlur) {
6560 this.updateValueState(eve, this.value, this.tempValues);
6561 }
6562 let args = {
6563 event: eve,
6564 items: this.selectAllEventEle,
6565 itemData: this.selectAllEventData,
6566 isInteracted: eve ? true : false,
6567 isChecked: false
6568 };
6569 this.trigger('selectedAll', args);
6570 this.selectAllEventData = [];
6571 this.selectAllEventEle = [];
6572 }
6573 if (isClearAll) {
6574 this.clearAllCallback(eve, isClearAll);
6575 }
6576 }
6577 });
6578 }
6579 }
6580 updateMainList(state, value) {
6581 if (this.allowFiltering || this.mode === 'CheckBox') {
6582 let element2 = this.findListElement(this.mainList, 'li', 'data-value', value);
6583 if (element2) {
6584 if (state) {
6585 element2.setAttribute('aria-selected', 'false');
6586 removeClass([element2], this.hideSelectedItem ?
6587 HIDE_LIST :
6588 dropDownBaseClasses.selected);
6589 if (this.mode === 'CheckBox') {
6590 element2.firstElementChild.setAttribute('aria-checked', 'false');
6591 removeClass([element2.firstElementChild.lastElementChild], 'e-check');
6592 }
6593 }
6594 else {
6595 element2.setAttribute('aria-selected', 'true');
6596 addClass([element2], this.hideSelectedItem ?
6597 HIDE_LIST :
6598 dropDownBaseClasses.selected);
6599 if (this.mode === 'CheckBox') {
6600 element2.firstElementChild.setAttribute('aria-checked', 'true');
6601 addClass([element2.firstElementChild.lastElementChild], 'e-check');
6602 }
6603 }
6604 }
6605 }
6606 }
6607 removeChip(value) {
6608 if (this.chipCollectionWrapper) {
6609 let element = this.findListElement(this.chipCollectionWrapper, 'span', 'data-value', value);
6610 if (element) {
6611 remove(element);
6612 }
6613 }
6614 }
6615 setWidth(width) {
6616 if (!isNullOrUndefined(width)) {
6617 if (typeof width === 'number') {
6618 this.overAllWrapper.style.width = formatUnit(width);
6619 }
6620 else if (typeof width === 'string') {
6621 this.overAllWrapper.style.width = (width.match(/px|%|em/)) ? (width) : (formatUnit(width));
6622 }
6623 }
6624 }
6625 updateChipStatus() {
6626 if (this.value.length) {
6627 if (!isNullOrUndefined(this.chipCollectionWrapper)) {
6628 (this.chipCollectionWrapper.style.display = '');
6629 }
6630 if (this.mode === 'Delimiter' || this.mode === 'CheckBox') {
6631 this.showDelimWrapper();
6632 }
6633 this.showOverAllClear();
6634 }
6635 else {
6636 if (!isNullOrUndefined(this.chipCollectionWrapper)) {
6637 this.chipCollectionWrapper.style.display = 'none';
6638 }
6639 if (!isNullOrUndefined(this.delimiterWrapper)) {
6640 (this.delimiterWrapper.style.display = 'none');
6641 }
6642 this.hideOverAllClear();
6643 }
6644 }
6645 addValue(value, text, eve) {
6646 if (!this.value) {
6647 this.value = [];
6648 }
6649 this.setProperties({ value: [].concat([], this.value, [value]) }, true);
6650 let element = this.findListElement(this.list, 'li', 'data-value', value);
6651 this.removeFocus();
6652 if (element) {
6653 this.addListFocus(element);
6654 this.addListSelection(element);
6655 }
6656 if (this.mode !== 'Delimiter' && this.mode !== 'CheckBox') {
6657 this.addChip(text, value, eve);
6658 }
6659 if (this.hideSelectedItem && this.fields.groupBy) {
6660 this.hideGroupItem(value);
6661 }
6662 this.updateChipStatus();
6663 this.checkMaxSelection();
6664 }
6665 checkMaxSelection() {
6666 let limit = this.value && this.value.length ? this.value.length : 0;
6667 if (limit === this.maximumSelectionLength) {
6668 let collection = this.list.querySelectorAll('li.'
6669 + dropDownBaseClasses.li + ':not(.e-active)');
6670 addClass(collection, 'e-disable');
6671 }
6672 }
6673 dispatchSelect(value, eve, element, isNotTrigger, length) {
6674 if (this.initStatus && !isNotTrigger) {
6675 let val = this.getDataByValue(value);
6676 let eventArgs = {
6677 e: eve,
6678 item: element,
6679 itemData: val,
6680 isInteracted: eve ? true : false,
6681 cancel: false
6682 };
6683 this.trigger('select', eventArgs, (eventArgs) => {
6684 if (!eventArgs.cancel) {
6685 if (length) {
6686 this.selectAllEventData.push(val);
6687 this.selectAllEventEle.push(element);
6688 }
6689 if (length === 1) {
6690 let args = {
6691 event: eve,
6692 items: this.selectAllEventEle,
6693 itemData: this.selectAllEventData,
6694 isInteracted: eve ? true : false,
6695 isChecked: true
6696 };
6697 this.trigger('selectedAll', args);
6698 this.selectAllEventData = [];
6699 }
6700 this.updateListSelectEventCallback(value, element, eve);
6701 }
6702 });
6703 }
6704 }
6705 addChip(text, value, e) {
6706 if (this.chipCollectionWrapper) {
6707 this.getChip(text, value, e);
6708 }
6709 }
6710 removeChipFocus() {
6711 let elements;
6712 let closeElements;
6713 elements = this.chipCollectionWrapper.querySelectorAll('span.' + CHIP);
6714 closeElements = this.chipCollectionWrapper.querySelectorAll('span.' + CHIP_CLOSE.split(' ')[0]);
6715 removeClass(elements, CHIP_SELECTED);
6716 if (Browser.isDevice) {
6717 for (let index = 0; index < closeElements.length; index++) {
6718 closeElements[index].style.display = 'none';
6719 }
6720 }
6721 }
6722 onMobileChipInteraction(e) {
6723 let chipElem = closest(e.target, '.' + CHIP);
6724 let chipClose = chipElem.querySelector('span.' + CHIP_CLOSE.split(' ')[0]);
6725 if (this.enabled && !this.readonly) {
6726 if (!chipElem.classList.contains(CHIP_SELECTED)) {
6727 this.removeChipFocus();
6728 chipClose.style.display = '';
6729 chipElem.classList.add(CHIP_SELECTED);
6730 }
6731 this.refreshPopup();
6732 e.preventDefault();
6733 }
6734 }
6735 getChip(data, value, e) {
6736 let itemData = { text: value, value: value };
6737 let chip = this.createElement('span', {
6738 className: CHIP,
6739 attrs: { 'data-value': value, 'title': data }
6740 });
6741 let chipContent = this.createElement('span', { className: CHIP_CONTENT });
6742 let chipClose = this.createElement('span', { className: CHIP_CLOSE });
6743 if (this.mainData) {
6744 itemData = isBlazor() ? JSON.parse(JSON.stringify(this.getDataByValue(value))) : this.getDataByValue(value);
6745 }
6746 if (this.valueTemplate && !isNullOrUndefined(itemData)) {
6747 let compiledString = compile(this.valueTemplate);
6748 for (let item of compiledString(itemData, null, null, this.valueTemplateId, this.isStringTemplate)) {
6749 chipContent.appendChild(item);
6750 }
6751 this.DropDownBaseupdateBlazorTemplates(false, false, false, false, true, false, false, false);
6752 }
6753 else {
6754 chipContent.innerHTML = data;
6755 }
6756 chip.appendChild(chipContent);
6757 let eventArgs = {
6758 isInteracted: e ? true : false,
6759 itemData: itemData,
6760 e: e,
6761 setClass: (classes) => {
6762 addClass([chip], classes);
6763 },
6764 cancel: false
6765 };
6766 this.trigger('tagging', eventArgs, (eventArgs) => {
6767 if (!eventArgs.cancel) {
6768 if (eventArgs.setClass && typeof eventArgs.setClass === 'string' && isBlazor()) {
6769 addClass([chip], eventArgs.setClass);
6770 }
6771 if (Browser.isDevice) {
6772 chip.classList.add(MOBILE_CHIP);
6773 append([chipClose], chip);
6774 chipClose.style.display = 'none';
6775 EventHandler.add(chip, 'click', this.onMobileChipInteraction, this);
6776 }
6777 else {
6778 EventHandler.add(chip, 'mousedown', this.chipClick, this);
6779 if (this.showClearButton) {
6780 chip.appendChild(chipClose);
6781 }
6782 }
6783 EventHandler.add(chipClose, 'mousedown', this.onChipRemove, this);
6784 this.chipCollectionWrapper.appendChild(chip);
6785 if (!this.changeOnBlur && e) {
6786 this.updateValueState(e, this.value, this.tempValues);
6787 }
6788 }
6789 });
6790 }
6791 calcPopupWidth() {
6792 let width = formatUnit(this.popupWidth);
6793 if (width.indexOf('%') > -1) {
6794 let inputWidth = (this.componentWrapper.offsetWidth) * parseFloat(width) / 100;
6795 width = inputWidth.toString() + 'px';
6796 }
6797 return width;
6798 }
6799 mouseIn() {
6800 if (this.enabled && !this.readonly) {
6801 this.showOverAllClear();
6802 }
6803 }
6804 mouseOut() {
6805 if (!this.inputFocus) {
6806 this.overAllClear.style.display = 'none';
6807 }
6808 }
6809 listOption(dataSource, fields) {
6810 let iconCss = isNullOrUndefined(fields.iconCss) ? false : true;
6811 let fieldProperty = isNullOrUndefined(fields.properties) ? fields :
6812 fields.properties;
6813 this.listCurrentOptions = (fields.text !== null || fields.value !== null) ? {
6814 fields: fieldProperty, showIcon: iconCss, ariaAttributes: { groupItemRole: 'presentation' }
6815 } : { fields: { value: 'text' } };
6816 extend(this.listCurrentOptions, this.listCurrentOptions, fields, true);
6817 if (this.mode === 'CheckBox') {
6818 this.notify('listoption', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', dataSource, fieldProperty });
6819 }
6820 return this.listCurrentOptions;
6821 }
6822 renderPopup() {
6823 if (!this.list) {
6824 super.render();
6825 }
6826 if (!this.popupObj) {
6827 let args = { cancel: false };
6828 this.trigger('beforeOpen', args, (args) => {
6829 if (!args.cancel) {
6830 document.body.appendChild(this.popupWrapper);
6831 let checkboxFilter = this.popupWrapper.querySelector('.' + FILTERPARENT);
6832 if (this.mode === 'CheckBox' && !this.allowFiltering && checkboxFilter && this.filterParent) {
6833 checkboxFilter.remove();
6834 this.filterParent = null;
6835 }
6836 let overAllHeight = parseInt(this.popupHeight, 10);
6837 this.popupWrapper.style.visibility = 'hidden';
6838 if (this.headerTemplate) {
6839 this.setHeaderTemplate();
6840 overAllHeight -= this.header.offsetHeight;
6841 }
6842 append([this.list], this.popupWrapper);
6843 if (this.footerTemplate) {
6844 this.setFooterTemplate();
6845 overAllHeight -= this.footer.offsetHeight;
6846 }
6847 if (this.mode === 'CheckBox' && this.showSelectAll) {
6848 this.notify('selectAll', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox' });
6849 overAllHeight -= this.selectAllHeight;
6850 }
6851 else if (this.mode === 'CheckBox' && !this.showSelectAll && (!this.headerTemplate || !this.footerTemplate)) {
6852 this.notify('selectAll', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox' });
6853 overAllHeight = parseInt(this.popupHeight, 10);
6854 }
6855 else if (this.mode === 'CheckBox' && !this.showSelectAll) {
6856 this.notify('selectAll', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox' });
6857 overAllHeight = parseInt(this.popupHeight, 10);
6858 if (this.headerTemplate && this.header) {
6859 overAllHeight -= this.header.offsetHeight;
6860 }
6861 if (this.footerTemplate && this.footer) {
6862 overAllHeight -= this.footer.offsetHeight;
6863 }
6864 }
6865 if (this.mode === 'CheckBox') {
6866 let args = {
6867 module: 'CheckBoxSelection',
6868 enable: this.mode === 'CheckBox',
6869 popupElement: this.popupWrapper
6870 };
6871 if (this.allowFiltering) {
6872 this.notify('searchBox', args);
6873 overAllHeight -= this.searchBoxHeight;
6874 }
6875 addClass([this.popupWrapper], 'e-checkbox');
6876 }
6877 if (this.popupHeight !== 'auto') {
6878 this.list.style.maxHeight = formatUnit(overAllHeight);
6879 this.popupWrapper.style.maxHeight = formatUnit(this.popupHeight);
6880 }
6881 else {
6882 this.list.style.maxHeight = formatUnit(this.popupHeight);
6883 }
6884 this.popupObj = new Popup(this.popupWrapper, {
6885 width: this.calcPopupWidth(), targetType: 'relative', position: { X: 'left', Y: 'bottom' },
6886 relateTo: this.overAllWrapper, collision: { X: 'flip', Y: 'flip' }, offsetY: 1,
6887 enableRtl: this.enableRtl, zIndex: this.zIndex,
6888 close: () => {
6889 if (this.popupObj.element.parentElement) {
6890 this.popupObj.unwireScrollEvents();
6891 detach(this.popupObj.element);
6892 }
6893 },
6894 open: () => {
6895 if (!this.isFirstClick) {
6896 let ulElement = this.list.querySelector('ul');
6897 if (ulElement) {
6898 if (this.itemTemplate && (this.mode === 'CheckBox') && isBlazor()) {
6899 setTimeout(() => {
6900 this.mainList = this.ulElement;
6901 }, 0);
6902 }
6903 else {
6904 this.mainList = ulElement.cloneNode ? ulElement.cloneNode(true) : ulElement;
6905 }
6906 }
6907 this.isFirstClick = true;
6908 }
6909 this.popupObj.wireScrollEvents();
6910 this.loadTemplate();
6911 this.setScrollPosition();
6912 if (this.allowFiltering) {
6913 this.notify('inputFocus', {
6914 module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', value: 'focus'
6915 });
6916 }
6917 }, targetExitViewport: () => {
6918 if (!Browser.isDevice) {
6919 this.hidePopup();
6920 }
6921 }
6922 });
6923 this.popupObj.close();
6924 this.popupWrapper.style.visibility = '';
6925 if (this.mode === 'CheckBox' && Browser.isDevice && this.allowFiltering) {
6926 this.notify('deviceSearchBox', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox' });
6927 }
6928 }
6929 });
6930 }
6931 }
6932 setHeaderTemplate() {
6933 let compiledString;
6934 if (this.header) {
6935 this.header.remove();
6936 }
6937 this.header = this.createElement('div');
6938 addClass([this.header], HEADER);
6939 compiledString = compile(this.headerTemplate);
6940 let elements = compiledString({}, null, null, this.headerTemplateId, this.isStringTemplate);
6941 for (let temp = 0; temp < elements.length; temp++) {
6942 this.header.appendChild(elements[temp]);
6943 }
6944 this.DropDownBaseupdateBlazorTemplates(false, false, false, false, false, true, false);
6945 if (this.mode === 'CheckBox' && this.showSelectAll) {
6946 prepend([this.header], this.popupWrapper);
6947 }
6948 else {
6949 append([this.header], this.popupWrapper);
6950 }
6951 EventHandler.add(this.header, 'mousedown', this.onListMouseDown, this);
6952 }
6953 setFooterTemplate() {
6954 let compiledString;
6955 if (this.footer) {
6956 this.footer.remove();
6957 }
6958 this.footer = this.createElement('div');
6959 addClass([this.footer], FOOTER);
6960 compiledString = compile(this.footerTemplate);
6961 let elements = compiledString({}, null, null, this.footerTemplateId, this.isStringTemplate);
6962 for (let temp = 0; temp < elements.length; temp++) {
6963 this.footer.appendChild(elements[temp]);
6964 }
6965 this.DropDownBaseupdateBlazorTemplates(false, false, false, false, false, false, true);
6966 append([this.footer], this.popupWrapper);
6967 EventHandler.add(this.footer, 'mousedown', this.onListMouseDown, this);
6968 }
6969 ClearAll(e) {
6970 if (this.enabled && !this.readonly) {
6971 let temp;
6972 if (this.value && this.value.length > 0) {
6973 let liElement = this.list && this.list.querySelectorAll('li.e-list-item');
6974 if (liElement && liElement.length > 0) {
6975 this.selectAllItems(false, e);
6976 }
6977 else {
6978 this.removeIndex = 0;
6979 for (temp = this.value[this.removeIndex]; this.removeIndex < this.value.length; temp = this.value[this.removeIndex]) {
6980 this.removeValue(temp, e, null, true);
6981 }
6982 }
6983 }
6984 else {
6985 this.clearAllCallback(e);
6986 }
6987 }
6988 }
6989 clearAllCallback(e, isClearAll) {
6990 let tempValues = this.value ? this.value.slice() : [];
6991 if (this.mainList && this.listData && (this.allowFiltering || this.allowCustomValue)) {
6992 let list = this.mainList.cloneNode ? this.mainList.cloneNode(true) : this.mainList;
6993 this.onActionComplete(list, this.mainData);
6994 }
6995 this.focusAtFirstListItem();
6996 this.updateDelimeter(this.delimiterChar, e);
6997 if (this.mode !== 'Box' && (!this.inputFocus || this.mode === 'CheckBox')) {
6998 this.updateDelimView();
6999 }
7000 this.makeTextBoxEmpty();
7001 this.checkPlaceholderSize();
7002 if (this.isPopupOpen()) {
7003 this.refreshPopup();
7004 }
7005 if (!this.inputFocus) {
7006 if (this.changeOnBlur) {
7007 this.updateValueState(e, this.value, tempValues);
7008 }
7009 if (this.mode !== 'CheckBox') {
7010 this.inputElement.focus();
7011 }
7012 }
7013 if (this.mode === 'CheckBox') {
7014 this.refreshPlaceHolder();
7015 this.refreshInputHight();
7016 if (this.changeOnBlur && isClearAll && (this.value && this.value.length === 0)) {
7017 this.updateValueState(e, this.value, this.tempValues);
7018 }
7019 }
7020 if (!this.changeOnBlur && isClearAll && (this.value && this.value.length === 0)) {
7021 this.updateValueState(e, this.value, this.tempValues);
7022 }
7023 if (this.mode === 'CheckBox' && this.enableGroupCheckBox && !isNullOrUndefined(this.fields.groupBy)) {
7024 this.updateListItems(this.list.querySelectorAll('li.e-list-item'), this.mainList.querySelectorAll('li.e-list-item'));
7025 }
7026 e.preventDefault();
7027 }
7028 windowResize() {
7029 this.refreshPopup();
7030 if ((!this.inputFocus || this.mode === 'CheckBox') && this.viewWrapper && this.viewWrapper.parentElement) {
7031 this.updateDelimView();
7032 }
7033 }
7034 resetValueHandler(e) {
7035 let formElement = closest(this.inputElement, 'form');
7036 if (formElement && e.target === formElement) {
7037 let textVal = (this.element.tagName === this.getNgDirective()) ? null : this.element.getAttribute('data-initial-value');
7038 this.text = textVal;
7039 }
7040 }
7041 wireEvent() {
7042 EventHandler.add(this.componentWrapper, 'mousedown', this.wrapperClick, this);
7043 EventHandler.add(window, 'resize', this.windowResize, this);
7044 EventHandler.add(this.inputElement, 'focus', this.focusInHandler, this);
7045 EventHandler.add(this.inputElement, 'keydown', this.onKeyDown, this);
7046 EventHandler.add(this.inputElement, 'keyup', this.KeyUp, this);
7047 if (this.mode !== 'CheckBox') {
7048 EventHandler.add(this.inputElement, 'input', this.onInput, this);
7049 }
7050 EventHandler.add(this.inputElement, 'blur', this.onBlur, this);
7051 EventHandler.add(this.componentWrapper, 'mousemove', this.mouseIn, this);
7052 let formElement = closest(this.inputElement, 'form');
7053 if (formElement) {
7054 EventHandler.add(formElement, 'reset', this.resetValueHandler, this);
7055 }
7056 EventHandler.add(this.componentWrapper, 'mouseout', this.mouseOut, this);
7057 EventHandler.add(this.overAllClear, 'mouseup', this.ClearAll, this);
7058 }
7059 onInput(e) {
7060 if (this.keyDownStatus) {
7061 this.isValidKey = true;
7062 }
7063 else {
7064 this.isValidKey = false;
7065 }
7066 this.keyDownStatus = false;
7067 // For Filtering works in mobile firefox
7068 if (Browser.isDevice && Browser.info.name === 'mozilla') {
7069 this.search(e);
7070 }
7071 }
7072 search(e) {
7073 if (!this.isPopupOpen() && this.openOnClick) {
7074 this.showPopup();
7075 }
7076 this.openClick(e);
7077 if (this.checkTextLength() && !this.allowFiltering && (e.keyCode !== 8)) {
7078 this.focusAtFirstListItem();
7079 }
7080 else {
7081 let text = this.targetElement();
7082 this.keyCode = e.keyCode;
7083 if (this.allowFiltering) {
7084 let eventArgs = {
7085 preventDefaultAction: false,
7086 text: this.targetElement(),
7087 updateData: (dataSource, query, fields) => {
7088 if (eventArgs.cancel) {
7089 return;
7090 }
7091 this.isFiltered = true;
7092 this.remoteFilterAction = true;
7093 this.dataUpdater(dataSource, query, fields);
7094 },
7095 event: e,
7096 cancel: false
7097 };
7098 this.trigger('filtering', eventArgs, (eventArgs) => {
7099 if (!eventArgs.cancel) {
7100 if (!this.isFiltered && !eventArgs.preventDefaultAction) {
7101 this.filterAction = true;
7102 this.dataUpdater(this.dataSource, null, this.fields);
7103 }
7104 }
7105 });
7106 }
7107 else if (this.allowCustomValue) {
7108 let query = new Query();
7109 query = (text !== '') ? query.where(this.fields.text, 'startswith', text, this.ignoreCase, this.ignoreAccent) : query;
7110 this.dataUpdater(this.mainData, query, this.fields);
7111 }
7112 else {
7113 let liCollections;
7114 liCollections = this.list.querySelectorAll('li.' + dropDownBaseClasses.li + ':not(.e-hide-listitem)');
7115 let activeElement = Search(this.targetElement(), liCollections, 'StartsWith', this.ignoreCase);
7116 if (activeElement && activeElement.item !== null) {
7117 this.addListFocus(activeElement.item);
7118 this.list.scrollTop =
7119 activeElement.item.offsetHeight * activeElement.index;
7120 }
7121 else if (this.targetElement() !== '') {
7122 this.removeFocus();
7123 }
7124 else {
7125 this.focusAtFirstListItem();
7126 }
7127 }
7128 }
7129 }
7130 preRender() {
7131 if (this.allowFiltering === null) {
7132 this.allowFiltering = (this.mode === 'CheckBox') ? true : false;
7133 }
7134 this.initializeData();
7135 this.updateDataAttribute(this.htmlAttributes);
7136 super.preRender();
7137 }
7138 getLocaleName() {
7139 return 'multi-select';
7140 }
7141 ;
7142 initializeData() {
7143 this.mainListCollection = [];
7144 this.beforePopupOpen = false;
7145 this.filterAction = false;
7146 this.remoteFilterAction = false;
7147 this.isFirstClick = false;
7148 this.mobFilter = true;
7149 this.isFiltered = false;
7150 this.focused = true;
7151 this.initial = true;
7152 this.backCommand = true;
7153 }
7154 updateData(delimiterChar, e) {
7155 let data = '';
7156 let delim = this.mode === 'Delimiter' || this.mode === 'CheckBox';
7157 let text = [];
7158 let temp;
7159 let tempData = this.listData;
7160 this.listData = this.mainData;
7161 this.hiddenElement.innerHTML = '';
7162 if (!isNullOrUndefined(this.value)) {
7163 for (let index = 0; !isNullOrUndefined(this.value[index]); index++) {
7164 if (this.listData) {
7165 temp = this.getTextByValue(this.value[index]);
7166 }
7167 else {
7168 temp = this.value[index];
7169 }
7170 data += temp + delimiterChar + ' ';
7171 text.push(temp);
7172 this.hiddenElement.innerHTML += '<option selected value ="' + this.value[index] + '">' + index + '</option>';
7173 }
7174 }
7175 this.setProperties({ text: text.toString() }, true);
7176 if (delim) {
7177 this.delimiterWrapper.innerHTML = data;
7178 this.delimiterWrapper.setAttribute('id', getUniqueID('delim_val'));
7179 this.inputElement.setAttribute('aria-describedby', this.delimiterWrapper.id);
7180 }
7181 let targetEle = e && e.target;
7182 let isClearAll = (targetEle && targetEle.classList.contains('e-close-hooker')) ? true : null;
7183 if (!this.changeOnBlur && ((e && !isClearAll)) || this.isSelectAll) {
7184 this.isSelectAll = false;
7185 this.updateValueState(e, this.value, this.tempValues);
7186 }
7187 this.listData = tempData;
7188 this.addValidInputClass();
7189 }
7190 initialTextUpdate() {
7191 if (!isNullOrUndefined(this.text)) {
7192 let textArr = this.text.split(this.delimiterChar);
7193 let textVal = [];
7194 for (let index = 0; textArr.length > index; index++) {
7195 let val = this.getValueByText(textArr[index]);
7196 if (!isNullOrUndefined(val)) {
7197 textVal.push(val);
7198 }
7199 else if (this.allowCustomValue) {
7200 textVal.push(textArr[index]);
7201 }
7202 }
7203 if (textVal && textVal.length) {
7204 this.setProperties({ value: textVal }, true);
7205 }
7206 }
7207 else {
7208 this.setProperties({ value: null }, true);
7209 }
7210 }
7211 renderList(isEmptyData) {
7212 super.render(isEmptyData);
7213 this.unwireListEvents();
7214 this.wireListEvents();
7215 }
7216 initialValueUpdate() {
7217 if (this.list) {
7218 let text;
7219 let element;
7220 let value;
7221 if (this.chipCollectionWrapper) {
7222 this.chipCollectionWrapper.innerHTML = '';
7223 }
7224 this.removeListSelection();
7225 if (!isNullOrUndefined(this.value)) {
7226 for (let index = 0; !isNullOrUndefined(this.value[index]); index++) {
7227 value = this.value[index];
7228 element = this.findListElement(this.hideSelectedItem ? this.ulElement : this.list, 'li', 'data-value', value);
7229 text = this.getTextByValue(value);
7230 if ((element && (element.getAttribute('aria-selected') !== 'true')) ||
7231 (element && (element.getAttribute('aria-selected') === 'true' && this.hideSelectedItem) &&
7232 (this.mode === 'Box' || this.mode === 'Default'))) {
7233 this.addChip(text, value);
7234 this.addListSelection(element);
7235 }
7236 else if (value && this.allowCustomValue) {
7237 let indexItem = this.listData.length;
7238 let newValue = {};
7239 setValue(this.fields.text, value, newValue);
7240 setValue(this.fields.value, value, newValue);
7241 let noDataEle = this.popupWrapper.querySelector('.' + dropDownBaseClasses.noData);
7242 this.addItem(newValue, indexItem);
7243 if (this.popupWrapper.contains(noDataEle)) {
7244 this.list.setAttribute('style', noDataEle.getAttribute('style'));
7245 this.popupWrapper.replaceChild(this.list, noDataEle);
7246 this.wireListEvents();
7247 }
7248 this.addChip(text, value);
7249 this.addListSelection(element);
7250 }
7251 }
7252 }
7253 if (this.mode === 'CheckBox') {
7254 this.updateDelimView();
7255 if (this.changeOnBlur) {
7256 this.updateValueState(null, this.value, this.tempValues);
7257 }
7258 this.updateDelimeter(this.delimiterChar);
7259 this.refreshInputHight();
7260 }
7261 else {
7262 this.updateDelimeter(this.delimiterChar);
7263 }
7264 if (this.mode === 'CheckBox' && this.showSelectAll && (isNullOrUndefined(this.value) || !this.value.length)) {
7265 this.notify('checkSelectAll', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', value: 'uncheck' });
7266 }
7267 if (this.mode === 'Box') {
7268 this.chipCollectionWrapper.style.display = '';
7269 }
7270 else if (this.mode === 'Delimiter' || this.mode === 'CheckBox') {
7271 this.showDelimWrapper();
7272 }
7273 }
7274 }
7275 updateActionCompleteData(li, item) {
7276 if (this.value && this.value.indexOf(li.getAttribute('data-value')) > -1) {
7277 this.mainList = this.ulElement;
7278 addClass([li], HIDE_LIST);
7279 }
7280 }
7281 updateDataList() {
7282 if (this.mainList && this.ulElement && this.mainList.childElementCount < this.ulElement.childElementCount) {
7283 this.mainList = this.ulElement.cloneNode ? this.ulElement.cloneNode(true) : this.ulElement;
7284 }
7285 }
7286 isValidLI(li) {
7287 return (li && !li.classList.contains(dropDownBaseClasses.disabled) && !li.classList.contains(dropDownBaseClasses.group) &&
7288 li.classList.contains(dropDownBaseClasses.li));
7289 }
7290 ;
7291 updateListSelection(li, e, length) {
7292 let customVal = li.getAttribute('data-value');
7293 let value = this.getFormattedValue(customVal);
7294 if (this.allowCustomValue && ((customVal !== 'false' && value === false) ||
7295 (!isNullOrUndefined(value) && value.toString() === 'NaN'))) {
7296 value = customVal;
7297 }
7298 let text = this.getTextByValue(value);
7299 this.removeHover();
7300 if (!this.value || this.value.indexOf(value) === -1) {
7301 this.dispatchSelect(value, e, li, (li.getAttribute('aria-selected') === 'true'), length);
7302 }
7303 else {
7304 this.removeValue(value, e, length);
7305 }
7306 }
7307 updateListSelectEventCallback(value, li, e) {
7308 let text = this.getTextByValue(value);
7309 if ((this.allowCustomValue || this.allowFiltering) && !this.findListElement(this.mainList, 'li', 'data-value', value)) {
7310 let temp = li.cloneNode(true);
7311 let data = this.getDataByValue(value);
7312 let eventArgs = {
7313 newData: data,
7314 cancel: false
7315 };
7316 this.trigger('customValueSelection', eventArgs, (eventArgs) => {
7317 if (!eventArgs.cancel) {
7318 append([temp], this.mainList);
7319 this.mainData.push(data);
7320 this.remoteCustomValue = false;
7321 this.addValue(value, text, e);
7322 }
7323 });
7324 }
7325 else {
7326 this.remoteCustomValue = false;
7327 this.addValue(value, text, e);
7328 }
7329 }
7330 removeListSelection() {
7331 let className = this.hideSelectedItem ?
7332 HIDE_LIST :
7333 dropDownBaseClasses.selected;
7334 let selectedItems = this.list.querySelectorAll('.' + className);
7335 let temp = selectedItems.length;
7336 if (selectedItems && selectedItems.length) {
7337 removeClass(selectedItems, className);
7338 while (temp > 0) {
7339 selectedItems[temp - 1].setAttribute('aria-selected', 'false');
7340 temp--;
7341 }
7342 }
7343 if (!isNullOrUndefined(this.mainList)) {
7344 let selectItems = this.mainList.querySelectorAll('.' + className);
7345 let temp1 = selectItems.length;
7346 if (selectItems && selectItems.length) {
7347 removeClass(selectItems, className);
7348 while (temp1 > 0) {
7349 selectItems[temp1 - 1].setAttribute('aria-selected', 'false');
7350 if (this.mode === 'CheckBox') {
7351 if (selectedItems && (selectedItems.length > (temp1 - 1))) {
7352 selectedItems[temp1 - 1].firstElementChild.setAttribute('aria-checked', 'false');
7353 removeClass([selectedItems[temp1 - 1].firstElementChild.lastElementChild], 'e-check');
7354 }
7355 selectItems[temp1 - 1].firstElementChild.setAttribute('aria-checked', 'false');
7356 removeClass([selectItems[temp1 - 1].firstElementChild.lastElementChild], 'e-check');
7357 }
7358 temp1--;
7359 }
7360 }
7361 }
7362 }
7363 ;
7364 removeHover() {
7365 let hoveredItem = this.list.querySelectorAll('.' + dropDownBaseClasses.hover);
7366 if (hoveredItem && hoveredItem.length) {
7367 removeClass(hoveredItem, dropDownBaseClasses.hover);
7368 }
7369 }
7370 ;
7371 removeFocus() {
7372 if (this.list && this.mainList) {
7373 let hoveredItem = this.list.querySelectorAll('.' + dropDownBaseClasses.focus);
7374 let mainlist = this.mainList.querySelectorAll('.' + dropDownBaseClasses.focus);
7375 if (hoveredItem && hoveredItem.length) {
7376 removeClass(hoveredItem, dropDownBaseClasses.focus);
7377 removeClass(mainlist, dropDownBaseClasses.focus);
7378 }
7379 }
7380 }
7381 ;
7382 addListHover(li) {
7383 if (this.enabled && this.isValidLI(li)) {
7384 this.removeHover();
7385 addClass([li], dropDownBaseClasses.hover);
7386 }
7387 else {
7388 if ((li !== null && li.classList.contains('e-list-group-item')) && this.enableGroupCheckBox && this.mode === 'CheckBox'
7389 && !isNullOrUndefined(this.fields.groupBy)) {
7390 this.removeHover();
7391 addClass([li], dropDownBaseClasses.hover);
7392 }
7393 }
7394 }
7395 ;
7396 addListFocus(element) {
7397 if (this.enabled && this.isValidLI(element)) {
7398 this.removeFocus();
7399 addClass([element], dropDownBaseClasses.focus);
7400 }
7401 else {
7402 if (this.enableGroupCheckBox && this.mode === 'CheckBox' && !isNullOrUndefined(this.fields.groupBy)) {
7403 addClass([element], dropDownBaseClasses.focus);
7404 }
7405 }
7406 }
7407 addListSelection(element) {
7408 let className = this.hideSelectedItem ?
7409 HIDE_LIST :
7410 dropDownBaseClasses.selected;
7411 if (this.isValidLI(element) && !element.classList.contains(dropDownBaseClasses.hover)) {
7412 addClass([element], className);
7413 this.updateMainList(false, element.getAttribute('data-value'));
7414 element.setAttribute('aria-selected', 'true');
7415 if (this.mode === 'CheckBox') {
7416 let ariaCheck = element.firstElementChild.getAttribute('aria-checked');
7417 if (ariaCheck === 'false' || isNullOrUndefined(ariaCheck)) {
7418 this.notify('updatelist', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', li: element, e: this });
7419 }
7420 }
7421 this.notify('activeList', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', li: element, e: this });
7422 if (this.chipCollectionWrapper !== null) {
7423 this.removeChipSelection();
7424 }
7425 attributes(this.inputElement, { 'aria-activedescendant': element.id });
7426 }
7427 }
7428 updateDelimeter(delimChar, e) {
7429 this.updateData(delimChar, e);
7430 }
7431 onMouseClick(e) {
7432 this.scrollFocusStatus = false;
7433 let target = e.target;
7434 let li = closest(target, '.' + dropDownBaseClasses.li);
7435 let headerLi = closest(target, '.' + dropDownBaseClasses.group);
7436 if (headerLi && this.enableGroupCheckBox && this.mode === 'CheckBox' && this.fields.groupBy) {
7437 target = target.classList.contains('e-list-group-item') ? target.firstElementChild.lastElementChild
7438 : e.target;
7439 if (target.classList.contains('e-check')) {
7440 this.selectAllItem(false, e);
7441 target.classList.remove('e-check');
7442 target.classList.remove('e-stop');
7443 closest(target, '.' + 'e-list-group-item').classList.remove('e-active');
7444 target.setAttribute('aria-selected', 'false');
7445 }
7446 else {
7447 this.selectAllItem(true, e);
7448 target.classList.remove('e-stop');
7449 target.classList.add('e-check');
7450 closest(target, '.' + 'e-list-group-item').classList.add('e-active');
7451 target.setAttribute('aria-selected', 'true');
7452 }
7453 this.refreshSelection();
7454 this.checkSelectAll();
7455 }
7456 else {
7457 if (this.isValidLI(li)) {
7458 let limit = this.value && this.value.length ? this.value.length : 0;
7459 if (li.classList.contains('e-active')) {
7460 limit = limit - 1;
7461 }
7462 if (limit < this.maximumSelectionLength) {
7463 this.updateListSelection(li, e);
7464 this.checkPlaceholderSize();
7465 this.addListFocus(li);
7466 if ((this.allowCustomValue || this.allowFiltering) && this.mainList && this.listData) {
7467 if (this.mode !== 'CheckBox') {
7468 this.focusAtLastListItem(li.getAttribute('data-value'));
7469 }
7470 this.refreshSelection();
7471 }
7472 else {
7473 this.makeTextBoxEmpty();
7474 }
7475 }
7476 if (this.mode === 'CheckBox') {
7477 this.updateDelimView();
7478 this.updateDelimeter(this.delimiterChar, e);
7479 this.refreshInputHight();
7480 }
7481 else {
7482 this.updateDelimeter(this.delimiterChar, e);
7483 }
7484 this.checkSelectAll();
7485 this.refreshPopup();
7486 if (this.hideSelectedItem) {
7487 this.focusAtFirstListItem();
7488 }
7489 if (this.closePopupOnSelect) {
7490 this.hidePopup();
7491 }
7492 else {
7493 e.preventDefault();
7494 }
7495 this.makeTextBoxEmpty();
7496 this.findGroupStart(target);
7497 }
7498 else {
7499 e.preventDefault();
7500 }
7501 if (this.mode !== 'CheckBox') {
7502 this.refreshListItems(isNullOrUndefined(li) ? null : li.textContent);
7503 }
7504 this.refreshPlaceHolder();
7505 this.deselectHeader();
7506 }
7507 }
7508 findGroupStart(target) {
7509 if (this.enableGroupCheckBox && this.mode === 'CheckBox' && !isNullOrUndefined(this.fields.groupBy)) {
7510 let count = 0;
7511 let liChecked = 0;
7512 let liUnchecked = 0;
7513 let groupValues;
7514 if (this.itemTemplate && !target.getElementsByClassName('e-frame').length) {
7515 while (!target.getElementsByClassName('e-frame').length) {
7516 target = target.parentElement;
7517 }
7518 }
7519 if (target.classList.contains('e-frame')) {
7520 target = target.parentElement.parentElement;
7521 }
7522 groupValues = this.findGroupAttrtibutes(target, liChecked, liUnchecked, count, 0);
7523 groupValues = this.findGroupAttrtibutes(target, groupValues[0], groupValues[1], groupValues[2], 1);
7524 while (!target.classList.contains('e-list-group-item')) {
7525 if (target.classList.contains('e-list-icon')) {
7526 target = target.parentElement;
7527 }
7528 target = target.previousElementSibling;
7529 if (target == null) {
7530 break;
7531 }
7532 }
7533 this.updateCheckBox(target, groupValues[0], groupValues[1], groupValues[2]);
7534 }
7535 }
7536 findGroupAttrtibutes(listElement, checked, unChecked, count, position) {
7537 while (!listElement.classList.contains('e-list-group-item')) {
7538 if (listElement.classList.contains('e-list-icon')) {
7539 listElement = listElement.parentElement;
7540 }
7541 if (listElement.getElementsByClassName('e-frame')[0].classList.contains('e-check') &&
7542 listElement.classList.contains('e-list-item')) {
7543 checked++;
7544 }
7545 else if (listElement.classList.contains('e-list-item')) {
7546 unChecked++;
7547 }
7548 count++;
7549 listElement = position ? listElement.nextElementSibling : listElement.previousElementSibling;
7550 if (listElement == null) {
7551 break;
7552 }
7553 }
7554 return [checked, unChecked, count];
7555 }
7556 updateCheckBox(groupHeader, checked, unChecked, count) {
7557 if (groupHeader === null) {
7558 return;
7559 }
7560 let checkBoxElement = groupHeader.getElementsByClassName('e-frame')[0];
7561 if (count === checked) {
7562 checkBoxElement.classList.remove('e-stop');
7563 checkBoxElement.classList.add('e-check');
7564 closest(checkBoxElement, '.' + 'e-list-group-item').classList.add('e-active');
7565 groupHeader.setAttribute('aria-selected', 'true');
7566 }
7567 else if (count === unChecked) {
7568 checkBoxElement.classList.remove('e-check');
7569 checkBoxElement.classList.remove('e-stop');
7570 closest(checkBoxElement, '.' + 'e-list-group-item').classList.remove('e-active');
7571 groupHeader.setAttribute('aria-selected', 'false');
7572 }
7573 else if (this.maximumSelectionLength === checked - 1) {
7574 checkBoxElement.classList.remove('e-stop');
7575 groupHeader.setAttribute('aria-selected', 'true');
7576 closest(checkBoxElement, '.' + 'e-list-group-item').classList.add('e-active');
7577 checkBoxElement.classList.add('e-check');
7578 }
7579 else {
7580 checkBoxElement.classList.remove('e-check');
7581 checkBoxElement.classList.add('e-stop');
7582 closest(checkBoxElement, '.' + 'e-list-group-item').classList.add('e-active');
7583 groupHeader.setAttribute('aria-selected', 'false');
7584 }
7585 }
7586 deselectHeader() {
7587 let limit = this.value && this.value.length ? this.value.length : 0;
7588 let collection = this.list.querySelectorAll('li.e-list-group-item:not(.e-active)');
7589 if (limit < this.maximumSelectionLength) {
7590 removeClass(collection, 'e-disable');
7591 }
7592 if (limit === this.maximumSelectionLength) {
7593 addClass(collection, 'e-disable');
7594 }
7595 }
7596 onMouseOver(e) {
7597 let currentLi = closest(e.target, '.' + dropDownBaseClasses.li);
7598 if (currentLi === null && this.mode === 'CheckBox' && !isNullOrUndefined(this.fields.groupBy)
7599 && this.enableGroupCheckBox) {
7600 currentLi = closest(e.target, '.' + dropDownBaseClasses.group);
7601 }
7602 this.addListHover(currentLi);
7603 }
7604 onMouseLeave(e) {
7605 this.removeHover();
7606 }
7607 onListMouseDown(e) {
7608 e.preventDefault();
7609 this.scrollFocusStatus = true;
7610 }
7611 onDocumentClick(e) {
7612 if (this.mode !== 'CheckBox') {
7613 let target = e.target;
7614 if (!(!isNullOrUndefined(this.popupObj) && closest(target, '#' + this.popupObj.element.id)) &&
7615 !this.overAllWrapper.contains(e.target)) {
7616 this.scrollFocusStatus = false;
7617 }
7618 else {
7619 this.scrollFocusStatus = (Browser.isIE || Browser.info.name === 'edge') && (document.activeElement === this.inputElement);
7620 }
7621 }
7622 }
7623 wireListEvents() {
7624 EventHandler.add(document, 'mousedown', this.onDocumentClick, this);
7625 EventHandler.add(this.list, 'mousedown', this.onListMouseDown, this);
7626 EventHandler.add(this.list, 'mouseup', this.onMouseClick, this);
7627 EventHandler.add(this.list, 'mouseover', this.onMouseOver, this);
7628 EventHandler.add(this.list, 'mouseout', this.onMouseLeave, this);
7629 }
7630 ;
7631 unwireListEvents() {
7632 EventHandler.remove(document, 'mousedown', this.onDocumentClick);
7633 if (this.list) {
7634 EventHandler.remove(this.list, 'mousedown', this.onListMouseDown);
7635 EventHandler.remove(this.list, 'mouseup', this.onMouseClick);
7636 EventHandler.remove(this.list, 'mouseover', this.onMouseOver);
7637 EventHandler.remove(this.list, 'mouseout', this.onMouseLeave);
7638 }
7639 }
7640 ;
7641 hideOverAllClear() {
7642 if (!this.value || !this.value.length || this.inputElement.value === '') {
7643 this.overAllClear.style.display = 'none';
7644 }
7645 }
7646 showOverAllClear() {
7647 if (((this.value && this.value.length) || this.inputElement.value !== '') && this.showClearButton && this.readonly !== true) {
7648 this.overAllClear.style.display = '';
7649 }
7650 else {
7651 this.overAllClear.style.display = 'none';
7652 }
7653 }
7654 /**
7655 * Sets the focus to widget for interaction.
7656 * @returns void
7657 */
7658 focusIn() {
7659 if (document.activeElement !== this.inputElement && this.enabled) {
7660 this.inputElement.focus();
7661 }
7662 }
7663 /**
7664 * Remove the focus from widget, if the widget is in focus state.
7665 * @returns void
7666 */
7667 focusOut() {
7668 if (document.activeElement === this.inputElement && this.enabled) {
7669 this.inputElement.blur();
7670 }
7671 }
7672 /**
7673 * Shows the spinner loader.
7674 * @returns void.
7675 */
7676 showSpinner() {
7677 if (isNullOrUndefined(this.spinnerElement)) {
7678 if (this.overAllClear.style.display !== 'none') {
7679 this.spinnerElement = this.overAllClear;
7680 }
7681 else {
7682 this.spinnerElement = this.createElement('span', { className: CLOSEICON_CLASS + ' ' + SPINNER_CLASS$1 });
7683 this.componentWrapper.appendChild(this.spinnerElement);
7684 }
7685 createSpinner({ target: this.spinnerElement, width: Browser.isDevice ? '16px' : '14px' }, this.createElement);
7686 addClass([this.spinnerElement], DISABLE_ICON);
7687 showSpinner(this.spinnerElement);
7688 }
7689 }
7690 /**
7691 * Hides the spinner loader.
7692 * @returns void.
7693 */
7694 hideSpinner() {
7695 if (!isNullOrUndefined(this.spinnerElement)) {
7696 hideSpinner(this.spinnerElement);
7697 removeClass([this.spinnerElement], DISABLE_ICON);
7698 if (this.spinnerElement.classList.contains(SPINNER_CLASS$1)) {
7699 detach(this.spinnerElement);
7700 }
7701 else {
7702 this.spinnerElement.innerHTML = '';
7703 }
7704 this.spinnerElement = null;
7705 }
7706 }
7707 updateDelimView() {
7708 if (this.delimiterWrapper) {
7709 this.hideDelimWrapper();
7710 }
7711 if (this.chipCollectionWrapper) {
7712 this.chipCollectionWrapper.style.display = 'none';
7713 }
7714 this.viewWrapper.style.display = '';
7715 this.viewWrapper.style.width = '';
7716 this.viewWrapper.classList.remove(TOTAL_COUNT_WRAPPER);
7717 if (this.value && this.value.length) {
7718 let data = '';
7719 let temp;
7720 let tempData;
7721 let tempIndex = 1;
7722 let wrapperleng;
7723 let remaining;
7724 let downIconWidth = 0;
7725 let overAllContainer;
7726 this.viewWrapper.innerHTML = '';
7727 let l10nLocale = {
7728 noRecordsTemplate: 'No Records Found',
7729 actionFailureTemplate: 'The Request Failed',
7730 overflowCountTemplate: '+${count} more..',
7731 totalCountTemplate: '${count} selected'
7732 };
7733 let l10n = new L10n(this.getLocaleName(), {}, this.locale);
7734 if (l10n.getConstant('actionFailureTemplate') === '') {
7735 l10n = new L10n('dropdowns', l10nLocale, this.locale);
7736 }
7737 let remainContent = l10n.getConstant('overflowCountTemplate');
7738 let raminElement = this.createElement('span', {
7739 className: REMAIN_WRAPPER
7740 });
7741 let compiledString = compile(remainContent);
7742 let totalCompiledString = compile(l10n.getConstant('totalCountTemplate'));
7743 raminElement.appendChild(compiledString({ 'count': this.value.length }, null, null, null, !this.isStringTemplate)[0]);
7744 this.viewWrapper.appendChild(raminElement);
7745 let remainSize = raminElement.offsetWidth;
7746 remove(raminElement);
7747 if (this.showDropDownIcon) {
7748 downIconWidth = this.dropIcon.offsetWidth +
7749 parseInt(window.getComputedStyle(this.dropIcon).marginRight, 10);
7750 }
7751 if (!isNullOrUndefined(this.value)) {
7752 for (let index = 0; !isNullOrUndefined(this.value[index]); index++) {
7753 data += (index === 0) ? '' : this.delimiterChar + ' ';
7754 temp = this.getOverflowVal(index);
7755 data += temp;
7756 temp = this.viewWrapper.innerHTML;
7757 this.viewWrapper.innerHTML = data;
7758 wrapperleng = this.viewWrapper.offsetWidth +
7759 parseInt(window.getComputedStyle(this.viewWrapper).paddingRight, 10);
7760 overAllContainer = this.componentWrapper.offsetWidth -
7761 parseInt(window.getComputedStyle(this.componentWrapper).paddingLeft, 10) -
7762 parseInt(window.getComputedStyle(this.componentWrapper).paddingRight, 10);
7763 if ((wrapperleng + downIconWidth) > overAllContainer) {
7764 if (tempData !== undefined && tempData !== '') {
7765 temp = tempData;
7766 index = tempIndex + 1;
7767 }
7768 this.viewWrapper.innerHTML = temp;
7769 remaining = this.value.length - index;
7770 wrapperleng = this.viewWrapper.offsetWidth;
7771 while (((wrapperleng + remainSize + downIconWidth) > overAllContainer) && wrapperleng !== 0
7772 && this.viewWrapper.innerHTML !== '') {
7773 let textArr = this.viewWrapper.innerHTML.split(this.delimiterChar);
7774 textArr.pop();
7775 this.viewWrapper.innerHTML = textArr.join(this.delimiterChar);
7776 remaining++;
7777 wrapperleng = this.viewWrapper.offsetWidth;
7778 }
7779 break;
7780 }
7781 else if ((wrapperleng + remainSize + downIconWidth) <= overAllContainer) {
7782 tempData = data;
7783 tempIndex = index;
7784 }
7785 else if (index === 0) {
7786 tempData = '';
7787 tempIndex = -1;
7788 }
7789 }
7790 }
7791 if (remaining > 0) {
7792 let totalWidth = overAllContainer - downIconWidth;
7793 this.viewWrapper.appendChild(this.updateRemainTemplate(raminElement, this.viewWrapper, remaining, compiledString, totalCompiledString, totalWidth));
7794 this.updateRemainWidth(this.viewWrapper, totalWidth);
7795 this.updateRemainingText(raminElement, downIconWidth, remaining, compiledString, totalCompiledString);
7796 }
7797 }
7798 else {
7799 this.viewWrapper.innerHTML = '';
7800 this.viewWrapper.style.display = 'none';
7801 }
7802 }
7803 updateRemainWidth(viewWrapper, totalWidth) {
7804 if (viewWrapper.classList.contains(TOTAL_COUNT_WRAPPER) && totalWidth < (viewWrapper.offsetWidth +
7805 parseInt(window.getComputedStyle(viewWrapper).paddingLeft, 10)
7806 + parseInt(window.getComputedStyle(viewWrapper).paddingLeft, 10))) {
7807 viewWrapper.style.width = totalWidth + 'px';
7808 }
7809 }
7810 updateRemainTemplate(raminElement, viewWrapper, remaining, compiledString, totalCompiledString, totalWidth) {
7811 if (viewWrapper.firstChild && viewWrapper.firstChild.nodeType === 3 && viewWrapper.firstChild.nodeValue === '') {
7812 viewWrapper.removeChild(viewWrapper.firstChild);
7813 }
7814 raminElement.innerHTML = '';
7815 raminElement.appendChild((viewWrapper.firstChild && viewWrapper.firstChild.nodeType === 3) ?
7816 compiledString({ 'count': remaining }, null, null, null, !this.isStringTemplate)[0] :
7817 totalCompiledString({ 'count': remaining }, null, null, null, !this.isStringTemplate)[0]);
7818 if (viewWrapper.firstChild && viewWrapper.firstChild.nodeType === 3) {
7819 viewWrapper.classList.remove(TOTAL_COUNT_WRAPPER);
7820 }
7821 else {
7822 viewWrapper.classList.add(TOTAL_COUNT_WRAPPER);
7823 this.updateRemainWidth(viewWrapper, totalWidth);
7824 }
7825 return raminElement;
7826 }
7827 updateRemainingText(raminElement, downIconWidth, remaining, compiledString, totalCompiledString) {
7828 let overAllContainer = this.componentWrapper.offsetWidth -
7829 parseInt(window.getComputedStyle(this.componentWrapper).paddingLeft, 10) -
7830 parseInt(window.getComputedStyle(this.componentWrapper).paddingRight, 10);
7831 let wrapperleng = this.viewWrapper.offsetWidth + parseInt(window.getComputedStyle(this.viewWrapper).paddingRight, 10);
7832 if (((wrapperleng + downIconWidth) >= overAllContainer) && wrapperleng !== 0 && this.viewWrapper.firstChild &&
7833 this.viewWrapper.firstChild.nodeType === 3) {
7834 while (((wrapperleng + downIconWidth) > overAllContainer) && wrapperleng !== 0 && this.viewWrapper.firstChild &&
7835 this.viewWrapper.firstChild.nodeType === 3) {
7836 let textArr = this.viewWrapper.firstChild.nodeValue.split(this.delimiterChar);
7837 textArr.pop();
7838 this.viewWrapper.firstChild.nodeValue = textArr.join(this.delimiterChar);
7839 if (this.viewWrapper.firstChild.nodeValue === '') {
7840 this.viewWrapper.removeChild(this.viewWrapper.firstChild);
7841 }
7842 remaining++;
7843 wrapperleng = this.viewWrapper.offsetWidth;
7844 }
7845 let totalWidth = overAllContainer - downIconWidth;
7846 this.updateRemainTemplate(raminElement, this.viewWrapper, remaining, compiledString, totalCompiledString, totalWidth);
7847 }
7848 }
7849 getOverflowVal(index) {
7850 let temp;
7851 if (this.mainData && this.mainData.length) {
7852 if (this.mode === 'CheckBox') {
7853 let newTemp = this.listData;
7854 this.listData = this.mainData;
7855 temp = this.getTextByValue(this.value[index]);
7856 this.listData = newTemp;
7857 }
7858 else {
7859 temp = this.getTextByValue(this.value[index]);
7860 }
7861 }
7862 else {
7863 temp = this.value[index];
7864 }
7865 return temp;
7866 }
7867 unWireEvent() {
7868 EventHandler.remove(this.componentWrapper, 'mousedown', this.wrapperClick);
7869 EventHandler.remove(window, 'resize', this.windowResize);
7870 EventHandler.remove(this.inputElement, 'focus', this.focusInHandler);
7871 EventHandler.remove(this.inputElement, 'keydown', this.onKeyDown);
7872 if (this.mode !== 'CheckBox') {
7873 EventHandler.remove(this.inputElement, 'input', this.onInput);
7874 }
7875 EventHandler.remove(this.inputElement, 'keyup', this.KeyUp);
7876 let formElement = closest(this.inputElement, 'form');
7877 if (formElement) {
7878 EventHandler.remove(formElement, 'reset', this.resetValueHandler);
7879 }
7880 EventHandler.remove(this.inputElement, 'blur', this.onBlur);
7881 EventHandler.remove(this.componentWrapper, 'mousemove', this.mouseIn);
7882 EventHandler.remove(this.componentWrapper, 'mouseout', this.mouseOut);
7883 EventHandler.remove(this.overAllClear, 'mousedown', this.ClearAll);
7884 }
7885 selectAllItem(state, event, list) {
7886 let li;
7887 li = this.list.querySelectorAll(state ?
7888 'li.e-list-item:not([aria-selected="true"]):not(.e-reorder-hide)' :
7889 'li.e-list-item[aria-selected="true"]:not(.e-reorder-hide)');
7890 if (this.enableGroupCheckBox && this.mode === 'CheckBox' && !isNullOrUndefined(this.fields.groupBy)) {
7891 let target = (event ? event.target : null);
7892 target = (event && event.keyCode === 32) ? list : target;
7893 target = (target && target.classList.contains('e-frame')) ? target.parentElement.parentElement : target;
7894 if (target && target.classList.contains('e-list-group-item')) {
7895 let listElement = target.nextElementSibling;
7896 if (isNullOrUndefined(listElement)) {
7897 return;
7898 }
7899 while (listElement.classList.contains('e-list-item')) {
7900 if (state) {
7901 if (!listElement.firstElementChild.lastElementChild.classList.contains('e-check')) {
7902 let selectionLimit = this.value && this.value.length ? this.value.length : 0;
7903 if (listElement.classList.contains('e-active')) {
7904 selectionLimit -= 1;
7905 }
7906 if (selectionLimit < this.maximumSelectionLength) {
7907 this.updateListSelection(listElement, event);
7908 }
7909 }
7910 }
7911 else {
7912 if (listElement.firstElementChild.lastElementChild.classList.contains('e-check')) {
7913 this.updateListSelection(listElement, event);
7914 }
7915 }
7916 listElement = listElement.nextElementSibling;
7917 if (listElement == null) {
7918 break;
7919 }
7920 }
7921 if (target.classList.contains('e-list-group-item')) {
7922 let focusedElement = this.list.getElementsByClassName('e-item-focus')[0];
7923 if (focusedElement) {
7924 focusedElement.classList.remove('e-item-focus');
7925 }
7926 state ? target.classList.add('e-active') : target.classList.remove('e-active');
7927 target.classList.add('e-item-focus');
7928 }
7929 this.textboxValueUpdate();
7930 this.checkPlaceholderSize();
7931 if (!this.changeOnBlur && event) {
7932 this.updateValueState(event, this.value, this.tempValues);
7933 }
7934 }
7935 else {
7936 this.updateValue(event, li, state);
7937 }
7938 }
7939 else {
7940 this.updateValue(event, li, state);
7941 }
7942 }
7943 updateValue(event, li, state) {
7944 let length = li.length;
7945 if (li && li.length) {
7946 let index = 0;
7947 let count = 0;
7948 if (this.enableGroupCheckBox) {
7949 count = state ? this.maximumSelectionLength - (this.value ? this.value.length : 0) : li.length;
7950 }
7951 else {
7952 count = state ? this.maximumSelectionLength - (this.value ? this.value.length : 0) : this.maximumSelectionLength;
7953 }
7954 while (index < length && index <= 50 && index < count) {
7955 this.updateListSelection(li[index], event, length - index);
7956 this.findGroupStart(li[index]);
7957 index++;
7958 }
7959 this.deselectHeader();
7960 if (length > 50) {
7961 setTimeout(() => {
7962 while (index < length && index < count) {
7963 this.updateListSelection(li[index], event, length - index);
7964 this.findGroupStart(li[index]);
7965 index++;
7966 }
7967 this.deselectHeader();
7968 this.textboxValueUpdate(event);
7969 }, 0);
7970 }
7971 }
7972 this.textboxValueUpdate(event);
7973 this.checkPlaceholderSize();
7974 }
7975 textboxValueUpdate(event) {
7976 if (this.mode !== 'Box' && !this.isPopupOpen()) {
7977 this.updateDelimView();
7978 }
7979 else {
7980 this.searchWrapper.classList.remove(ZERO_SIZE);
7981 }
7982 if (this.mode === 'CheckBox') {
7983 this.updateDelimView();
7984 this.updateDelimeter(this.delimiterChar, event);
7985 this.refreshInputHight();
7986 }
7987 else {
7988 this.updateDelimeter(this.delimiterChar, event);
7989 }
7990 this.refreshPlaceHolder();
7991 }
7992 setZIndex() {
7993 if (this.popupObj) {
7994 this.popupObj.setProperties({ 'zIndex': this.zIndex });
7995 }
7996 }
7997 updateDataSource(prop) {
7998 if (isNullOrUndefined(this.list)) {
7999 this.renderPopup();
8000 }
8001 else {
8002 this.resetList(this.dataSource);
8003 }
8004 if (this.value && this.value.length) {
8005 this.setProperties({ 'value': this.value });
8006 this.refreshSelection();
8007 }
8008 }
8009 onLoadSelect() {
8010 this.setDynValue = true;
8011 this.renderPopup();
8012 }
8013 selectAllItems(state, event) {
8014 if (isNullOrUndefined(this.list)) {
8015 this.selectAllAction = () => {
8016 if (this.mode === 'CheckBox' && this.showSelectAll) {
8017 let args = {
8018 module: 'CheckBoxSelection',
8019 enable: this.mode === 'CheckBox',
8020 value: state ? 'check' : 'uncheck'
8021 };
8022 this.notify('checkSelectAll', args);
8023 }
8024 this.selectAllItem(state, event);
8025 this.selectAllAction = null;
8026 };
8027 super.render();
8028 }
8029 else {
8030 this.selectAllAction = null;
8031 if (this.mode === 'CheckBox' && this.showSelectAll) {
8032 let args = {
8033 value: state ? 'check' : 'uncheck',
8034 enable: this.mode === 'CheckBox',
8035 module: 'CheckBoxSelection'
8036 };
8037 this.notify('checkSelectAll', args);
8038 }
8039 this.selectAllItem(state, event);
8040 }
8041 }
8042 /**
8043 * Get the properties to be maintained in the persisted state.
8044 */
8045 getPersistData() {
8046 return this.addOnPersist(['value']);
8047 }
8048 ;
8049 /**
8050 * Dynamically change the value of properties.
8051 * @private
8052 */
8053 onPropertyChanged(newProp, oldProp) {
8054 if (newProp.dataSource && !isNullOrUndefined(Object.keys(newProp.dataSource))) {
8055 this.mainList = null;
8056 this.mainData = null;
8057 this.isFirstClick = false;
8058 }
8059 if (this.getModuleName() === 'multiselect') {
8060 this.filterAction = false;
8061 this.setUpdateInitial(['fields', 'query', 'dataSource'], newProp);
8062 }
8063 for (let prop of Object.keys(newProp)) {
8064 switch (prop) {
8065 case 'query':
8066 case 'dataSource':
8067 if (this.mode === 'CheckBox' && this.showSelectAll) {
8068 if (!isNullOrUndefined(this.popupObj)) {
8069 this.popupObj.destroy();
8070 this.popupObj = null;
8071 }
8072 this.renderPopup();
8073 }
8074 break;
8075 case 'htmlAttributes':
8076 this.updateHTMLAttribute();
8077 break;
8078 case 'showClearButton':
8079 this.updateClearButton(newProp.showClearButton);
8080 break;
8081 case 'text':
8082 this.updateVal(this.value, this.value, 'text');
8083 break;
8084 case 'value':
8085 this.updateVal(this.value, oldProp.value, 'value');
8086 this.addValidInputClass();
8087 break;
8088 case 'width':
8089 this.setWidth(newProp.width);
8090 this.popupObj.setProperties({ width: this.calcPopupWidth() });
8091 break;
8092 case 'placeholder':
8093 this.refreshPlaceHolder();
8094 break;
8095 case 'filterBarPlaceholder':
8096 if (this.allowFiltering) {
8097 this.notify('filterBarPlaceholder', { filterBarPlaceholder: newProp.filterBarPlaceholder });
8098 }
8099 break;
8100 case 'delimiterChar':
8101 if (this.mode !== 'Box') {
8102 this.updateDelimView();
8103 }
8104 this.updateData(newProp.delimiterChar);
8105 break;
8106 case 'cssClass':
8107 if (!isNullOrUndefined(oldProp.cssClass) && oldProp.cssClass !== '') {
8108 removeClass([this.overAllWrapper], oldProp.cssClass.split(' '));
8109 removeClass([this.popupWrapper], oldProp.cssClass.split(' '));
8110 }
8111 this.updateCssClass();
8112 break;
8113 case 'enableRtl':
8114 this.enableRTL(newProp.enableRtl);
8115 super.onPropertyChanged(newProp, oldProp);
8116 break;
8117 case 'readonly':
8118 this.updateReadonly(newProp.readonly);
8119 this.hidePopup();
8120 break;
8121 case 'enabled':
8122 this.hidePopup();
8123 this.enable(newProp.enabled);
8124 break;
8125 case 'showSelectAll':
8126 if (this.popupObj) {
8127 this.popupObj.destroy();
8128 this.popupObj = null;
8129 }
8130 this.renderPopup();
8131 break;
8132 case 'showDropDownIcon':
8133 this.dropDownIcon();
8134 break;
8135 case 'floatLabelType':
8136 this.setFloatLabelType();
8137 this.addValidInputClass();
8138 break;
8139 case 'enableSelectionOrder':
8140 break;
8141 case 'selectAllText':
8142 this.notify('selectAllText', false);
8143 break;
8144 case 'popupHeight':
8145 case 'headerTemplate':
8146 case 'footerTemplate':
8147 this.reInitializePoup();
8148 break;
8149 case 'allowFiltering':
8150 if (this.mode === 'CheckBox' && this.popupObj) {
8151 this.reInitializePoup();
8152 }
8153 this.updateSelectElementData(this.allowFiltering);
8154 break;
8155 default:
8156 let msProps;
8157 msProps = this.getPropObject(prop, newProp, oldProp);
8158 super.onPropertyChanged(msProps.newProperty, msProps.oldProperty);
8159 break;
8160 }
8161 }
8162 }
8163 reInitializePoup() {
8164 if (this.popupObj) {
8165 this.popupObj.destroy();
8166 this.popupObj = null;
8167 }
8168 this.renderPopup();
8169 }
8170 updateVal(newProp, oldProp, prop) {
8171 if (!this.list) {
8172 this.onLoadSelect();
8173 }
8174 else if (!this.inputFocus) {
8175 if (prop === 'text') {
8176 this.initialTextUpdate();
8177 newProp = this.value;
8178 }
8179 if (this.value && this.value.length === 0) {
8180 this.tempValues = oldProp;
8181 }
8182 this.initialValueUpdate();
8183 if (this.mode !== 'Box') {
8184 this.updateDelimView();
8185 }
8186 this.refreshInputHight();
8187 this.refreshPlaceHolder();
8188 if (this.mode !== 'CheckBox' && this.changeOnBlur) {
8189 this.updateValueState(null, newProp, oldProp);
8190 }
8191 this.checkPlaceholderSize();
8192 }
8193 if (!this.changeOnBlur) {
8194 this.updateValueState(null, newProp, oldProp);
8195 }
8196 }
8197 /**
8198 * Adds a new item to the multiselect popup list. By default, new item appends to the list as the last item,
8199 * but you can insert based on the index parameter.
8200 * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
8201 * @param { number } itemIndex - Specifies the index to place the newly added item in the popup list.
8202 * @return {void}.
8203 */
8204 addItem(items, itemIndex) {
8205 super.addItem(items, itemIndex);
8206 }
8207 /**
8208 * Hides the popup, if the popup in a open state.
8209 * @returns void
8210 */
8211 hidePopup() {
8212 let delay = 100;
8213 if (this.isPopupOpen()) {
8214 let animModel = {
8215 name: 'FadeOut',
8216 duration: 100,
8217 delay: delay ? delay : 0
8218 };
8219 let eventArgs = { popup: this.popupObj, cancel: false, animation: animModel };
8220 this.trigger('close', eventArgs, (eventArgs) => {
8221 if (!eventArgs.cancel) {
8222 this.beforePopupOpen = false;
8223 this.overAllWrapper.classList.remove(iconAnimation);
8224 this.popupObj.hide(new Animation(eventArgs.animation));
8225 attributes(this.inputElement, { 'aria-expanded': 'false' });
8226 if (this.allowFiltering) {
8227 this.notify('inputFocus', { module: 'CheckBoxSelection', enable: this.mode === 'CheckBox', value: 'clear' });
8228 }
8229 this.popupObj.hide();
8230 removeClass([document.body, this.popupObj.element], 'e-popup-full-page');
8231 EventHandler.remove(this.list, 'keydown', this.onKeyDown);
8232 }
8233 });
8234 }
8235 }
8236 /**
8237 * Shows the popup, if the popup in a closed state.
8238 * @returns void
8239 */
8240 showPopup() {
8241 if (!this.enabled) {
8242 return;
8243 }
8244 if (isBlazor() && this.itemTemplate) {
8245 this.DropDownBaseupdateBlazorTemplates(true, false, false, false, false, false, false, false);
8246 if (this.mode !== 'CheckBox' && this.list) {
8247 this.refreshSelection();
8248 }
8249 }
8250 if (!this.ulElement) {
8251 this.beforePopupOpen = true;
8252 super.render();
8253 return;
8254 }
8255 let mainLiLength = this.ulElement.querySelectorAll('li.' + 'e-list-item').length;
8256 let liLength = this.ulElement.querySelectorAll('li.'
8257 + dropDownBaseClasses.li + '.' + HIDE_LIST).length;
8258 if (mainLiLength > 0 && (mainLiLength === liLength) && (liLength === this.mainData.length)) {
8259 this.beforePopupOpen = false;
8260 return;
8261 }
8262 this.onPopupShown();
8263 }
8264 /**
8265 * Based on the state parameter, entire list item will be selected/deselected.
8266 * parameter
8267 * `true` - Selects entire list items.
8268 * `false` - Un Selects entire list items.
8269 * @returns void
8270 */
8271 selectAll(state) {
8272 this.isSelectAll = true;
8273 this.selectAllItems(state);
8274 }
8275 getModuleName() {
8276 return 'multiselect';
8277 }
8278 ;
8279 /**
8280 * Allows you to clear the selected values from the Multiselect component.
8281 * @returns void
8282 */
8283 clear() {
8284 this.selectAll(false);
8285 this.setProperties({ value: null }, true);
8286 }
8287 /**
8288 * To Initialize the control rendering
8289 * @private
8290 */
8291 render() {
8292 this.setDynValue = this.initStatus = false;
8293 this.isSelectAll = false;
8294 this.searchWrapper = this.createElement('span', { className: SEARCHBOX_WRAPPER + ' ' + ((this.mode === 'Box') ? BOX_ELEMENT : '') });
8295 this.viewWrapper = this.createElement('span', { className: DELIMITER_VIEW + ' ' + DELIMITER_WRAPPER, styles: 'display:none;' });
8296 this.overAllClear = this.createElement('span', {
8297 className: CLOSEICON_CLASS, styles: 'display:none;'
8298 });
8299 this.componentWrapper = this.createElement('div', { className: ELEMENT_WRAPPER });
8300 this.overAllWrapper = this.createElement('div', { className: OVER_ALL_WRAPPER });
8301 if (this.mode === 'CheckBox') {
8302 addClass([this.overAllWrapper], 'e-checkbox');
8303 }
8304 if (Browser.isDevice) {
8305 this.componentWrapper.classList.add(ELEMENT_MOBILE_WRAPPER);
8306 }
8307 this.setWidth(this.width);
8308 this.overAllWrapper.appendChild(this.componentWrapper);
8309 this.popupWrapper = this.createElement('div', { id: this.element.id + '_popup', className: POPUP_WRAPPER });
8310 if (this.mode === 'Delimiter' || this.mode === 'CheckBox') {
8311 this.delimiterWrapper = this.createElement('span', { className: DELIMITER_WRAPPER, styles: 'display:none' });
8312 this.componentWrapper.appendChild(this.delimiterWrapper);
8313 }
8314 else {
8315 this.chipCollectionWrapper = this.createElement('span', {
8316 className: CHIP_WRAPPER,
8317 styles: 'display:none'
8318 });
8319 if (this.mode === 'Default') {
8320 this.chipCollectionWrapper.setAttribute('id', getUniqueID('chip_default'));
8321 }
8322 else if (this.mode === 'Box') {
8323 this.chipCollectionWrapper.setAttribute('id', getUniqueID('chip_box'));
8324 }
8325 this.componentWrapper.appendChild(this.chipCollectionWrapper);
8326 }
8327 if (this.mode !== 'Box') {
8328 this.componentWrapper.appendChild(this.viewWrapper);
8329 }
8330 this.componentWrapper.appendChild(this.searchWrapper);
8331 if (this.showClearButton && !Browser.isDevice) {
8332 this.componentWrapper.appendChild(this.overAllClear);
8333 }
8334 else {
8335 this.componentWrapper.classList.add(CLOSE_ICON_HIDE);
8336 }
8337 this.dropDownIcon();
8338 this.inputElement = this.createElement('input', {
8339 className: INPUT_ELEMENT,
8340 attrs: {
8341 spellcheck: 'false',
8342 type: 'text',
8343 autocomplete: 'off',
8344 tabindex: '0'
8345 }
8346 });
8347 if (this.mode === 'Default' || this.mode === 'Box') {
8348 this.inputElement.setAttribute('aria-describedby', this.chipCollectionWrapper.id);
8349 }
8350 if (this.element.tagName !== this.getNgDirective()) {
8351 this.element.style.display = 'none';
8352 }
8353 if (this.element.tagName === this.getNgDirective()) {
8354 this.element.appendChild(this.overAllWrapper);
8355 this.searchWrapper.appendChild(this.inputElement);
8356 }
8357 else {
8358 this.element.parentElement.insertBefore(this.overAllWrapper, this.element);
8359 this.searchWrapper.appendChild(this.inputElement);
8360 this.searchWrapper.appendChild(this.element);
8361 this.element.removeAttribute('tabindex');
8362 }
8363 if (this.floatLabelType !== 'Never') {
8364 createFloatLabel(this.overAllWrapper, this.searchWrapper, this.element, this.inputElement, this.value, this.floatLabelType, this.placeholder);
8365 }
8366 else if (this.floatLabelType === 'Never') {
8367 this.refreshPlaceHolder();
8368 }
8369 this.addValidInputClass();
8370 this.element.style.opacity = '';
8371 let id = this.element.getAttribute('id') ? this.element.getAttribute('id') : getUniqueID('ej2_dropdownlist');
8372 this.element.id = id;
8373 this.hiddenElement = this.createElement('select', {
8374 attrs: { 'aria-hidden': 'true', 'class': HIDDEN_ELEMENT, 'tabindex': '-1', 'multiple': '' }
8375 });
8376 this.componentWrapper.appendChild(this.hiddenElement);
8377 this.validationAttribute(this.element, this.hiddenElement);
8378 if (this.mode !== 'CheckBox') {
8379 this.hideOverAllClear();
8380 }
8381 this.wireEvent();
8382 this.enable(this.enabled);
8383 this.enableRTL(this.enableRtl);
8384 this.checkInitialValue();
8385 this.renderComplete();
8386 }
8387 checkInitialValue() {
8388 let isData = this.dataSource instanceof Array ? (this.dataSource.length > 0)
8389 : !isNullOrUndefined(this.dataSource);
8390 if (!(this.value && this.value.length) &&
8391 isNullOrUndefined(this.text) &&
8392 !isData &&
8393 this.element.tagName === 'SELECT' &&
8394 this.element.options.length > 0) {
8395 let optionsElement = this.element.options;
8396 let valueCol = [];
8397 let textCol = '';
8398 for (let index = 0, optionsLen = optionsElement.length; index < optionsLen; index++) {
8399 let opt = optionsElement[index];
8400 if (!isNullOrUndefined(opt.getAttribute('selected'))) {
8401 (opt.getAttribute('value')) ? valueCol.push(opt.getAttribute('value')) : textCol += (opt.text + this.delimiterChar);
8402 }
8403 }
8404 if (valueCol.length > 0) {
8405 this.setProperties({ value: valueCol }, true);
8406 }
8407 else if (textCol !== '') {
8408 this.setProperties({ text: textCol }, true);
8409 }
8410 if (valueCol.length > 0 || textCol !== '') {
8411 this.refreshInputHight();
8412 this.refreshPlaceHolder();
8413 }
8414 }
8415 if ((this.value && this.value.length) || !isNullOrUndefined(this.text)) {
8416 this.renderPopup();
8417 }
8418 if (!isNullOrUndefined(this.text) && (isNullOrUndefined(this.value) || this.value.length === 0)) {
8419 this.initialTextUpdate();
8420 }
8421 if (this.value && this.value.length) {
8422 if (!(this.dataSource instanceof DataManager)) {
8423 this.initialValueUpdate();
8424 this.initialUpdate();
8425 }
8426 else {
8427 this.setInitialValue = () => {
8428 this.initStatus = false;
8429 this.initialValueUpdate();
8430 this.initialUpdate();
8431 this.setInitialValue = null;
8432 this.initStatus = true;
8433 };
8434 }
8435 this.updateTempValue();
8436 }
8437 else {
8438 this.initialUpdate();
8439 }
8440 this.initStatus = true;
8441 this.checkAutoFocus();
8442 if (!isNullOrUndefined(this.text)) {
8443 this.element.setAttribute('data-initial-value', this.text);
8444 }
8445 }
8446 checkAutoFocus() {
8447 if (this.element.hasAttribute('autofocus')) {
8448 this.inputElement.focus();
8449 }
8450 }
8451 setFloatLabelType() {
8452 removeFloating(this.overAllWrapper, this.componentWrapper, this.searchWrapper, this.inputElement, this.value, this.floatLabelType, this.placeholder);
8453 if (this.floatLabelType !== 'Never') {
8454 createFloatLabel(this.overAllWrapper, this.searchWrapper, this.element, this.inputElement, this.value, this.floatLabelType, this.placeholder);
8455 }
8456 }
8457 addValidInputClass() {
8458 if ((!isNullOrUndefined(this.value) && this.value.length) || this.floatLabelType === 'Always') {
8459 addClass([this.overAllWrapper], 'e-valid-input');
8460 }
8461 else {
8462 removeClass([this.overAllWrapper], 'e-valid-input');
8463 }
8464 }
8465 dropDownIcon() {
8466 if (this.showDropDownIcon) {
8467 this.dropIcon = this.createElement('span', { className: dropdownIcon });
8468 this.componentWrapper.appendChild(this.dropIcon);
8469 addClass([this.componentWrapper], ['e-down-icon']);
8470 }
8471 else {
8472 if (!isNullOrUndefined(this.dropIcon)) {
8473 this.dropIcon.parentElement.removeChild(this.dropIcon);
8474 removeClass([this.componentWrapper], ['e-down-icon']);
8475 }
8476 }
8477 }
8478 initialUpdate() {
8479 if (this.mode !== 'Box') {
8480 this.updateDelimView();
8481 }
8482 this.updateCssClass();
8483 this.updateHTMLAttribute();
8484 this.updateReadonly(this.readonly);
8485 this.refreshInputHight();
8486 this.checkPlaceholderSize();
8487 }
8488 /**
8489 * Removes the component from the DOM and detaches all its related event handlers. Also it removes the attributes and classes.
8490 * @method destroy
8491 * @return {void}
8492 */
8493 destroy() {
8494 if (this.popupObj) {
8495 this.popupObj.hide();
8496 }
8497 this.notify(destroy, {});
8498 this.unwireListEvents();
8499 this.unWireEvent();
8500 this.list = null;
8501 this.popupObj = null;
8502 this.mainList = null;
8503 this.mainData = null;
8504 super.destroy();
8505 let temp = ['readonly', 'aria-disabled', 'aria-placeholder', 'placeholder'];
8506 let length = temp.length;
8507 while (length > 0) {
8508 this.inputElement.removeAttribute(temp[length - 1]);
8509 length--;
8510 }
8511 this.element.removeAttribute('data-initial-value');
8512 this.element.style.display = 'block';
8513 if (this.overAllWrapper.parentElement) {
8514 if (this.overAllWrapper.parentElement.tagName === this.getNgDirective()) {
8515 remove(this.overAllWrapper);
8516 }
8517 else {
8518 this.overAllWrapper.parentElement.insertBefore(this.element, this.overAllWrapper);
8519 remove(this.overAllWrapper);
8520 }
8521 }
8522 }
8523 ;
8524};
8525__decorate$4([
8526 Complex({ text: null, value: null, iconCss: null, groupBy: null }, FieldSettings)
8527], MultiSelect.prototype, "fields", void 0);
8528__decorate$4([
8529 Property(false)
8530], MultiSelect.prototype, "enablePersistence", void 0);
8531__decorate$4([
8532 Property(null)
8533], MultiSelect.prototype, "groupTemplate", void 0);
8534__decorate$4([
8535 Property('No Records Found')
8536], MultiSelect.prototype, "noRecordsTemplate", void 0);
8537__decorate$4([
8538 Property('The Request Failed')
8539], MultiSelect.prototype, "actionFailureTemplate", void 0);
8540__decorate$4([
8541 Property('None')
8542], MultiSelect.prototype, "sortOrder", void 0);
8543__decorate$4([
8544 Property(true)
8545], MultiSelect.prototype, "enabled", void 0);
8546__decorate$4([
8547 Property([])
8548], MultiSelect.prototype, "dataSource", void 0);
8549__decorate$4([
8550 Property(null)
8551], MultiSelect.prototype, "query", void 0);
8552__decorate$4([
8553 Property('StartsWith')
8554], MultiSelect.prototype, "filterType", void 0);
8555__decorate$4([
8556 Property(1000)
8557], MultiSelect.prototype, "zIndex", void 0);
8558__decorate$4([
8559 Property(false)
8560], MultiSelect.prototype, "ignoreAccent", void 0);
8561__decorate$4([
8562 Property()
8563], MultiSelect.prototype, "locale", void 0);
8564__decorate$4([
8565 Property(false)
8566], MultiSelect.prototype, "enableGroupCheckBox", void 0);
8567__decorate$4([
8568 Property(null)
8569], MultiSelect.prototype, "cssClass", void 0);
8570__decorate$4([
8571 Property('100%')
8572], MultiSelect.prototype, "width", void 0);
8573__decorate$4([
8574 Property('300px')
8575], MultiSelect.prototype, "popupHeight", void 0);
8576__decorate$4([
8577 Property('100%')
8578], MultiSelect.prototype, "popupWidth", void 0);
8579__decorate$4([
8580 Property(null)
8581], MultiSelect.prototype, "placeholder", void 0);
8582__decorate$4([
8583 Property(null)
8584], MultiSelect.prototype, "filterBarPlaceholder", void 0);
8585__decorate$4([
8586 Property({})
8587], MultiSelect.prototype, "htmlAttributes", void 0);
8588__decorate$4([
8589 Property(null)
8590], MultiSelect.prototype, "valueTemplate", void 0);
8591__decorate$4([
8592 Property(null)
8593], MultiSelect.prototype, "headerTemplate", void 0);
8594__decorate$4([
8595 Property(null)
8596], MultiSelect.prototype, "footerTemplate", void 0);
8597__decorate$4([
8598 Property(null)
8599], MultiSelect.prototype, "itemTemplate", void 0);
8600__decorate$4([
8601 Property(null)
8602], MultiSelect.prototype, "allowFiltering", void 0);
8603__decorate$4([
8604 Property(true)
8605], MultiSelect.prototype, "changeOnBlur", void 0);
8606__decorate$4([
8607 Property(false)
8608], MultiSelect.prototype, "allowCustomValue", void 0);
8609__decorate$4([
8610 Property(true)
8611], MultiSelect.prototype, "showClearButton", void 0);
8612__decorate$4([
8613 Property(1000)
8614], MultiSelect.prototype, "maximumSelectionLength", void 0);
8615__decorate$4([
8616 Property(false)
8617], MultiSelect.prototype, "readonly", void 0);
8618__decorate$4([
8619 Property(null)
8620], MultiSelect.prototype, "text", void 0);
8621__decorate$4([
8622 Property(null)
8623], MultiSelect.prototype, "value", void 0);
8624__decorate$4([
8625 Property(true)
8626], MultiSelect.prototype, "hideSelectedItem", void 0);
8627__decorate$4([
8628 Property(true)
8629], MultiSelect.prototype, "closePopupOnSelect", void 0);
8630__decorate$4([
8631 Property('Default')
8632], MultiSelect.prototype, "mode", void 0);
8633__decorate$4([
8634 Property(',')
8635], MultiSelect.prototype, "delimiterChar", void 0);
8636__decorate$4([
8637 Property(true)
8638], MultiSelect.prototype, "ignoreCase", void 0);
8639__decorate$4([
8640 Property(false)
8641], MultiSelect.prototype, "showDropDownIcon", void 0);
8642__decorate$4([
8643 Property('Never')
8644], MultiSelect.prototype, "floatLabelType", void 0);
8645__decorate$4([
8646 Property(false)
8647], MultiSelect.prototype, "showSelectAll", void 0);
8648__decorate$4([
8649 Property('Select All')
8650], MultiSelect.prototype, "selectAllText", void 0);
8651__decorate$4([
8652 Property('Unselect All')
8653], MultiSelect.prototype, "unSelectAllText", void 0);
8654__decorate$4([
8655 Property(true)
8656], MultiSelect.prototype, "enableSelectionOrder", void 0);
8657__decorate$4([
8658 Property(true)
8659], MultiSelect.prototype, "openOnClick", void 0);
8660__decorate$4([
8661 Event()
8662], MultiSelect.prototype, "change", void 0);
8663__decorate$4([
8664 Event()
8665], MultiSelect.prototype, "removing", void 0);
8666__decorate$4([
8667 Event()
8668], MultiSelect.prototype, "removed", void 0);
8669__decorate$4([
8670 Event()
8671], MultiSelect.prototype, "selectedAll", void 0);
8672__decorate$4([
8673 Event()
8674], MultiSelect.prototype, "beforeOpen", void 0);
8675__decorate$4([
8676 Event()
8677], MultiSelect.prototype, "open", void 0);
8678__decorate$4([
8679 Event()
8680], MultiSelect.prototype, "close", void 0);
8681__decorate$4([
8682 Event()
8683], MultiSelect.prototype, "blur", void 0);
8684__decorate$4([
8685 Event()
8686], MultiSelect.prototype, "focus", void 0);
8687__decorate$4([
8688 Event()
8689], MultiSelect.prototype, "chipSelection", void 0);
8690__decorate$4([
8691 Event()
8692], MultiSelect.prototype, "filtering", void 0);
8693__decorate$4([
8694 Event()
8695], MultiSelect.prototype, "tagging", void 0);
8696__decorate$4([
8697 Event()
8698], MultiSelect.prototype, "customValueSelection", void 0);
8699MultiSelect = __decorate$4([
8700 NotifyPropertyChanges
8701], MultiSelect);
8702
8703const ICON = 'e-icons';
8704const CHECKBOXFRAME = 'e-frame';
8705const CHECK = 'e-check';
8706const CHECKBOXWRAP = 'e-checkbox-wrapper';
8707const INDETERMINATE = 'e-stop';
8708const checkAllParent = 'e-selectall-parent';
8709const searchBackIcon = 'e-input-group-icon e-back-icon e-icons';
8710const filterBarClearIcon = 'e-input-group-icon e-clear-icon e-icons';
8711const filterInput = 'e-input-filter';
8712const filterParent = 'e-filter-parent';
8713const mobileFilter = 'e-ddl-device-filter';
8714const clearIcon = 'e-clear-icon';
8715const popupFullScreen = 'e-popup-full-page';
8716const device = 'e-ddl-device';
8717const FOCUS$1 = 'e-input-focus';
8718/**
8719 * The Multiselect enable CheckBoxSelection call this inject module.
8720 */
8721class CheckBoxSelection {
8722 constructor(parent) {
8723 this.activeLi = [];
8724 this.activeEle = [];
8725 this.parent = parent;
8726 this.addEventListener();
8727 }
8728 getModuleName() {
8729 return 'CheckBoxSelection';
8730 }
8731 addEventListener() {
8732 if (this.parent.isDestroyed) {
8733 return;
8734 }
8735 this.parent.on('updatelist', this.listSelection, this);
8736 this.parent.on('listoption', this.listOption, this);
8737 this.parent.on('selectAll', this.setSelectAll, this);
8738 this.parent.on('checkSelectAll', this.checkSelectAll, this);
8739 this.parent.on('searchBox', this.setSearchBox, this);
8740 this.parent.on('blur', this.onBlur, this);
8741 this.parent.on('targetElement', this.targetElement, this);
8742 this.parent.on('deviceSearchBox', this.setDeviceSearchBox, this);
8743 this.parent.on('inputFocus', this.getFocus, this);
8744 this.parent.on('reOrder', this.setReorder, this);
8745 this.parent.on('activeList', this.getActiveList, this);
8746 this.parent.on('selectAllText', this.setLocale, this);
8747 this.parent.on('filterBarPlaceholder', this.setPlaceholder, this);
8748 EventHandler.add(document, 'mousedown', this.onDocumentClick, this);
8749 this.parent.on('addItem', this.checboxCreate, this);
8750 }
8751 removeEventListener() {
8752 if (this.parent.isDestroyed) {
8753 return;
8754 }
8755 this.parent.off('updatelist', this.listSelection);
8756 this.parent.off('listoption', this.listOption);
8757 this.parent.off('selectAll', this.setSelectAll);
8758 this.parent.off('checkSelectAll', this.checkSelectAll);
8759 this.parent.off('searchBox', this.setSearchBox);
8760 this.parent.off('blur', this.onBlur);
8761 this.parent.off('targetElement', this.targetElement);
8762 this.parent.off('deviceSearchBox', this.setDeviceSearchBox);
8763 this.parent.off('inputFocus', this.getFocus);
8764 this.parent.off('reOrder', this.setReorder);
8765 this.parent.off('activeList', this.getActiveList);
8766 this.parent.off('selectAllText', this.setLocale);
8767 this.parent.off('filterBarPlaceholder', this.setPlaceholder);
8768 this.parent.off('addItem', this.checboxCreate);
8769 EventHandler.remove(document, 'mousedown', this.onDocumentClick);
8770 }
8771 listOption(args) {
8772 if (isNullOrUndefined(this.parent.listCurrentOptions.itemCreated)) {
8773 this.parent.listCurrentOptions.itemCreated = (e) => {
8774 this.checboxCreate(e);
8775 };
8776 }
8777 else {
8778 let itemCreated = this.parent.listCurrentOptions.itemCreated;
8779 this.parent.listCurrentOptions.itemCreated = (e) => {
8780 this.checboxCreate(e);
8781 itemCreated.apply(this, [e]);
8782 };
8783 }
8784 }
8785 ;
8786 setPlaceholder(props) {
8787 Input.setPlaceholder(props.filterBarPlaceholder, this.filterInput);
8788 }
8789 checboxCreate(e) {
8790 let item;
8791 if (!isNullOrUndefined(e.item)) {
8792 item = e.item;
8793 }
8794 else {
8795 item = e;
8796 }
8797 if (this.parent.enableGroupCheckBox || (item.className !== 'e-list-group-item '
8798 && item.className !== 'e-list-group-item')) {
8799 let checkboxEle = createCheckBox(this.parent.createElement, true);
8800 let icon = select('div.' + ICON, item);
8801 let id = item.getAttribute('data-uid');
8802 item.insertBefore(checkboxEle, item.childNodes[isNullOrUndefined(icon) ? 0 : 1]);
8803 select('.' + CHECKBOXFRAME, checkboxEle);
8804 let frame = select('.' + CHECKBOXFRAME, checkboxEle);
8805 if (this.parent.enableGroupCheckBox) {
8806 this.parent.popupWrapper.classList.add('e-multiselect-group');
8807 }
8808 return item;
8809 }
8810 else {
8811 return item;
8812 }
8813 }
8814 setSelectAll() {
8815 if (this.parent.showSelectAll) {
8816 if (isNullOrUndefined(this.checkAllParent)) {
8817 this.checkAllParent = this.parent.createElement('div', {
8818 className: checkAllParent
8819 });
8820 this.selectAllSpan = this.parent.createElement('span', {
8821 className: 'e-all-text'
8822 });
8823 this.selectAllSpan.textContent = '';
8824 this.checkAllParent.appendChild(this.selectAllSpan);
8825 this.setLocale();
8826 this.checboxCreate(this.checkAllParent);
8827 if (this.parent.headerTemplate) {
8828 if (!isNullOrUndefined(this.parent.filterParent)) {
8829 append([this.checkAllParent], this.parent.filterParent);
8830 }
8831 else {
8832 append([this.checkAllParent], this.parent.popupWrapper);
8833 }
8834 }
8835 if (!this.parent.headerTemplate) {
8836 if (!isNullOrUndefined(this.parent.filterParent)) {
8837 this.parent.filterParent.parentNode.insertBefore(this.checkAllParent, this.parent.filterParent.nextSibling);
8838 }
8839 else {
8840 prepend([this.checkAllParent], this.parent.popupWrapper);
8841 }
8842 }
8843 EventHandler.add(this.checkAllParent, 'mousedown', this.clickHandler, this);
8844 }
8845 if (this.parent.list.classList.contains('e-nodata') || (this.parent.listData && this.parent.listData.length <= 1)) {
8846 this.checkAllParent.style.display = 'none';
8847 }
8848 else {
8849 this.checkAllParent.style.display = 'block';
8850 }
8851 this.parent.selectAllHeight = this.checkAllParent.getBoundingClientRect().height;
8852 }
8853 else if (!isNullOrUndefined(this.checkAllParent)) {
8854 this.checkAllParent.parentElement.removeChild(this.checkAllParent);
8855 this.checkAllParent = null;
8856 }
8857 }
8858 destroy() {
8859 this.removeEventListener();
8860 }
8861 listSelection(args) {
8862 let target;
8863 if (!isNullOrUndefined(args.e)) {
8864 target = !isNullOrUndefined(args.e.target) ?
8865 (args.e.target.classList.contains('e-frame')
8866 && (!this.parent.showSelectAll
8867 || (this.checkAllParent && !this.checkAllParent.contains(args.e.target)))) ?
8868 args.e.target : args.li.querySelector('.e-checkbox-wrapper').childNodes[1]
8869 : args.li.querySelector('.e-checkbox-wrapper').childNodes[1];
8870 }
8871 else {
8872 target = args.li.lastElementChild.childNodes[1];
8873 }
8874 if (this.parent.itemTemplate || this.parent.enableGroupCheckBox) {
8875 target = args.li.firstElementChild.childNodes[1];
8876 }
8877 if (!isNullOrUndefined(target)) {
8878 this.checkWrapper = closest(target, '.' + CHECKBOXWRAP);
8879 }
8880 if (!isNullOrUndefined(this.checkWrapper)) {
8881 let checkElement = select('.' + CHECKBOXFRAME, this.checkWrapper);
8882 let selectAll = false;
8883 this.validateCheckNode(this.checkWrapper, checkElement.classList.contains(CHECK), args.li, args.e, selectAll);
8884 }
8885 }
8886 validateCheckNode(checkWrap, isCheck, li, e, selectAll) {
8887 this.changeState(checkWrap, isCheck ? 'uncheck' : 'check', e, true, selectAll);
8888 }
8889 clickHandler(e) {
8890 let target;
8891 if (e.currentTarget.classList.contains(this.checkAllParent.className)) {
8892 target = e.currentTarget.firstElementChild.lastElementChild;
8893 }
8894 else {
8895 target = e.currentTarget;
8896 }
8897 this.checkWrapper = closest(target, '.' + CHECKBOXWRAP);
8898 let selectAll = true;
8899 if (!isNullOrUndefined(this.checkWrapper)) {
8900 let checkElement = select('.' + CHECKBOXFRAME, this.checkWrapper);
8901 this.validateCheckNode(this.checkWrapper, checkElement.classList.contains(CHECK), null, e, selectAll);
8902 }
8903 e.preventDefault();
8904 }
8905 changeState(wrapper, state, e, isPrevent, selectAll) {
8906 let ariaState;
8907 let frameSpan = wrapper.getElementsByClassName(CHECKBOXFRAME)[0];
8908 if (state === 'check' && !frameSpan.classList.contains(CHECK)) {
8909 frameSpan.classList.remove(INDETERMINATE);
8910 frameSpan.classList.add(CHECK);
8911 ariaState = 'true';
8912 if (selectAll) {
8913 this.parent.selectAllItems(true, e);
8914 this.setLocale(true);
8915 }
8916 }
8917 else if (state === 'uncheck' && (frameSpan.classList.contains(CHECK) || frameSpan.classList.contains(INDETERMINATE))) {
8918 removeClass([frameSpan], [CHECK, INDETERMINATE]);
8919 ariaState = 'false';
8920 if (selectAll) {
8921 this.parent.selectAllItems(false, e);
8922 this.setLocale();
8923 }
8924 }
8925 else if (state === 'indeterminate' && !(frameSpan.classList.contains(INDETERMINATE))) {
8926 removeClass([frameSpan], [CHECK]);
8927 frameSpan.classList.add(INDETERMINATE);
8928 ariaState = 'false';
8929 if (selectAll) {
8930 this.parent.selectAllItems(false, e);
8931 this.setLocale();
8932 }
8933 }
8934 ariaState = state === 'check' ? 'true' : state === 'uncheck' ? 'false' : ariaState;
8935 if (!isNullOrUndefined(ariaState)) {
8936 wrapper.setAttribute('aria-checked', ariaState);
8937 }
8938 }
8939 setSearchBox(args) {
8940 if (isNullOrUndefined(this.parent.filterParent)) {
8941 this.parent.filterParent = this.parent.createElement('span', {
8942 className: filterParent
8943 });
8944 this.filterInput = this.parent.createElement('input', {
8945 attrs: { type: 'text' },
8946 className: filterInput
8947 });
8948 this.parent.element.parentNode.insertBefore(this.filterInput, this.parent.element);
8949 let backIcon = false;
8950 if (Browser.isDevice) {
8951 backIcon = true;
8952 this.parent.mobFilter = false;
8953 }
8954 this.filterInputObj = Input.createInput({
8955 element: this.filterInput,
8956 buttons: backIcon ? [searchBackIcon, filterBarClearIcon] : [filterBarClearIcon],
8957 properties: { placeholder: this.parent.filterBarPlaceholder }
8958 }, this.parent.createElement);
8959 append([this.filterInputObj.container], this.parent.filterParent);
8960 prepend([this.parent.filterParent], args.popupElement);
8961 attributes(this.filterInput, {
8962 'aria-disabled': 'false',
8963 'aria-owns': this.parent.element.id + '_options',
8964 'role': 'listbox',
8965 'aria-activedescendant': null,
8966 'autocomplete': 'off',
8967 'autocorrect': 'off',
8968 'autocapitalize': 'off',
8969 'spellcheck': 'false'
8970 });
8971 this.clearIconElement = this.filterInput.parentElement.querySelector('.' + clearIcon);
8972 if (!Browser.isDevice && this.clearIconElement) {
8973 EventHandler.add(this.clearIconElement, 'mousedown', this.clearText, this);
8974 this.clearIconElement.style.visibility = 'hidden';
8975 }
8976 EventHandler.add(this.filterInput, 'input', this.parent.onInput, this.parent);
8977 EventHandler.add(this.filterInput, 'keyup', this.parent.KeyUp, this.parent);
8978 EventHandler.add(this.filterInput, 'keydown', this.parent.onKeyDown, this.parent);
8979 EventHandler.add(this.filterInput, 'blur', this.onBlur, this);
8980 this.parent.searchBoxHeight = (this.filterInputObj.container.parentElement).getBoundingClientRect().height;
8981 return this.filterInputObj;
8982 }
8983 }
8984 ;
8985 clickOnBackIcon(e) {
8986 this.parent.hidePopup();
8987 removeClass([document.body, this.parent.popupObj.element], popupFullScreen);
8988 this.parent.inputElement.focus();
8989 }
8990 clearText(e) {
8991 this.parent.targetInputElement.value = '';
8992 this.parent.refreshPopup();
8993 this.parent.refreshListItems(null);
8994 this.clearIconElement.style.visibility = 'hidden';
8995 this.filterInput.focus();
8996 this.setReorder(e);
8997 e.preventDefault();
8998 }
8999 setDeviceSearchBox() {
9000 this.parent.popupObj.element.classList.add(device);
9001 this.parent.popupObj.element.classList.add(mobileFilter);
9002 this.parent.popupObj.position = { X: 0, Y: 0 };
9003 this.parent.popupObj.dataBind();
9004 attributes(this.parent.popupObj.element, { style: 'left:0px;right:0px;top:0px;bottom:0px;' });
9005 addClass([document.body, this.parent.popupObj.element], popupFullScreen);
9006 this.setSearchBoxPosition();
9007 this.backIconElement = this.filterInputObj.container.querySelector('.e-back-icon');
9008 this.clearIconElement = this.filterInputObj.container.querySelector('.' + clearIcon);
9009 this.clearIconElement.style.visibility = 'hidden';
9010 EventHandler.add(this.backIconElement, 'click', this.clickOnBackIcon, this);
9011 EventHandler.add(this.clearIconElement, 'click', this.clearText, this);
9012 }
9013 setSearchBoxPosition() {
9014 let searchBoxHeight = this.filterInput.parentElement.getBoundingClientRect().height;
9015 this.parent.popupObj.element.style.maxHeight = '100%';
9016 this.parent.popupObj.element.style.width = '100%';
9017 this.parent.list.style.maxHeight = (window.innerHeight - searchBoxHeight) + 'px';
9018 this.parent.list.style.height = (window.innerHeight - searchBoxHeight) + 'px';
9019 let clearElement = this.filterInput.parentElement.querySelector('.' + clearIcon);
9020 detach(this.filterInput);
9021 clearElement.parentElement.insertBefore(this.filterInput, clearElement);
9022 }
9023 targetElement() {
9024 if (!isNullOrUndefined(this.clearIconElement)) {
9025 this.parent.targetInputElement = this.filterInput;
9026 this.clearIconElement.style.visibility = this.parent.targetInputElement.value === '' ? 'hidden' : 'visible';
9027 }
9028 return this.parent.targetInputElement.value;
9029 }
9030 onBlur(e) {
9031 if (!this.parent.element.classList.contains('e-listbox')) {
9032 let target;
9033 if (this.parent.keyAction) {
9034 return;
9035 }
9036 if (Browser.isIE) {
9037 target = !isNullOrUndefined(e) && e.target;
9038 }
9039 if (!Browser.isIE) {
9040 target = !isNullOrUndefined(e) && e.relatedTarget;
9041 }
9042 if (document.body.contains(this.parent.popupObj.element) && this.parent.popupObj.element.contains(target) && !Browser.isIE
9043 && this.filterInput) {
9044 this.filterInput.focus();
9045 return;
9046 }
9047 if (this.parent.scrollFocusStatus && this.filterInput) {
9048 e.preventDefault();
9049 this.filterInput.focus();
9050 this.parent.scrollFocusStatus = false;
9051 return;
9052 }
9053 if (document.body.contains(this.parent.popupObj.element) && !this.parent.popupObj.element.classList.contains('e-popup-close')) {
9054 this.parent.inputFocus = false;
9055 this.parent.updateValueState(e, this.parent.value, this.parent.tempValues);
9056 this.parent.dispatchEvent(this.parent.hiddenElement, 'change');
9057 }
9058 if (document.body.contains(this.parent.popupObj.element) &&
9059 !this.parent.popupObj.element.classList.contains('e-popup-close')) {
9060 this.parent.inputFocus = false;
9061 this.parent.overAllWrapper.classList.remove(FOCUS$1);
9062 this.parent.trigger('blur');
9063 this.parent.focused = true;
9064 }
9065 if (document.body.contains(this.parent.popupObj.element) &&
9066 !this.parent.popupObj.element.classList.contains('e-popup-close') && !Browser.isDevice) {
9067 this.parent.hidePopup();
9068 }
9069 }
9070 }
9071 onDocumentClick(e) {
9072 if (!this.parent.element.classList.contains('e-listbox') && this.parent.element.tagName !== 'EJS-LISTBOX') {
9073 let target = e.target;
9074 if (!isNullOrUndefined(this.parent.popupObj) && closest(target, '#' + this.parent.popupObj.element.id)) {
9075 e.preventDefault();
9076 }
9077 if (!(!isNullOrUndefined(this.parent.popupObj) && closest(target, '#' + this.parent.popupObj.element.id)) &&
9078 !this.parent.overAllWrapper.contains(e.target)) {
9079 if (this.parent.overAllWrapper.classList.contains(dropDownBaseClasses.focus) || this.parent.isPopupOpen()) {
9080 this.parent.inputFocus = false;
9081 this.parent.scrollFocusStatus = false;
9082 this.parent.hidePopup();
9083 this.parent.onBlur();
9084 this.parent.focused = true;
9085 }
9086 }
9087 else {
9088 this.parent.scrollFocusStatus = (Browser.isIE || Browser.info.name === 'edge') && (document.activeElement === this.filterInput);
9089 }
9090 if (!this.parent.overAllWrapper.contains(e.target) && this.parent.overAllWrapper.classList.contains('e-input-focus') &&
9091 !this.parent.isPopupOpen()) {
9092 if (Browser.isIE) {
9093 this.parent.onBlur();
9094 }
9095 else {
9096 this.parent.onBlur(e);
9097 }
9098 }
9099 if (this.filterInput === target) {
9100 this.filterInput.focus();
9101 }
9102 }
9103 }
9104 getFocus(e) {
9105 this.parent.overAllWrapper.classList.remove(FOCUS$1);
9106 if (this.parent.keyAction && e.value !== 'clear') {
9107 this.parent.keyAction = false;
9108 return;
9109 }
9110 if (e.value === 'focus') {
9111 this.filterInput.focus();
9112 this.parent.removeFocus();
9113 EventHandler.remove(this.parent.list, 'keydown', this.parent.onKeyDown);
9114 }
9115 if (e.value === 'clear') {
9116 this.filterInput.value = '';
9117 this.clearIconElement.style.visibility = 'hidden';
9118 }
9119 }
9120 checkSelectAll(e) {
9121 if (e.value === 'check' && this.checkAllParent.getAttribute('aria-checked') !== 'true') {
9122 this.changeState(this.checkAllParent, e.value, null, null, false);
9123 this.setLocale(true);
9124 }
9125 if (e.value === 'uncheck') {
9126 this.changeState(this.checkAllParent, e.value, null, null, false);
9127 this.setLocale();
9128 }
9129 if (e.value === 'indeterminate') {
9130 this.changeState(this.checkAllParent, e.value, null, null, false);
9131 this.setLocale();
9132 }
9133 }
9134 setLocale(unSelect) {
9135 if (this.parent.selectAllText !== 'Select All' || this.parent.unSelectAllText !== 'Unselect All') {
9136 let template = unSelect ? this.parent.unSelectAllText : this.parent.selectAllText;
9137 let compiledString;
9138 this.selectAllSpan.textContent = '';
9139 compiledString = compile(template);
9140 for (let item of compiledString({})) {
9141 this.selectAllSpan.textContent = item.textContent;
9142 }
9143 }
9144 else {
9145 let l10nLocale = { selectAllText: 'Select All', unSelectAllText: 'Unselect All' };
9146 let l10n = new L10n(this.parent.getLocaleName(), {}, this.parent.locale);
9147 if (l10n.getConstant('selectAllText') === '') {
9148 l10n = new L10n('dropdowns', l10nLocale, this.parent.locale);
9149 }
9150 this.selectAllSpan.textContent = unSelect ? l10n.getConstant('unSelectAllText') : l10n.getConstant('selectAllText');
9151 }
9152 }
9153 getActiveList(args) {
9154 if (args.li.classList.contains('e-active')) {
9155 this.activeLi.push(args.li.cloneNode(true));
9156 }
9157 else {
9158 this.activeLi.splice(args.index, 1);
9159 }
9160 }
9161 setReorder(args) {
9162 if (this.parent.enableSelectionOrder && !isNullOrUndefined(this.parent.value)) {
9163 let activeLiCount = this.parent.ulElement.querySelectorAll('li.e-active').length;
9164 let remLi;
9165 let ulEle = this.parent.createElement('ul', {
9166 className: 'e-list-parent e-ul e-reorder'
9167 });
9168 let removeEle = this.parent.createElement('div');
9169 if (activeLiCount > 0) {
9170 append(this.parent.ulElement.querySelectorAll('li.e-active'), ulEle);
9171 remLi = this.parent.ulElement.querySelectorAll('li.e-active');
9172 addClass(remLi, 'e-reorder-hide');
9173 prepend([ulEle], this.parent.list);
9174 }
9175 this.parent.focusAtFirstListItem();
9176 }
9177 }
9178}
9179
9180/**
9181 * export all modules from current location
9182 */
9183
9184var __decorate$5 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
9185 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9186 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9187 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
9188 return c > 3 && r && Object.defineProperty(target, key, r), r;
9189};
9190var ListBox_1;
9191/// <reference path='../drop-down-base/drop-down-base-model.d.ts'/>
9192const ITEMTEMPLATE_PROPERTY$1 = 'ItemTemplate';
9193class SelectionSettings extends ChildProperty {
9194}
9195__decorate$5([
9196 Property('Multiple')
9197], SelectionSettings.prototype, "mode", void 0);
9198__decorate$5([
9199 Property(false)
9200], SelectionSettings.prototype, "showCheckbox", void 0);
9201__decorate$5([
9202 Property(false)
9203], SelectionSettings.prototype, "showSelectAll", void 0);
9204__decorate$5([
9205 Property('Left')
9206], SelectionSettings.prototype, "checkboxPosition", void 0);
9207class ToolbarSettings extends ChildProperty {
9208}
9209__decorate$5([
9210 Property([])
9211], ToolbarSettings.prototype, "items", void 0);
9212__decorate$5([
9213 Property('Right')
9214], ToolbarSettings.prototype, "position", void 0);
9215/**
9216 * The ListBox is a graphical user interface component used to display a list of items.
9217 * Users can select one or more items in the list using a checkbox or by keyboard selection.
9218 * It supports sorting, grouping, reordering, and drag and drop of items.
9219 * ```html
9220 * <select id="listbox">
9221 * <option value='1'>Badminton</option>
9222 * <option value='2'>Basketball</option>
9223 * <option value='3'>Cricket</option>
9224 * <option value='4'>Football</option>
9225 * <option value='5'>Tennis</option>
9226 * </select>
9227 * ```
9228 * ```typescript
9229 * <script>
9230 * var listObj = new ListBox();
9231 * listObj.appendTo("#listbox");
9232 * </script>
9233 * ```
9234 */
9235let ListBox = ListBox_1 = class ListBox extends DropDownBase {
9236 /**
9237 * Constructor for creating the ListBox component.
9238 */
9239 constructor(options, element) {
9240 super(options, element);
9241 this.isValidKey = false;
9242 this.keyDownStatus = false;
9243 }
9244 /**
9245 * Adds a new item to the popup list. By default, new item appends to the list as the last item,
9246 * but you can insert based on the index parameter.
9247 * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
9248 * @param { number } itemIndex - Specifies the index to place the newly added item in the popup list.
9249 * @return {void}.
9250 * @private
9251 */
9252 addItem(items, itemIndex) {
9253 super.addItem(items, itemIndex);
9254 }
9255 ;
9256 /**
9257 * Build and render the component
9258 * @private
9259 */
9260 render() {
9261 this.inputString = '';
9262 this.initLoad = true;
9263 this.isCustomFiltering = false;
9264 this.initialSelectedOptions = this.value;
9265 super.render();
9266 this.renderComplete();
9267 }
9268 initWrapper() {
9269 let hiddenSelect = this.createElement('select', { className: 'e-hidden-select', attrs: { 'multiple': '' } });
9270 this.list.classList.add('e-listbox-wrapper');
9271 if (this.itemTemplate) {
9272 this.list.classList.add('e-list-template');
9273 }
9274 this.list.classList.add('e-wrapper');
9275 if (this.element.tagName === 'EJS-LISTBOX') {
9276 this.element.setAttribute('tabindex', '0');
9277 if (this.initLoad) {
9278 this.element.appendChild(this.list);
9279 }
9280 }
9281 else {
9282 if (this.initLoad) {
9283 this.element.parentElement.insertBefore(this.list, this.element);
9284 }
9285 this.list.insertBefore(this.element, this.list.firstChild);
9286 this.element.style.display = 'none';
9287 }
9288 this.list.insertBefore(hiddenSelect, this.list.firstChild);
9289 if (this.list.getElementsByClassName(cssClass.li)[0]) {
9290 this.list.getElementsByClassName(cssClass.li)[0].classList.remove(dropDownBaseClasses.focus);
9291 }
9292 removeClass([this.list], [dropDownBaseClasses.content, dropDownBaseClasses.root]);
9293 this.validationAttribute(this.element, hiddenSelect);
9294 this.list.setAttribute('role', 'listbox');
9295 attributes(this.list, { 'role': 'listbox', 'aria-multiselectable': this.selectionSettings.mode === 'Multiple' ? 'true' : 'false' });
9296 if (this.selectionSettings.showCheckbox && this.selectionSettings.showSelectAll && this.liCollections.length) {
9297 let l10nSelect = new L10n(this.getModuleName(), { selectAllText: 'Select All', unSelectAllText: 'Unselect All' }, this.locale);
9298 this.showSelectAll = true;
9299 this.selectAllText = l10nSelect.getConstant('selectAllText');
9300 this.unSelectAllText = l10nSelect.getConstant('unSelectAllText');
9301 this.popupWrapper = this.list;
9302 this.checkBoxSelectionModule.checkAllParent = null;
9303 this.notify('selectAll', {});
9304 }
9305 }
9306 initDraggable() {
9307 if (this.allowDragAndDrop) {
9308 new Sortable(this.ulElement, {
9309 scope: this.scope,
9310 itemClass: cssClass.li,
9311 dragStart: this.triggerDragStart.bind(this),
9312 drag: this.triggerDrag.bind(this),
9313 beforeDrop: this.beforeDragEnd.bind(this),
9314 drop: this.dragEnd.bind(this),
9315 placeHolder: () => { return this.createElement('span', { className: 'e-placeholder' }); },
9316 helper: (e) => {
9317 let ele = e.sender.cloneNode(true);
9318 ele.style.width = this.getItems()[0].offsetWidth + 'px';
9319 if ((this.value && this.value.length) > 1 && this.isSelected(ele)) {
9320 ele.appendChild(this.createElement('span', {
9321 className: 'e-list-badge', innerHTML: this.value.length + ''
9322 }));
9323 }
9324 return ele;
9325 }
9326 });
9327 }
9328 }
9329 updateActionCompleteData(li, item) {
9330 this.jsonData.push(item);
9331 }
9332 initToolbar() {
9333 let scope;
9334 let pos = this.toolbarSettings.position;
9335 let prevScope = this.element.getAttribute('data-value');
9336 if (this.toolbarSettings.items.length) {
9337 let toolElem = this.createElement('div', { className: 'e-listbox-tool', attrs: { 'role': 'toolbar' } });
9338 let wrapper = this.createElement('div', {
9339 className: 'e-listboxtool-wrapper e-' + pos.toLowerCase()
9340 });
9341 this.list.parentElement.insertBefore(wrapper, this.list);
9342 wrapper.appendChild(pos === 'Right' ? this.list : toolElem);
9343 wrapper.appendChild(pos === 'Right' ? toolElem : this.list);
9344 this.createButtons(toolElem);
9345 if (!this.element.id) {
9346 this.element.id = getUniqueID('e-' + this.getModuleName());
9347 }
9348 if (this.scope) {
9349 document.querySelector(this.scope).setAttribute('data-value', this.element.id);
9350 }
9351 else {
9352 this.updateToolBarState();
9353 }
9354 }
9355 scope = this.element.getAttribute('data-value');
9356 if (prevScope && scope && (prevScope !== scope)) {
9357 this.tBListBox = getComponent(document.getElementById(prevScope), this.getModuleName());
9358 this.tBListBox.updateToolBarState();
9359 }
9360 else if (scope) {
9361 this.tBListBox = getComponent(document.getElementById(scope), this.getModuleName());
9362 this.tBListBox.updateToolBarState();
9363 }
9364 }
9365 createButtons(toolElem) {
9366 let btn;
9367 let ele;
9368 let title;
9369 let l10n = new L10n(this.getModuleName(), {
9370 moveUp: 'Move Up', moveDown: 'Move Down', moveTo: 'Move To',
9371 moveFrom: 'Move From', moveAllTo: 'Move All To', moveAllFrom: 'Move All From'
9372 }, this.locale);
9373 this.toolbarSettings.items.forEach((value) => {
9374 title = l10n.getConstant(value);
9375 ele = this.createElement('button', {
9376 attrs: {
9377 'type': 'button',
9378 'data-value': value,
9379 'title': title,
9380 'aria-label': title
9381 }
9382 });
9383 toolElem.appendChild(ele);
9384 btn = new Button({ iconCss: 'e-icons e-' + value.toLowerCase() }, ele);
9385 btn.createElement = this.createElement;
9386 });
9387 }
9388 validationAttribute(input, hiddenSelect) {
9389 super.validationAttribute(input, hiddenSelect);
9390 hiddenSelect.required = input.required;
9391 input.required = false;
9392 }
9393 setHeight() {
9394 let ele = this.toolbarSettings.items.length ? this.list.parentElement : this.list;
9395 ele.style.height = formatUnit(this.height);
9396 }
9397 setCssClass() {
9398 let wrap = this.toolbarSettings.items.length ? this.list.parentElement : this.list;
9399 if (this.cssClass) {
9400 addClass([wrap], this.cssClass.split(' '));
9401 }
9402 if (this.enableRtl) {
9403 addClass([wrap], 'e-rtl');
9404 }
9405 }
9406 setEnable() {
9407 let ele = this.toolbarSettings.items.length ? this.list.parentElement : this.list;
9408 if (this.enabled) {
9409 removeClass([ele], cssClass.disabled);
9410 }
9411 else {
9412 addClass([ele], cssClass.disabled);
9413 }
9414 }
9415 showSpinner() {
9416 if (!this.spinner) {
9417 this.spinner = this.createElement('div', { className: 'e-listbox-wrapper', styles: 'height:' + formatUnit(this.height) });
9418 }
9419 this.element.parentElement.insertBefore(this.spinner, this.element.nextSibling);
9420 createSpinner({ target: this.spinner }, this.createElement);
9421 showSpinner(this.spinner);
9422 }
9423 hideSpinner() {
9424 if (this.spinner.querySelector('.e-spinner-pane')) {
9425 hideSpinner(this.spinner);
9426 }
9427 if (this.spinner.parentElement) {
9428 detach(this.spinner);
9429 }
9430 }
9431 onInput() {
9432 if (this.keyDownStatus) {
9433 this.isValidKey = true;
9434 }
9435 else {
9436 this.isValidKey = false;
9437 }
9438 this.keyDownStatus = false;
9439 }
9440 onActionComplete(ulElement, list, e) {
9441 let searchEle;
9442 if (this.allowFiltering) {
9443 searchEle = this.list.getElementsByClassName('e-filter-parent')[0];
9444 }
9445 super.onActionComplete(ulElement, list, e);
9446 if (this.allowFiltering && !isNullOrUndefined(searchEle)) {
9447 this.list.insertBefore(searchEle, this.list.firstElementChild);
9448 }
9449 this.initWrapper();
9450 this.setSelection();
9451 this.initDraggable();
9452 this.mainList = this.ulElement;
9453 if (this.initLoad) {
9454 this.jsonData = [];
9455 extend(this.jsonData, list, []);
9456 this.initToolbarAndStyles();
9457 this.wireEvents();
9458 if (this.showCheckbox) {
9459 this.setCheckboxPosition();
9460 }
9461 if (this.allowFiltering) {
9462 this.setFiltering();
9463 }
9464 }
9465 else {
9466 if (this.allowFiltering) {
9467 this.list.getElementsByClassName('e-input-filter')[0].focus();
9468 }
9469 }
9470 this.initLoad = false;
9471 }
9472 initToolbarAndStyles() {
9473 this.initToolbar();
9474 this.setCssClass();
9475 this.setEnable();
9476 this.setHeight();
9477 }
9478 triggerDragStart(args) {
9479 let badge;
9480 args = extend(this.getDragArgs(args), { dragSelected: true });
9481 if (Browser.isIos) {
9482 this.list.style.overflow = 'hidden';
9483 }
9484 this.trigger('dragStart', args, (dragEventArgs) => {
9485 this.allowDragAll = dragEventArgs.dragSelected;
9486 if (!this.allowDragAll) {
9487 badge = this.ulElement.getElementsByClassName('e-list-badge')[0];
9488 if (badge) {
9489 detach(badge);
9490 }
9491 }
9492 if (isBlazor()) {
9493 args.bindEvents(args.dragElement);
9494 }
9495 });
9496 }
9497 triggerDrag(args) {
9498 this.trigger('drag', this.getDragArgs(args));
9499 let listObj = this.getComponent(args.target);
9500 if (listObj && listObj.listData.length === 0) {
9501 listObj.ulElement.innerHTML = '';
9502 }
9503 }
9504 beforeDragEnd(args) {
9505 let dragValue = args.droppedElement.getAttribute('data-value');
9506 if (this.value.indexOf(dragValue) > -1) {
9507 args.items = this.getDataByValues(this.value);
9508 }
9509 else {
9510 args.items = this.getDataByValues([dragValue]);
9511 }
9512 this.trigger('beforeDrop', args);
9513 }
9514 // tslint:disable-next-line:max-func-body-length
9515 dragEnd(args) {
9516 let listData;
9517 let liColl;
9518 let jsonData;
9519 let droppedData;
9520 let selectedOptions;
9521 let sortedData;
9522 let dropValue = this.getFormattedValue(args.droppedElement.getAttribute('data-value'));
9523 let listObj = this.getComponent(args.droppedElement);
9524 let getArgs = this.getDragArgs({ target: args.droppedElement }, true);
9525 let sourceArgs = { previousData: this.dataSource };
9526 let destArgs = { previousData: listObj.dataSource };
9527 let dragArgs = extend({}, getArgs, { target: args.target, source: { previousData: this.dataSource } });
9528 if (listObj !== this) {
9529 let sourceArgs1 = extend(sourceArgs, { currentData: this.listData });
9530 dragArgs = extend(dragArgs, { source: sourceArgs1, destination: destArgs });
9531 }
9532 if (Browser.isIos) {
9533 this.list.style.overflow = '';
9534 }
9535 if (listObj === this) {
9536 let ul = this.ulElement;
9537 listData = [].slice.call(this.listData);
9538 liColl = [].slice.call(this.liCollections);
9539 jsonData = [].slice.call(this.jsonData);
9540 sortedData = [].slice.call(this.sortedData);
9541 let toIdx = args.currentIndex = this.getCurIdx(this, args.currentIndex);
9542 let rIdx = listData.indexOf(this.getDataByValue(dropValue));
9543 let jsonIdx = jsonData.indexOf(this.getDataByValue(dropValue));
9544 let sIdx = sortedData.indexOf(this.getDataByValue(dropValue));
9545 listData.splice(toIdx, 0, listData.splice(rIdx, 1)[0]);
9546 jsonData.splice(toIdx, 0, jsonData.splice(jsonIdx, 1)[0]);
9547 sortedData.splice(toIdx, 0, sortedData.splice(sIdx, 1)[0]);
9548 liColl.splice(toIdx, 0, liColl.splice(rIdx, 1)[0]);
9549 if (this.allowDragAll) {
9550 selectedOptions = this.value && Array.prototype.indexOf.call(this.value, dropValue) > -1 ? this.value : [dropValue];
9551 selectedOptions.forEach((value) => {
9552 if (value !== dropValue) {
9553 let idx = listData.indexOf(this.getDataByValue(value));
9554 let jsonIdx = jsonData.indexOf(this.getDataByValue(value));
9555 let sIdx = sortedData.indexOf(this.getDataByValue(value));
9556 if (idx > toIdx) {
9557 toIdx++;
9558 }
9559 listData.splice(toIdx, 0, listData.splice(idx, 1)[0]);
9560 jsonData.splice(toIdx, 0, jsonData.splice(jsonIdx, 1)[0]);
9561 sortedData.splice(toIdx, 0, sortedData.splice(sIdx, 1)[0]);
9562 liColl.splice(toIdx, 0, liColl.splice(idx, 1)[0]);
9563 ul.insertBefore(this.getItems()[this.getIndexByValue(value)], ul.getElementsByClassName('e-placeholder')[0]);
9564 }
9565 });
9566 }
9567 this.listData = listData;
9568 this.jsonData = jsonData;
9569 this.sortedData = sortedData;
9570 this.liCollections = liColl;
9571 }
9572 else {
9573 let li;
9574 let fLiColl = [].slice.call(this.liCollections);
9575 let currIdx = args.currentIndex = this.getCurIdx(listObj, args.currentIndex);
9576 let ul = listObj.ulElement;
9577 listData = [].slice.call(listObj.listData);
9578 liColl = [].slice.call(listObj.liCollections);
9579 jsonData = [].slice.call(listObj.jsonData);
9580 sortedData = [].slice.call(listObj.sortedData);
9581 selectedOptions = (this.value && Array.prototype.indexOf.call(this.value, dropValue) > -1 && this.allowDragAll)
9582 ? this.value : [dropValue];
9583 selectedOptions.forEach((value) => {
9584 droppedData = this.getDataByValue(value);
9585 let srcIdx = this.listData.indexOf(droppedData);
9586 let jsonSrcIdx = this.jsonData.indexOf(droppedData);
9587 this.listData.splice(srcIdx, 1);
9588 this.jsonData.splice(jsonSrcIdx, 1);
9589 let rLi = fLiColl.splice(srcIdx, 1)[0];
9590 let destIdx = value === dropValue ? args.currentIndex : currIdx;
9591 listData.splice(destIdx, 0, droppedData);
9592 jsonData.splice(destIdx, 0, droppedData);
9593 liColl.splice(destIdx, 0, rLi);
9594 sortedData.splice(destIdx, 0, droppedData);
9595 if (!value) {
9596 let liCollElem = this.getItems();
9597 for (let i = 0; i < liCollElem.length; i++) {
9598 if (liCollElem[i].getAttribute('data-value') === null && liCollElem[i].classList.contains('e-list-item')) {
9599 li = liCollElem[i];
9600 break;
9601 }
9602 }
9603 }
9604 else {
9605 li = this.getItems()[this.getIndexByValue(value)];
9606 }
9607 this.removeSelected(this, value === dropValue ? [args.droppedElement] : [li]);
9608 ul.insertBefore(li, ul.getElementsByClassName('e-placeholder')[0]);
9609 currIdx++;
9610 });
9611 this.updateSelectedOptions();
9612 if (this.fields.groupBy) {
9613 this.ulElement.innerHTML = this.renderItems(this.listData, this.fields).innerHTML;
9614 this.setSelection();
9615 }
9616 if (listObj.sortOrder !== 'None' || this.selectionSettings.showCheckbox
9617 !== listObj.selectionSettings.showCheckbox || listObj.fields.groupBy) {
9618 let sortabale = getComponent(ul, 'sortable');
9619 ul.innerHTML = listObj.renderItems(listData, listObj.fields).innerHTML;
9620 if (sortabale.placeHolderElement) {
9621 ul.appendChild(sortabale.placeHolderElement);
9622 }
9623 ul.appendChild(args.helper);
9624 listObj.setSelection();
9625 }
9626 this.liCollections = fLiColl;
9627 listObj.liCollections = liColl;
9628 listObj.jsonData = extend([], [], jsonData, false);
9629 listObj.listData = extend([], [], listData, false);
9630 listObj.sortedData = extend([], [], sortedData, false);
9631 if (this.listData.length === 0) {
9632 this.l10nUpdate();
9633 }
9634 }
9635 if (this === listObj) {
9636 let sourceArgs1 = extend(sourceArgs, { currentData: listData });
9637 dragArgs = extend(dragArgs, { source: sourceArgs1 });
9638 }
9639 else {
9640 let dragArgs1 = extend(destArgs, { currentData: listData });
9641 dragArgs = extend(dragArgs, { destination: dragArgs1 });
9642 }
9643 this.trigger('drop', dragArgs);
9644 }
9645 removeSelected(listObj, elems) {
9646 if (listObj.selectionSettings.showCheckbox) {
9647 elems.forEach((ele) => { ele.getElementsByClassName('e-frame')[0].classList.remove('e-check'); });
9648 }
9649 else {
9650 removeClass(elems, cssClass.selected);
9651 }
9652 }
9653 getCurIdx(listObj, idx) {
9654 if (listObj.fields.groupBy) {
9655 idx -= [].slice.call(listObj.ulElement.children).slice(0, idx)
9656 .filter((ele) => ele.classList.contains(cssClass.group)).length;
9657 }
9658 return idx;
9659 }
9660 getComponent(li) {
9661 let listObj;
9662 let ele = (this.element.tagName === 'EJS-LISTBOX' ? closest(li, '.e-listbox')
9663 : closest(li, '.e-listbox-wrapper') && closest(li, '.e-listbox-wrapper').querySelector('.e-listbox'));
9664 if (ele) {
9665 listObj = getComponent(ele, this.getModuleName());
9666 }
9667 return listObj;
9668 }
9669 listOption(dataSource, fields) {
9670 this.listCurrentOptions = super.listOption(dataSource, fields);
9671 this.listCurrentOptions = extend({}, this.listCurrentOptions, { itemCreated: this.triggerBeforeItemRender.bind(this) }, true);
9672 this.notify('listoption', { module: 'CheckBoxSelection' });
9673 return this.listCurrentOptions;
9674 }
9675 triggerBeforeItemRender(e) {
9676 e.item.setAttribute('tabindex', '-1');
9677 this.trigger('beforeItemRender', { element: e.item, item: e.curData });
9678 }
9679 requiredModules() {
9680 let modules = [];
9681 if (this.selectionSettings.showCheckbox) {
9682 modules.push({
9683 member: 'CheckBoxSelection',
9684 args: [this]
9685 });
9686 }
9687 return modules;
9688 }
9689 /**
9690 * This method is used to enable or disable the items in the ListBox based on the items and enable argument.
9691 * @param items Text items that needs to be enabled/disabled.
9692 * @param enable Set `true`/`false` to enable/disable the list items.
9693 * @returns void
9694 */
9695 enableItems(items, enable = true) {
9696 let li;
9697 items.forEach((item) => {
9698 li = this.findListElement(this.list, 'li', 'data-value', this.getValueByText(item));
9699 if (enable) {
9700 removeClass([li], cssClass.disabled);
9701 li.removeAttribute('aria-disabled');
9702 }
9703 else {
9704 addClass([li], cssClass.disabled);
9705 li.setAttribute('aria-disabled', 'true');
9706 }
9707 });
9708 }
9709 /**
9710 * Based on the state parameter, specified list item will be selected/deselected.
9711 * @param items Array of text value of the item.
9712 * @param state Set `true`/`false` to select/un select the list items.
9713 * @returns void
9714 */
9715 selectItems(items, state = true) {
9716 this.setSelection(items, state, true);
9717 this.updateSelectedOptions();
9718 }
9719 /**
9720 * Based on the state parameter, entire list item will be selected/deselected.
9721 * @param state Set `true`/`false` to select/un select the entire list items.
9722 * @returns void
9723 */
9724 selectAll(state = true) {
9725 this.selectAllItems(state);
9726 }
9727 /**
9728 * Adds a new item to the list. By default, new item appends to the list as the last item,
9729 * but you can insert based on the index parameter.
9730 * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
9731 * @param { number } itemIndex - Specifies the index to place the newly added item in the list.
9732 * @returns {void}.
9733 */
9734 addItems(items, itemIndex) {
9735 super.addItem(items, itemIndex);
9736 }
9737 /**
9738 * Removes a item from the list. By default, removed the last item in the list,
9739 * but you can remove based on the index parameter.
9740 * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
9741 * @param { number } itemIndex - Specifies the index to remove the item from the list.
9742 * @returns {void}.
9743 */
9744 removeItems(items, itemIndex) {
9745 this.removeItem(items, itemIndex);
9746 }
9747 /**
9748 * Removes a item from the list. By default, removed the last item in the list,
9749 * but you can remove based on the index parameter.
9750 * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
9751 * @param { number } itemIndex - Specifies the index to remove the item from the list.
9752 * @returns {void}.
9753 */
9754 removeItem(items, itemIndex) {
9755 let liCollections = [];
9756 let liElement = this.list.querySelectorAll('.' + dropDownBaseClasses.li);
9757 if (items) {
9758 items = (items instanceof Array ? items : [items]);
9759 let fields = this.fields;
9760 let dataValue;
9761 let objValue;
9762 let dupData = [];
9763 let itemIdx;
9764 extend(dupData, [], this.listData);
9765 for (let j = 0; j < items.length; j++) {
9766 if (items[j] instanceof Object) {
9767 dataValue = getValue(fields.value, items[j]);
9768 }
9769 else {
9770 dataValue = items[j].toString();
9771 }
9772 for (let i = 0, len = dupData.length; i < len; i++) {
9773 if (dupData[i] instanceof Object) {
9774 objValue = getValue(fields.value, dupData[i]);
9775 }
9776 else {
9777 objValue = dupData[i].toString();
9778 }
9779 if (objValue === dataValue) {
9780 itemIdx = this.getIndexByValue(dataValue);
9781 liCollections.push(liElement[itemIdx]);
9782 this.listData.splice(i, 1);
9783 this.updateLiCollection(itemIdx);
9784 }
9785 }
9786 }
9787 }
9788 else {
9789 itemIndex = itemIndex ? itemIndex : 0;
9790 liCollections.push(liElement[itemIndex]);
9791 this.listData.splice(itemIndex, 1);
9792 this.updateLiCollection(itemIndex);
9793 }
9794 for (let i = 0; i < liCollections.length; i++) {
9795 this.ulElement.removeChild(liCollections[i]);
9796 }
9797 }
9798 /**
9799 * Gets the array of data Object that matches the given array of values.
9800 * @param { string[] | number[] | boolean[] } value - Specifies the array value of the list item.
9801 * @returns object[].
9802 */
9803 getDataByValues(value) {
9804 let data = [];
9805 for (let i = 0; i < value.length; i++) {
9806 data.push(this.getDataByValue(value[i]));
9807 }
9808 return data;
9809 }
9810 /**
9811 * Moves the given value(s) / selected value(s) upwards.
9812 * @param { string[] | number[] | boolean[] } value - Specifies the value(s).
9813 * @returns {void}
9814 */
9815 moveUp(value) {
9816 let elem = (value) ? this.getElemByValue(value) : this.getSelectedItems();
9817 this.moveUpDown(true, false, elem);
9818 }
9819 /**
9820 * Moves the given value(s) / selected value(s) downwards.
9821 * @param { string[] | number[] | boolean[] } value - Specifies the value(s).
9822 * @returns {void}
9823 */
9824 moveDown(value) {
9825 let elem = (value) ? this.getElemByValue(value) : this.getSelectedItems();
9826 this.moveUpDown(false, false, elem);
9827 }
9828 /**
9829 * Moves the given value(s) / selected value(s) to the given / default scoped ListBox.
9830 * @param { string[] | number[] | boolean[] } value - Specifies the value or array value of the list item.
9831 * @returns {void}
9832 */
9833 moveTo(value, index, targetId) {
9834 let elem = (value) ? this.getElemByValue(value) : this.getSelectedItems();
9835 let tlistbox = (targetId) ? getComponent(targetId, ListBox_1) : this.getScopedListBox();
9836 this.moveData(this, tlistbox, false, elem, index);
9837 }
9838 /**
9839 * Moves all the values from one ListBox to the scoped ListBox.
9840 * @param { string } targetId - Specifies the scoped ListBox ID.
9841 * @param { string } index - Specifies the index to where the items moved.
9842 * @returns {void}
9843 */
9844 moveAllTo(targetId, index) {
9845 let tlistbox = (targetId) ? getComponent(targetId, ListBox_1) : this.getScopedListBox();
9846 this.moveAllData(this, tlistbox, false, index);
9847 }
9848 /**
9849 * Returns the updated dataSource in ListBox
9850 * @returns {{ [key: string]: Object }[] | string[] | boolean[] | number[]}
9851 */
9852 getDataList() {
9853 return this.jsonData;
9854 }
9855 getElemByValue(value) {
9856 let elem = [];
9857 for (let i = 0; i < value.length; i++) {
9858 elem.push(this.ulElement.querySelector('[data-value ="' + value[i] + '"]'));
9859 }
9860 return elem;
9861 }
9862 updateLiCollection(index) {
9863 let tempLi = [].slice.call(this.liCollections);
9864 tempLi.splice(index, 1);
9865 this.liCollections = tempLi;
9866 }
9867 selectAllItems(state, event) {
9868 [].slice.call(this.getItems()).forEach((li) => {
9869 if (!li.classList.contains(cssClass.disabled)) {
9870 if (this.selectionSettings.showCheckbox) {
9871 let ele = li.getElementsByClassName('e-check')[0];
9872 if ((!ele && state) || (ele && !state)) {
9873 this.notify('updatelist', { li: li });
9874 if (this.maximumSelectionLength >= this.list.querySelectorAll('.e-list-item span.e-check').length) {
9875 this.checkMaxSelection();
9876 }
9877 }
9878 }
9879 else {
9880 if (state) {
9881 li.classList.add(cssClass.selected);
9882 }
9883 else {
9884 li.classList.remove(cssClass.selected);
9885 }
9886 }
9887 }
9888 });
9889 this.updateSelectedOptions();
9890 if (this.allowFiltering && this.selectionSettings.showCheckbox) {
9891 let liEle = this.list.getElementsByTagName('li');
9892 let index = 0;
9893 if (state) {
9894 for (index = 0; index < liEle.length; index++) {
9895 let dataValue1 = this.getFormattedValue(liEle[index].getAttribute('data-value'));
9896 if (!this.value.some((e) => e === dataValue1)) {
9897 this.value.push(this.getFormattedValue(liEle[index].getAttribute('data-value')));
9898 }
9899 }
9900 }
9901 else {
9902 for (index = 0; index < liEle.length; index++) {
9903 let dataValue2 = this.getFormattedValue(liEle[index].getAttribute('data-value'));
9904 this.value = this.value.filter((e) => e !== dataValue2);
9905 }
9906 }
9907 if (document.querySelectorAll('ul').length < 2) {
9908 this.updateMainList();
9909 }
9910 }
9911 this.triggerChange(this.getSelectedItems(), event);
9912 }
9913 updateMainList() {
9914 let mainCount = this.mainList.querySelectorAll('.e-list-item').length;
9915 let ulEleCount = this.ulElement.querySelectorAll('.e-list-item').length;
9916 if (this.selectionSettings.showCheckbox || (document.querySelectorAll('ul').length > 1 || mainCount !== ulEleCount)) {
9917 let listindex = 0;
9918 let valueindex = 0;
9919 let count = 0;
9920 for (listindex; listindex < this.mainList.querySelectorAll('.e-list-item').length;) {
9921 if (this.value) {
9922 for (valueindex; valueindex < this.value.length; valueindex++) {
9923 if (this.mainList.querySelectorAll('.e-list-item')[listindex].getAttribute('data-value') === this.value[valueindex]) {
9924 count++;
9925 }
9926 }
9927 }
9928 if (!count && this.selectionSettings.showCheckbox) {
9929 this.mainList.querySelectorAll('.e-list-item')[listindex].getElementsByClassName('e-frame')[0].classList.remove('e-check');
9930 }
9931 if (document.querySelectorAll('ul').length > 1 && count && mainCount !== ulEleCount) {
9932 this.mainList.removeChild(this.mainList.getElementsByTagName('li')[listindex]);
9933 listindex = 0;
9934 }
9935 else {
9936 listindex++;
9937 }
9938 count = 0;
9939 valueindex = 0;
9940 }
9941 }
9942 }
9943 wireEvents() {
9944 let form = closest(this.element, 'form');
9945 let wrapper = this.element.tagName === 'EJS-LISTBOX' ? this.element : this.list;
9946 EventHandler.add(this.list, 'click', this.clickHandler, this);
9947 EventHandler.add(wrapper, 'keydown', this.keyDownHandler, this);
9948 EventHandler.add(wrapper, 'focusout', this.focusOutHandler, this);
9949 this.wireToolbarEvent();
9950 if (this.selectionSettings.showCheckbox) {
9951 EventHandler.remove(document, 'mousedown', this.checkBoxSelectionModule.onDocumentClick);
9952 }
9953 if (this.fields.groupBy || this.element.querySelector('select>optgroup')) {
9954 EventHandler.remove(this.list, 'scroll', this.setFloatingHeader);
9955 }
9956 if (form) {
9957 EventHandler.add(form, 'reset', this.formResetHandler, this);
9958 }
9959 }
9960 wireToolbarEvent() {
9961 if (this.toolbarSettings.items.length) {
9962 EventHandler.add(this.getToolElem(), 'click', this.toolbarClickHandler, this);
9963 }
9964 }
9965 unwireEvents() {
9966 let form = closest(this.element, 'form');
9967 let wrapper = this.element.tagName === 'EJS-LISTBOX' ? this.element : this.list;
9968 EventHandler.remove(this.list, 'click', this.clickHandler);
9969 EventHandler.remove(wrapper, 'keydown', this.keyDownHandler);
9970 EventHandler.remove(wrapper, 'focusout', this.focusOutHandler);
9971 if (this.toolbarSettings.items.length) {
9972 EventHandler.remove(this.getToolElem(), 'click', this.toolbarClickHandler);
9973 }
9974 if (form) {
9975 EventHandler.remove(form, 'reset', this.formResetHandler);
9976 }
9977 }
9978 clickHandler(e) {
9979 this.selectHandler(e);
9980 }
9981 ;
9982 checkSelectAll() {
9983 let searchCount = 0;
9984 let liItems = this.list.querySelectorAll('li.' + dropDownBaseClasses.li);
9985 for (let i = 0; i < liItems.length; i++) {
9986 if (!liItems[i].classList.contains('e-disabled')) {
9987 searchCount++;
9988 }
9989 }
9990 let len = this.getSelectedItems().length;
9991 if (this.showSelectAll && searchCount) {
9992 this.notify('checkSelectAll', { module: 'CheckBoxSelection',
9993 value: (searchCount === len) ? 'check' : (len === 0) ? 'uncheck' : 'indeterminate' });
9994 }
9995 }
9996 getQuery(query) {
9997 let filterQuery = query ? query.clone() : this.query ? this.query.clone() : new Query();
9998 if (this.allowFiltering) {
9999 let filterType = this.inputString === '' ? 'contains' : this.filterType;
10000 let dataType = this.typeOfData(this.dataSource).typeof;
10001 if (!(this.dataSource instanceof DataManager) && dataType === 'string' || dataType === 'number') {
10002 filterQuery.where('', filterType, this.inputString, this.ignoreCase, this.ignoreAccent);
10003 }
10004 else {
10005 let fields = (this.fields.text) ? this.fields.text : '';
10006 filterQuery.where(fields, filterType, this.inputString, this.ignoreCase, this.ignoreAccent);
10007 }
10008 }
10009 else {
10010 filterQuery = query ? query : this.query ? this.query : new Query();
10011 }
10012 return filterQuery;
10013 }
10014 setFiltering() {
10015 if (isNullOrUndefined(this.filterParent)) {
10016 this.filterParent = this.createElement('span', {
10017 className: 'e-filter-parent'
10018 });
10019 this.filterInput = this.createElement('input', {
10020 attrs: { type: 'text' },
10021 className: 'e-input-filter'
10022 });
10023 this.element.parentNode.insertBefore(this.filterInput, this.element);
10024 let filterInputObj = Input.createInput({
10025 element: this.filterInput
10026 }, this.createElement);
10027 append([filterInputObj.container], this.filterParent);
10028 prepend([this.filterParent], this.list);
10029 attributes(this.filterInput, {
10030 'aria-disabled': 'false',
10031 'aria-owns': this.element.id + '_options',
10032 'role': 'listbox',
10033 'aria-activedescendant': null,
10034 'autocomplete': 'off',
10035 'autocorrect': 'off',
10036 'autocapitalize': 'off',
10037 'spellcheck': 'false'
10038 });
10039 this.inputString = this.filterInput.value;
10040 EventHandler.add(this.filterInput, 'input', this.onInput, this);
10041 EventHandler.add(this.filterInput, 'keyup', this.KeyUp, this);
10042 EventHandler.add(this.filterInput, 'keydown', this.onKeyDown, this);
10043 return filterInputObj;
10044 }
10045 }
10046 selectHandler(e, isKey) {
10047 let isSelect = true;
10048 let currSelIdx;
10049 let li = closest(e.target, '.' + cssClass.li);
10050 let selectedLi = [li];
10051 if (li) {
10052 currSelIdx = [].slice.call(li.parentElement.children).indexOf(li);
10053 if (!this.selectionSettings.showCheckbox) {
10054 if ((e.ctrlKey || Browser.isDevice) && this.isSelected(li)) {
10055 li.classList.remove(cssClass.selected);
10056 li.removeAttribute('aria-selected');
10057 isSelect = false;
10058 }
10059 else if (!(this.selectionSettings.mode === 'Multiple' && (e.ctrlKey || Browser.isDevice))) {
10060 this.getSelectedItems().forEach((ele) => {
10061 ele.removeAttribute('aria-selected');
10062 });
10063 removeClass(this.getSelectedItems(), cssClass.selected);
10064 }
10065 }
10066 else {
10067 isSelect = !li.getElementsByClassName('e-frame')[0].classList.contains('e-check');
10068 }
10069 if (e.shiftKey && !this.selectionSettings.showCheckbox && this.selectionSettings.mode !== 'Single') {
10070 selectedLi = [].slice.call(li.parentElement.children)
10071 .slice(Math.min(currSelIdx, this.prevSelIdx), Math.max(currSelIdx, this.prevSelIdx) + 1)
10072 .filter((ele) => { return ele.classList.contains(cssClass.li); });
10073 }
10074 else {
10075 this.prevSelIdx = [].slice.call(li.parentElement.children).indexOf(li);
10076 }
10077 if (isSelect) {
10078 if (!this.selectionSettings.showCheckbox) {
10079 addClass(selectedLi, cssClass.selected);
10080 }
10081 selectedLi.forEach((ele) => {
10082 ele.setAttribute('aria-selected', 'true');
10083 });
10084 this.list.setAttribute('aria-activedescendant', li.id);
10085 }
10086 if (!isKey && (this.maximumSelectionLength > (this.value && this.value.length) || !isSelect) &&
10087 (this.maximumSelectionLength >= (this.value && this.value.length) || !isSelect) &&
10088 !(this.maximumSelectionLength < (this.value && this.value.length))) {
10089 this.notify('updatelist', { li: li, e: e });
10090 }
10091 if (this.allowFiltering && !isKey) {
10092 let liDataValue = this.getFormattedValue(li.getAttribute('data-value'));
10093 if (!isSelect) {
10094 this.value = this.value.filter((value1) => value1 !== liDataValue);
10095 }
10096 else {
10097 let values = [];
10098 extend(values, this.value);
10099 values.push(liDataValue);
10100 this.value = values;
10101 }
10102 if (document.querySelectorAll('ul').length < 2) {
10103 this.updateMainList();
10104 }
10105 }
10106 this.updateSelectedOptions();
10107 this.triggerChange(this.getSelectedItems(), e);
10108 this.checkMaxSelection();
10109 }
10110 }
10111 triggerChange(selectedLis, event) {
10112 this.trigger('change', { elements: selectedLis, items: this.getDataByElems(selectedLis), value: this.value, event: event });
10113 }
10114 getDataByElems(elems) {
10115 let data = [];
10116 elems.forEach((ele) => {
10117 data.push(this.getDataByValue(this.getFormattedValue(ele.getAttribute('data-value'))));
10118 });
10119 return data;
10120 }
10121 checkMaxSelection() {
10122 let limit = this.list.querySelectorAll('.e-list-item span.e-check').length;
10123 if (this.selectionSettings.showCheckbox) {
10124 let index = 0;
10125 let liCollElem;
10126 liCollElem = this.list.getElementsByClassName('e-list-item');
10127 for (index; index < liCollElem.length; index++) {
10128 if (!liCollElem[index].querySelector('.e-frame.e-check')) {
10129 if (limit === this.maximumSelectionLength) {
10130 liCollElem[index].classList.add('e-disable');
10131 }
10132 else if (liCollElem[index].classList.contains('e-disable')) {
10133 liCollElem[index].classList.remove('e-disable');
10134 }
10135 }
10136 }
10137 }
10138 }
10139 toolbarClickHandler(e) {
10140 let btn = closest(e.target, 'button');
10141 if (btn) {
10142 if (btn.disabled) {
10143 return;
10144 }
10145 switch (btn.getAttribute('data-value')) {
10146 case 'moveUp':
10147 this.moveUpDown(true);
10148 break;
10149 case 'moveDown':
10150 this.moveUpDown();
10151 break;
10152 case 'moveTo':
10153 this.moveItemTo();
10154 break;
10155 case 'moveFrom':
10156 this.moveItemFrom();
10157 break;
10158 case 'moveAllTo':
10159 this.moveAllItemTo();
10160 break;
10161 case 'moveAllFrom':
10162 this.moveAllItemFrom();
10163 break;
10164 }
10165 }
10166 }
10167 moveUpDown(isUp, isKey, value) {
10168 let elems = this.getSelectedItems();
10169 if (value) {
10170 elems = value;
10171 }
10172 if (((isUp && this.isSelected(this.ulElement.firstElementChild))
10173 || (!isUp && this.isSelected(this.ulElement.lastElementChild))) && !value) {
10174 return;
10175 }
10176 (isUp ? elems : elems.reverse()).forEach((ele) => {
10177 let idx = Array.prototype.indexOf.call(this.ulElement.children, ele);
10178 moveTo(this.ulElement, this.ulElement, [idx], isUp ? idx - 1 : idx + 2);
10179 this.changeData(idx, isUp ? idx - 1 : idx + 1, ele);
10180 });
10181 elems[0].focus();
10182 if (!isKey && this.toolbarSettings.items.length) {
10183 this.getToolElem().querySelector('[data-value=' + (isUp ? 'moveUp' : 'moveDown') + ']').focus();
10184 }
10185 this.updateToolBarState();
10186 }
10187 moveItemTo() {
10188 this.moveData(this, this.getScopedListBox());
10189 }
10190 moveItemFrom() {
10191 this.moveData(this.getScopedListBox(), this);
10192 }
10193 /**
10194 * Called internally if any of the property value changed.
10195 * @returns void
10196 * @private
10197 */
10198 // tslint:disable-next-line:max-func-body-length
10199 moveData(fListBox, tListBox, isKey, value, index) {
10200 let idx = [];
10201 let dataIdx = [];
10202 let jsonIdx = [];
10203 let sortIdx = [];
10204 let listData = [].slice.call(fListBox.listData);
10205 let tListData = [].slice.call(tListBox.listData);
10206 let sortData = [].slice.call(fListBox.sortedData);
10207 let tSortData = [].slice.call(tListBox.sortedData);
10208 let fliCollections = [].slice.call(fListBox.liCollections);
10209 let dataLiIdx = [];
10210 let tliCollections = [].slice.call(tListBox.liCollections);
10211 let tempItems = [];
10212 let data = [];
10213 let elems = fListBox.getSelectedItems();
10214 if (value) {
10215 elems = value;
10216 }
10217 let isRefresh = tListBox.sortOrder !== 'None' ||
10218 (tListBox.selectionSettings.showCheckbox !== fListBox.selectionSettings.showCheckbox) || tListBox.fields.groupBy;
10219 fListBox.value = [];
10220 if (elems.length) {
10221 this.removeSelected(fListBox, elems);
10222 elems.forEach((ele, i) => {
10223 idx.push(Array.prototype.indexOf.call(fListBox.ulElement.children, ele)); // update sortable elem
10224 // To update lb view data
10225 dataLiIdx.push(Array.prototype.indexOf.call(fListBox.ulElement.querySelectorAll('.e-list-item'), ele));
10226 // To update lb listdata data
10227 dataIdx.push(Array.prototype.indexOf.call(fListBox.listData, fListBox.getDataByElems([ele])[0]));
10228 // To update lb sorted data
10229 sortIdx.push(Array.prototype.indexOf.call(fListBox.sortedData, fListBox.getDataByElems([ele])[0]));
10230 // To update lb original data
10231 jsonIdx.push(Array.prototype.indexOf.call(fListBox.jsonData, fListBox.getDataByElems([ele])[0]));
10232 });
10233 if (this.sortOrder !== 'None') {
10234 sortIdx.forEach((i) => {
10235 tempItems.push(fListBox.sortedData[i]);
10236 });
10237 }
10238 else {
10239 jsonIdx.forEach((i) => {
10240 tempItems.push(fListBox.jsonData[i]);
10241 });
10242 }
10243 let rLiCollection = [];
10244 dataLiIdx.sort((n1, n2) => n1 - n2).reverse().forEach((i) => {
10245 rLiCollection.push(fliCollections.splice(i, 1)[0]);
10246 });
10247 fListBox.liCollections = fliCollections;
10248 if (index) {
10249 let toColl = tliCollections.splice(0, index);
10250 tListBox.liCollections = toColl.concat(rLiCollection.reverse()).concat(tliCollections);
10251 }
10252 else {
10253 tListBox.liCollections = tliCollections.concat(rLiCollection.reverse());
10254 }
10255 if (tListBox.listData.length === 0) {
10256 tListBox.ulElement.innerHTML = '';
10257 }
10258 dataIdx.sort((n1, n2) => n2 - n1).forEach((i) => {
10259 listData.splice(i, 1)[0];
10260 });
10261 sortIdx.sort((n1, n2) => n2 - n1).forEach((i) => {
10262 sortData.splice(i, 1)[0];
10263 });
10264 jsonIdx.slice().reverse().forEach((i) => {
10265 data.push(fListBox.jsonData.splice(i, 1)[0]);
10266 });
10267 if (isRefresh) {
10268 if (fListBox.fields.groupBy) {
10269 fListBox.ulElement.innerHTML = fListBox.renderItems(listData, fListBox.fields).innerHTML;
10270 }
10271 else {
10272 elems.forEach((ele) => { detach(ele); });
10273 }
10274 }
10275 else {
10276 moveTo(fListBox.ulElement, tListBox.ulElement, idx, index);
10277 }
10278 if (tListBox.mainList.childElementCount !== tListBox.jsonData.length) {
10279 tListBox.mainList = tListBox.ulElement;
10280 }
10281 fListBox.updateMainList();
10282 let childCnt = fListBox.ulElement.querySelectorAll('.e-list-item').length;
10283 let ele;
10284 let liIdx;
10285 let tJsonData = [].slice.call(tListBox.jsonData);
10286 tSortData = [].slice.call(tListBox.sortedData);
10287 if (elems.length === 1 && childCnt && !fListBox.selectionSettings.showCheckbox) {
10288 liIdx = childCnt <= dataLiIdx[0] ? childCnt - 1 : dataLiIdx[0];
10289 ele = fListBox.ulElement.querySelectorAll('.e-list-item')[liIdx];
10290 fListBox.ulElement.querySelectorAll('.e-list-item')[fListBox.getValidIndex(ele, liIdx, childCnt === dataIdx[0]
10291 ? 38 : 40)].classList.add(cssClass.selected);
10292 }
10293 if (isKey) {
10294 this.list.focus();
10295 }
10296 fListBox.listData = listData;
10297 fListBox.sortedData = sortData;
10298 index = (index) ? index : tListData.length;
10299 for (let i = 0; i < tempItems.length; i++) {
10300 tListData.splice(index, 0, tempItems[i]);
10301 tJsonData.splice(index, 0, tempItems[i]);
10302 tSortData.splice(index, 0, tempItems[i]);
10303 }
10304 tListBox.listData = tListData;
10305 tListBox.jsonData = tJsonData;
10306 tListBox.sortedData = tSortData;
10307 if (isRefresh) {
10308 tListBox.ulElement.innerHTML = tListBox.renderItems(tListData, tListBox.fields).innerHTML;
10309 tListBox.setSelection();
10310 }
10311 fListBox.updateSelectedOptions();
10312 if (fListBox.listData.length === 0) {
10313 fListBox.l10nUpdate();
10314 }
10315 }
10316 if (fListBox.value.length === 1 && fListBox.getSelectedItems().length) {
10317 fListBox.value[0] = fListBox.getSelectedItems()[0].innerHTML;
10318 }
10319 }
10320 moveAllItemTo() {
10321 this.moveAllData(this, this.getScopedListBox());
10322 }
10323 moveAllItemFrom() {
10324 this.moveAllData(this.getScopedListBox(), this);
10325 }
10326 moveAllData(fListBox, tListBox, isKey, index) {
10327 let listData = [].slice.call(tListBox.listData);
10328 let jsonData = [].slice.call(tListBox.jsonData);
10329 let isRefresh = tListBox.sortOrder !== 'None' ||
10330 (tListBox.selectionSettings.showCheckbox !== fListBox.selectionSettings.showCheckbox) || tListBox.fields.groupBy;
10331 this.removeSelected(fListBox, fListBox.getSelectedItems());
10332 if (tListBox.listData.length === 0) {
10333 tListBox.ulElement.innerHTML = '';
10334 }
10335 if (isRefresh) {
10336 fListBox.ulElement.innerHTML = '';
10337 }
10338 else {
10339 moveTo(fListBox.ulElement, tListBox.ulElement, Array.apply(null, { length: fListBox.ulElement.childElementCount }).map(Number.call, Number), index);
10340 }
10341 if (isKey) {
10342 this.list.focus();
10343 }
10344 index = (index) ? index : listData.length;
10345 for (let i = 0; i < fListBox.listData.length; i++) {
10346 listData.splice(index + i, 0, fListBox.listData[i]);
10347 }
10348 for (let i = 0; i < fListBox.jsonData.length; i++) {
10349 jsonData.splice(index + i, 0, fListBox.jsonData[i]);
10350 }
10351 let fliCollections = [].slice.call(fListBox.liCollections);
10352 let tliCollections = [].slice.call(tListBox.liCollections);
10353 fListBox.liCollections = [];
10354 fListBox.value = [];
10355 if (index) {
10356 let toColl = tliCollections.splice(0, index);
10357 tListBox.liCollections = toColl.concat(fliCollections).concat(tliCollections);
10358 }
10359 else {
10360 tListBox.liCollections = tliCollections.concat(fliCollections);
10361 }
10362 listData = listData
10363 .filter((data) => data.isHeader !== true);
10364 tListBox.listData = listData;
10365 tListBox.jsonData = jsonData;
10366 fListBox.listData = fListBox.sortedData = fListBox.jsonData = [];
10367 if (isRefresh) {
10368 tListBox.ulElement.innerHTML = tListBox.renderItems(listData, tListBox.fields).innerHTML;
10369 }
10370 else {
10371 tListBox.sortedData = listData;
10372 }
10373 fListBox.updateSelectedOptions();
10374 if (fListBox.listData.length === 0) {
10375 fListBox.l10nUpdate();
10376 }
10377 }
10378 changeData(fromIdx, toIdx, ele) {
10379 let listData = [].slice.call(this.listData);
10380 let jsonData = [].slice.call(this.jsonData);
10381 let jsonIdx = Array.prototype.indexOf.call(this.jsonData, this.getDataByElems([ele])[0]);
10382 let liColl = [].slice.call(this.liCollections);
10383 listData.splice(toIdx, 0, listData.splice(fromIdx, 1)[0]);
10384 jsonData.splice(toIdx, 0, jsonData.splice(jsonIdx, 1)[0]);
10385 liColl.splice(toIdx, 0, liColl.splice(fromIdx, 1)[0]);
10386 this.listData = listData;
10387 this.jsonData = jsonData;
10388 this.liCollections = liColl;
10389 }
10390 getSelectedItems() {
10391 let ele = [];
10392 if (this.selectionSettings.showCheckbox) {
10393 [].slice.call(this.ulElement.getElementsByClassName('e-check')).forEach((cbox) => {
10394 ele.push(closest(cbox, '.' + cssClass.li));
10395 });
10396 }
10397 else {
10398 ele = [].slice.call(this.ulElement.getElementsByClassName(cssClass.selected));
10399 }
10400 return ele;
10401 }
10402 getScopedListBox() {
10403 let listObj;
10404 if (this.scope) {
10405 [].slice.call(document.querySelectorAll(this.scope)).forEach((ele) => {
10406 if (getComponent(ele, this.getModuleName())) {
10407 listObj = getComponent(ele, this.getModuleName());
10408 }
10409 });
10410 }
10411 return listObj;
10412 }
10413 getDragArgs(args, isDragEnd) {
10414 let elems = this.getSelectedItems();
10415 if (elems.length) {
10416 elems.pop();
10417 if (isDragEnd) {
10418 elems.push(args.target);
10419 }
10420 }
10421 else {
10422 elems = [args.target];
10423 }
10424 if (isBlazor()) {
10425 return { elements: elems, items: this.getDataByElems(elems), bindEvents: args.bindEvents,
10426 dragElement: args.dragElement };
10427 }
10428 else {
10429 return { elements: elems, items: this.getDataByElems(elems) };
10430 }
10431 }
10432 onKeyDown(e) {
10433 this.keyDownHandler(e);
10434 event.stopPropagation();
10435 }
10436 keyDownHandler(e) {
10437 if ([32, 35, 36, 37, 38, 39, 40, 65].indexOf(e.keyCode) > -1 && !this.allowFiltering) {
10438 e.preventDefault();
10439 if (e.keyCode === 32 && this.ulElement.children.length) {
10440 this.selectHandler({
10441 target: this.ulElement.getElementsByClassName('e-focused')[0],
10442 ctrlKey: e.ctrlKey, shiftKey: e.shiftKey
10443 });
10444 }
10445 else if (e.keyCode === 65 && e.ctrlKey) {
10446 this.selectAll();
10447 }
10448 else if ((e.keyCode === 38 || e.keyCode === 40) && e.ctrlKey && e.shiftKey) {
10449 this.moveUpDown(e.keyCode === 38 ? true : false, true);
10450 }
10451 else if ((this.toolbarSettings.items.length || this.tBListBox) && (e.keyCode === 39 || e.keyCode === 37) && e.ctrlKey) {
10452 let listObj = this.tBListBox || this.getScopedListBox();
10453 if (e.keyCode === 39) {
10454 e.shiftKey ? this.moveAllData(this, listObj, true) : this.moveData(this, listObj, true);
10455 }
10456 else {
10457 e.shiftKey ? this.moveAllData(listObj, this, true) : this.moveData(listObj, this, true);
10458 }
10459 }
10460 else if (e.keyCode !== 37 && e.keyCode !== 39) {
10461 this.upDownKeyHandler(e);
10462 }
10463 }
10464 else if (this.allowFiltering) {
10465 if (e.keyCode === 40 || e.keyCode === 38) {
10466 this.upDownKeyHandler(e);
10467 }
10468 }
10469 }
10470 upDownKeyHandler(e) {
10471 let ul = this.ulElement;
10472 let defaultIdx = (e.keyCode === 40 || e.keyCode === 36) ? 0 : ul.childElementCount - 1;
10473 let fliIdx = defaultIdx;
10474 let fli = ul.getElementsByClassName('e-focused')[0] || ul.getElementsByClassName(cssClass.selected)[0];
10475 if (fli) {
10476 if (e.keyCode !== 35 && e.keyCode !== 36) {
10477 fliIdx = Array.prototype.indexOf.call(ul.children, fli);
10478 e.keyCode === 40 ? fliIdx++ : fliIdx--;
10479 if (fliIdx < 0 || fliIdx > ul.childElementCount - 1) {
10480 return;
10481 }
10482 }
10483 removeClass([fli], 'e-focused');
10484 }
10485 let cli = ul.children[fliIdx];
10486 if (cli) {
10487 fliIdx = this.getValidIndex(cli, fliIdx, e.keyCode);
10488 if (fliIdx === -1) {
10489 addClass([fli], 'e-focused');
10490 return;
10491 }
10492 ul.children[fliIdx].focus();
10493 ul.children[fliIdx].classList.add('e-focused');
10494 if (!e.ctrlKey) {
10495 this.selectHandler({ target: ul.children[fliIdx], ctrlKey: e.ctrlKey, shiftKey: e.shiftKey }, true);
10496 }
10497 }
10498 }
10499 KeyUp(e) {
10500 let char = String.fromCharCode(e.keyCode);
10501 let isWordCharacter = char.match(/\w/);
10502 if (!isNullOrUndefined(isWordCharacter)) {
10503 this.isValidKey = true;
10504 }
10505 this.isValidKey = (e.keyCode === 8) || this.isValidKey;
10506 if (this.isValidKey) {
10507 this.isValidKey = false;
10508 switch (e.keyCode) {
10509 default:
10510 let text = this.targetElement();
10511 let keyCode = e.keyCode;
10512 if (this.allowFiltering) {
10513 let eventArgsData = {
10514 preventDefaultAction: false,
10515 text: this.targetElement(),
10516 updateData: (dataSource, query, fields) => {
10517 if (eventArgsData.cancel) {
10518 return;
10519 }
10520 this.isFiltered = true;
10521 this.remoteFilterAction = true;
10522 this.dataUpdater(dataSource, query, fields);
10523 },
10524 event: e,
10525 cancel: false
10526 };
10527 this.trigger('filtering', eventArgsData, (args) => {
10528 this.isDataFetched = false;
10529 if (eventArgsData.cancel || (this.filterInput.value !== '' && this.isFiltered)) {
10530 return;
10531 }
10532 if (!eventArgsData.cancel && !this.isCustomFiltering && !eventArgsData.preventDefaultAction) {
10533 this.inputString = this.filterInput.value;
10534 this.filteringAction(this.jsonData, new Query(), this.fields);
10535 }
10536 if (!this.isFiltered && !this.isCustomFiltering && !eventArgsData.preventDefaultAction) {
10537 this.dataUpdater(this.jsonData, new Query(), this.fields);
10538 }
10539 });
10540 }
10541 }
10542 }
10543 }
10544 /**
10545 * To filter the data from given data source by using query
10546 * @param {Object[] | DataManager } dataSource - Set the data source to filter.
10547 * @param {Query} query - Specify the query to filter the data.
10548 * @param {FieldSettingsModel} fields - Specify the fields to map the column in the data table.
10549 * @return {void}.
10550 */
10551 filter(dataSource, query, fields) {
10552 this.isCustomFiltering = true;
10553 this.filteringAction(dataSource, query, fields);
10554 }
10555 filteringAction(dataSource, query, fields) {
10556 this.resetList(dataSource, fields, query);
10557 }
10558 targetElement() {
10559 this.targetInputElement = this.list.getElementsByClassName('e-input-filter')[0];
10560 return this.targetInputElement.value;
10561 }
10562 dataUpdater(dataSource, query, fields) {
10563 this.isDataFetched = false;
10564 let backCommand = true;
10565 if (this.targetElement().trim() === '') {
10566 let list = this.mainList.cloneNode ? this.mainList.cloneNode(true) : this.mainList;
10567 if (backCommand) {
10568 this.remoteCustomValue = false;
10569 this.onActionComplete(list, this.jsonData);
10570 this.notify('reOrder', { module: 'CheckBoxSelection', enable: this.selectionSettings.showCheckbox, e: this });
10571 }
10572 }
10573 else {
10574 this.resetList(dataSource, fields, query);
10575 }
10576 }
10577 focusOutHandler() {
10578 let ele = this.list.getElementsByClassName('e-focused')[0];
10579 if (ele) {
10580 ele.classList.remove('e-focused');
10581 }
10582 }
10583 getValidIndex(cli, index, keyCode) {
10584 let cul = this.ulElement;
10585 if (cli.classList.contains('e-disabled') || cli.classList.contains(cssClass.group)) {
10586 (keyCode === 40 || keyCode === 36) ? index++ : index--;
10587 }
10588 if (index < 0 || index === cul.childElementCount) {
10589 return -1;
10590 }
10591 cli = cul.querySelectorAll('.e-list-item')[index];
10592 if (cli.classList.contains('e-disabled') || cli.classList.contains(cssClass.group)) {
10593 index = this.getValidIndex(cli, index, keyCode);
10594 }
10595 return index;
10596 }
10597 updateSelectedOptions() {
10598 let selectedOptions = [];
10599 let values = [];
10600 extend(values, this.value);
10601 this.getSelectedItems().forEach((ele) => {
10602 if (!ele.classList.contains('e-grabbed')) {
10603 selectedOptions.push(this.getFormattedValue(ele.getAttribute('data-value')));
10604 }
10605 });
10606 if (this.mainList.childElementCount === this.ulElement.childElementCount) {
10607 this.setProperties({ value: selectedOptions }, true);
10608 }
10609 this.updateSelectTag();
10610 this.updateToolBarState();
10611 if (this.tBListBox) {
10612 this.tBListBox.updateToolBarState();
10613 }
10614 if (this.allowFiltering) {
10615 this.list.getElementsByClassName('e-input-filter')[0].focus();
10616 }
10617 }
10618 clearSelection(values = this.value) {
10619 if (this.selectionSettings.showCheckbox) {
10620 let dvalue;
10621 this.getSelectedItems().forEach((li) => {
10622 dvalue = this.getFormattedValue(li.getAttribute('data-value'));
10623 if (values.indexOf(dvalue) < 0) {
10624 li.getElementsByClassName('e-check')[0].classList.remove('e-check');
10625 li.getElementsByClassName('e-checkbox-wrapper')[0].removeAttribute('aria-checked');
10626 li.removeAttribute('aria-selected');
10627 }
10628 });
10629 }
10630 }
10631 ;
10632 setSelection(values = this.value, isSelect = true, isText = false) {
10633 let li;
10634 let liselect;
10635 if (values) {
10636 values.forEach((value) => {
10637 li = this.list.querySelector('[data-value="' + (isText ? this.getValueByText(value) : value) + '"]');
10638 if (li) {
10639 if (this.selectionSettings.showCheckbox) {
10640 liselect = li.getElementsByClassName('e-frame')[0].classList.contains('e-check');
10641 }
10642 else {
10643 liselect = li.classList.contains('e-selected');
10644 }
10645 if (!isSelect && liselect || isSelect && !liselect && li) {
10646 if (this.selectionSettings.showCheckbox) {
10647 this.notify('updatelist', { li: li });
10648 }
10649 else {
10650 if (isSelect) {
10651 li.classList.add(cssClass.selected);
10652 li.setAttribute('aria-selected', 'true');
10653 }
10654 else {
10655 li.classList.remove(cssClass.selected);
10656 li.removeAttribute('aria-selected');
10657 }
10658 }
10659 }
10660 }
10661 });
10662 }
10663 this.updateSelectTag();
10664 }
10665 updateSelectTag() {
10666 let ele = this.getSelectTag();
10667 ele.innerHTML = '';
10668 if (this.value) {
10669 Array.prototype.forEach.call(this.value, (value) => {
10670 ele.innerHTML += '<option selected value="' + value + '"></option>';
10671 });
10672 }
10673 this.checkSelectAll();
10674 }
10675 updateToolBarState() {
10676 if (this.toolbarSettings.items.length) {
10677 let listObj = this.getScopedListBox();
10678 let wrap = this.list.parentElement.getElementsByClassName('e-listbox-tool')[0];
10679 this.toolbarSettings.items.forEach((value) => {
10680 let btn = wrap.querySelector('[data-value="' + value + '"]');
10681 switch (value) {
10682 case 'moveAllTo':
10683 btn.disabled = this.ulElement.childElementCount ? false : true;
10684 break;
10685 case 'moveAllFrom':
10686 btn.disabled = listObj.ulElement.childElementCount ? false : true;
10687 break;
10688 case 'moveFrom':
10689 btn.disabled = listObj.value && listObj.value.length ? false : true;
10690 break;
10691 case 'moveUp':
10692 btn.disabled = this.value && this.value.length
10693 && !this.isSelected(this.ulElement.children[0]) ? false : true;
10694 break;
10695 case 'moveDown':
10696 btn.disabled = this.value && this.value.length
10697 && !this.isSelected(this.ulElement.children[this.ulElement.childElementCount - 1]) ? false : true;
10698 break;
10699 default:
10700 btn.disabled = this.value && this.value.length ? false : true;
10701 break;
10702 }
10703 });
10704 }
10705 }
10706 setCheckboxPosition() {
10707 let listWrap = this.list;
10708 if (!this.initLoad && this.selectionSettings.checkboxPosition === 'Left') {
10709 listWrap.classList.remove('e-right');
10710 }
10711 if (this.selectionSettings.checkboxPosition === 'Right') {
10712 listWrap.classList.add('e-right');
10713 }
10714 }
10715 showCheckbox(showCheckbox) {
10716 let index = 0;
10717 let liColl = this.list.lastElementChild.querySelectorAll('li');
10718 let liCollLen = this.list.lastElementChild.getElementsByClassName('e-list-item').length;
10719 if (showCheckbox) {
10720 this.ulElement = this.renderItems(this.listData, this.fields);
10721 this.mainList = this.ulElement;
10722 this.list.removeChild(this.list.getElementsByTagName('ul')[0]);
10723 this.list.appendChild(this.ulElement);
10724 if (this.selectionSettings.showSelectAll) {
10725 let l10nShow = new L10n(this.getModuleName(), { selectAllText: 'Select All', unSelectAllText: 'Unselect All' }, this.locale);
10726 this.showSelectAll = true;
10727 this.selectAllText = l10nShow.getConstant('selectAllText');
10728 this.unSelectAllText = l10nShow.getConstant('unSelectAllText');
10729 this.popupWrapper = this.list;
10730 this.checkBoxSelectionModule.checkAllParent = null;
10731 this.notify('selectAll', {});
10732 this.checkSelectAll();
10733 }
10734 }
10735 else {
10736 if (this.selectionSettings.showSelectAll) {
10737 this.list.removeChild(this.list.getElementsByClassName('e-selectall-parent')[0]);
10738 }
10739 for (index; index < liCollLen; index++) {
10740 liColl[index].removeChild(liColl[index].getElementsByClassName('e-checkbox-wrapper')[0]);
10741 if (liColl[index].hasAttribute('aria-selected')) {
10742 liColl[index].removeAttribute('aria-selected');
10743 }
10744 }
10745 this.mainList = this.ulElement;
10746 }
10747 this.value = [];
10748 }
10749 isSelected(ele) {
10750 if (!isNullOrUndefined(ele)) {
10751 return ele.classList.contains(cssClass.selected) || ele.querySelector('.e-check') !== null;
10752 }
10753 else {
10754 return false;
10755 }
10756 }
10757 getSelectTag() {
10758 return this.list.getElementsByClassName('e-hidden-select')[0];
10759 }
10760 getToolElem() {
10761 return this.list.parentElement.getElementsByClassName('e-listbox-tool')[0];
10762 }
10763 formResetHandler() {
10764 this.value = this.initialSelectedOptions;
10765 }
10766 /**
10767 * Return the module name.
10768 * @private
10769 */
10770 getModuleName() {
10771 return 'listbox';
10772 }
10773 /**
10774 * Get the properties to be maintained in the persisted state.
10775 */
10776 getPersistData() {
10777 return this.addOnPersist(['value']);
10778 }
10779 getLocaleName() {
10780 return 'listbox';
10781 }
10782 ;
10783 destroy() {
10784 if (this.itemTemplate) {
10785 resetBlazorTemplate(`${this.element.id}${ITEMTEMPLATE_PROPERTY$1}`, ITEMTEMPLATE_PROPERTY$1);
10786 }
10787 this.unwireEvents();
10788 if (this.element.tagName === 'EJS-LISTBOX') {
10789 this.element.innerHTML = '';
10790 }
10791 else {
10792 this.element.style.display = 'inline-block';
10793 if (this.toolbarSettings.items.length) {
10794 this.list.parentElement.parentElement.insertBefore(this.list, this.list.parentElement);
10795 detach(this.list.nextElementSibling);
10796 }
10797 this.list.parentElement.insertBefore(this.element, this.list);
10798 }
10799 super.destroy();
10800 }
10801 /**
10802 * Called internally if any of the property value changed.
10803 * @returns void
10804 * @private
10805 */
10806 // tslint:disable-next-line:max-func-body-length
10807 onPropertyChanged(newProp, oldProp) {
10808 let wrap = this.toolbarSettings.items.length ? this.list.parentElement : this.list;
10809 super.onPropertyChanged(newProp, oldProp);
10810 this.setUpdateInitial(['fields', 'query', 'dataSource'], newProp);
10811 for (let prop of Object.keys(newProp)) {
10812 switch (prop) {
10813 case 'cssClass':
10814 if (oldProp.cssClass) {
10815 removeClass([wrap], oldProp.cssClass.split(' '));
10816 }
10817 if (newProp.cssClass) {
10818 addClass([wrap], newProp.cssClass.split(' '));
10819 }
10820 break;
10821 case 'enableRtl':
10822 if (newProp.enableRtl) {
10823 wrap.classList.add('e-rtl');
10824 }
10825 else {
10826 wrap.classList.remove('e-rtl');
10827 }
10828 break;
10829 case 'value':
10830 removeClass(this.list.querySelectorAll('.' + cssClass.selected), cssClass.selected);
10831 this.clearSelection(this.value);
10832 this.setSelection();
10833 break;
10834 case 'height':
10835 this.setHeight();
10836 break;
10837 case 'enabled':
10838 this.setEnable();
10839 break;
10840 case 'allowDragAndDrop':
10841 if (newProp.allowDragAndDrop) {
10842 this.initDraggable();
10843 }
10844 else {
10845 getComponent(this.ulElement, 'sortable').destroy();
10846 }
10847 break;
10848 case 'allowFiltering':
10849 if (this.allowFiltering) {
10850 this.setFiltering();
10851 }
10852 else {
10853 this.list.removeChild(this.list.getElementsByClassName('e-filter-parent')[0]);
10854 this.filterParent = null;
10855 }
10856 break;
10857 case 'scope':
10858 if (this.allowDragAndDrop) {
10859 getComponent(this.ulElement, 'sortable').scope = newProp.scope;
10860 }
10861 if (this.toolbarSettings.items.length) {
10862 if (oldProp.scope) {
10863 getComponent(document.querySelector(oldProp.scope), this.getModuleName())
10864 .tBListBox = null;
10865 }
10866 if (newProp.scope) {
10867 getComponent(document.querySelector(newProp.scope), this.getModuleName())
10868 .tBListBox = this;
10869 }
10870 }
10871 break;
10872 case 'toolbarSettings':
10873 let ele;
10874 let pos = newProp.toolbarSettings.position;
10875 let toolElem = this.getToolElem();
10876 if (pos) {
10877 removeClass([wrap], ['e-right', 'e-left']);
10878 wrap.classList.add('e-' + pos.toLowerCase());
10879 if (pos === 'Left') {
10880 wrap.insertBefore(toolElem, this.list);
10881 }
10882 else {
10883 wrap.appendChild(toolElem);
10884 }
10885 }
10886 if (newProp.toolbarSettings.items) {
10887 if (oldProp.toolbarSettings.items.length) {
10888 ele = this.list.parentElement;
10889 ele.parentElement.insertBefore(this.list, ele);
10890 detach(ele);
10891 }
10892 this.initToolbarAndStyles();
10893 this.wireToolbarEvent();
10894 }
10895 break;
10896 case 'selectionSettings':
10897 let showSelectAll = newProp.selectionSettings.showSelectAll;
10898 let showCheckbox = newProp.selectionSettings.showCheckbox;
10899 if (!isNullOrUndefined(showSelectAll)) {
10900 this.showSelectAll = showSelectAll;
10901 if (this.showSelectAll) {
10902 let l10nSel = new L10n(this.getModuleName(), { selectAllText: 'Select All', unSelectAllText: 'Unselect All' }, this.locale);
10903 this.checkBoxSelectionModule.checkAllParent = null;
10904 this.showSelectAll = true;
10905 this.selectAllText = l10nSel.getConstant('selectAllText');
10906 this.unSelectAllText = l10nSel.getConstant('selectAllText');
10907 this.popupWrapper = this.list;
10908 }
10909 this.notify('selectAll', {});
10910 this.checkSelectAll();
10911 }
10912 if (!isNullOrUndefined(showCheckbox)) {
10913 this.showCheckbox(showCheckbox);
10914 }
10915 if (this.selectionSettings.showCheckbox) {
10916 this.setCheckboxPosition();
10917 }
10918 break;
10919 case 'dataSource':
10920 this.jsonData = [].slice.call(this.dataSource);
10921 break;
10922 }
10923 }
10924 }
10925};
10926__decorate$5([
10927 Complex({ text: null, value: null, iconCss: null, groupBy: null }, FieldSettings)
10928], ListBox.prototype, "fields", void 0);
10929__decorate$5([
10930 Property(false)
10931], ListBox.prototype, "enablePersistence", void 0);
10932__decorate$5([
10933 Property(null)
10934], ListBox.prototype, "itemTemplate", void 0);
10935__decorate$5([
10936 Property('None')
10937], ListBox.prototype, "sortOrder", void 0);
10938__decorate$5([
10939 Property(true)
10940], ListBox.prototype, "enabled", void 0);
10941__decorate$5([
10942 Property([])
10943], ListBox.prototype, "dataSource", void 0);
10944__decorate$5([
10945 Property(null)
10946], ListBox.prototype, "query", void 0);
10947__decorate$5([
10948 Property('StartsWith')
10949], ListBox.prototype, "filterType", void 0);
10950__decorate$5([
10951 Property()
10952], ListBox.prototype, "locale", void 0);
10953__decorate$5([
10954 Property('')
10955], ListBox.prototype, "cssClass", void 0);
10956__decorate$5([
10957 Property([])
10958], ListBox.prototype, "value", void 0);
10959__decorate$5([
10960 Property('')
10961], ListBox.prototype, "height", void 0);
10962__decorate$5([
10963 Property(false)
10964], ListBox.prototype, "allowDragAndDrop", void 0);
10965__decorate$5([
10966 Property(1000)
10967], ListBox.prototype, "maximumSelectionLength", void 0);
10968__decorate$5([
10969 Property(false)
10970], ListBox.prototype, "allowFiltering", void 0);
10971__decorate$5([
10972 Property('')
10973], ListBox.prototype, "scope", void 0);
10974__decorate$5([
10975 Property(true)
10976], ListBox.prototype, "ignoreCase", void 0);
10977__decorate$5([
10978 Event()
10979], ListBox.prototype, "beforeItemRender", void 0);
10980__decorate$5([
10981 Event()
10982], ListBox.prototype, "filtering", void 0);
10983__decorate$5([
10984 Event()
10985], ListBox.prototype, "select", void 0);
10986__decorate$5([
10987 Event()
10988], ListBox.prototype, "change", void 0);
10989__decorate$5([
10990 Event()
10991], ListBox.prototype, "beforeDrop", void 0);
10992__decorate$5([
10993 Event()
10994], ListBox.prototype, "dragStart", void 0);
10995__decorate$5([
10996 Event()
10997], ListBox.prototype, "drag", void 0);
10998__decorate$5([
10999 Event()
11000], ListBox.prototype, "drop", void 0);
11001__decorate$5([
11002 Event()
11003], ListBox.prototype, "dataBound", void 0);
11004__decorate$5([
11005 Property(null)
11006], ListBox.prototype, "groupTemplate", void 0);
11007__decorate$5([
11008 Property('No Records Found')
11009], ListBox.prototype, "noRecordsTemplate", void 0);
11010__decorate$5([
11011 Property('The Request Failed')
11012], ListBox.prototype, "actionFailureTemplate", void 0);
11013__decorate$5([
11014 Property(1000)
11015], ListBox.prototype, "zIndex", void 0);
11016__decorate$5([
11017 Property(false)
11018], ListBox.prototype, "ignoreAccent", void 0);
11019__decorate$5([
11020 Complex({}, ToolbarSettings)
11021], ListBox.prototype, "toolbarSettings", void 0);
11022__decorate$5([
11023 Complex({}, SelectionSettings)
11024], ListBox.prototype, "selectionSettings", void 0);
11025ListBox = ListBox_1 = __decorate$5([
11026 NotifyPropertyChanges
11027], ListBox);
11028
11029/**
11030 * export all modules from current location
11031 */
11032
11033/**
11034 * export all modules from current location
11035 */
11036
11037export { incrementalSearch, Search, highlightSearch, revertHighlightSearch, FieldSettings, dropDownBaseClasses, DropDownBase, dropDownListClasses, DropDownList, ComboBox, AutoComplete, MultiSelect, CheckBoxSelection, SelectionSettings, ToolbarSettings, ListBox };
11038//# sourceMappingURL=ej2-dropdowns.es2015.js.map