all files / combo-box/ combo-box.js

96.81% Statements 547/565
83.2% Branches 520/625
98.41% Functions 62/63
96.77% Lines 540/558
5 statements, 2 functions, 11 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873    13× 13× 13×       302× 302× 302× 302×           215×   224×     224× 133× 133×   224× 145×   224× 224× 218× 218× 218× 218× 218×   224×         19×   19×   19×   2873×                     40×         40× 27× 27× 27× 27×                             27× 25×         13×           10×   40× 40×   182× 182× 78×     104×       224×                   224×   88× 88× 40× 40×       48×   48×     227×   370× 370× 370×   328× 328× 328×   328× 36× 36×       220× 220× 220× 220× 19×   201×   189× 189× 189× 189× 189×                                                     189× 189× 99× 99× 99× 67× 67× 67× 66×         67×       90×       189×     12×     249× 18×   249×     242×     25× 25× 25× 25× 25×     288× 284×       284× 284×       284×     283× 282× 282× 282×     281×   282×     75× 52×   75× 42× 42× 42× 29×     22×     42× 36×       42×             34×     77× 64×   75×     70×   94×   94× 94× 61× 52× 52× 52×   61× 61×   33× 11× 11× 11× 11×   11× 11×       22× 22× 22× 17×       49× 49× 49× 49×     36× 36× 36× 36× 18× 18× 18×   18× 10× 10×     93×   147× 78× 76×   145× 85×   145× 144× 144× 143× 143× 143× 143× 143×     145×   249× 247× 164×     12× 12×                     12×   11×   12×   122× 122× 121× 121×     20×   20× 20×   15× 15×   15×   77× 77× 77×       71× 55× 55× 47× 47× 47× 47× 46× 46×                   16× 14×     47× 47× 47× 47× 47×     46× 46×   47× 47× 47×       47×         47× 47× 47× 47× 47× 44×     200× 125× 125×   200× 207× 207×                 197× 197× 196×     196×         224× 224× 224×   9902×       125×   267×   267× 208× 208×   208× 28×   208× 208× 208× 63×   63× 63×   145× 36× 36× 36× 36× 36× 28×   36× 36×   28×     144× 58×     203× 203×   203×   21×   19×   19×   13×   26×   692×   260×                                                                                                              
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/* istanbul ignore next */ 
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    Iif (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) Eif (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../drop-down-list/drop-down-list", "../common/incremental-search", "@syncfusion/ej2-popups", "@syncfusion/ej2-inputs", "@syncfusion/ej2-data"], function (require, exports, ej2_base_1, ej2_base_2, drop_down_list_1, incremental_search_1, ej2_popups_1, ej2_inputs_1, ej2_data_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var SPINNER_CLASS = 'e-atc-spinner-icon';
    drop_down_list_1.dropDownListClasses.root = 'e-combobox';
    var inputObject = {
        container: null,
        buttons: []
    };
    var ComboBox = (function (_super) {
        __extends(ComboBox, _super);
        function ComboBox(options, element) {
            return _super.call(this, options, element) || this;
        }
        ComboBox.prototype.preRender = function () {
            _super.prototype.preRender.call(this);
        };
        ComboBox.prototype.getLocaleName = function () {
            return 'combo-box';
        };
        ComboBox.prototype.wireEvent = function () {
            if (this.getModuleName() === 'combobox') {
                ej2_base_1.EventHandler.add(this.inputWrapper.buttons[0], 'mousedown', this.preventBlur, this);
                ej2_base_1.EventHandler.add(this.inputWrapper.container, 'blur', this.onBlurHandler, this);
            }
            if (!ej2_base_2.isNullOrUndefined(this.inputWrapper.buttons[0])) {
                ej2_base_1.EventHandler.add(this.inputWrapper.buttons[0], 'mousedown', this.dropDownClick, this);
            }
            ej2_base_1.EventHandler.add(this.inputElement, 'focus', this.targetFocus, this);
            if (!this.readonly) {
                ej2_base_1.EventHandler.add(this.inputElement, 'input', this.onInput, this);
                ej2_base_1.EventHandler.add(this.inputElement, 'keyup', this.onFilterUp, this);
                ej2_base_1.EventHandler.add(this.inputElement, 'keydown', this.onFilterDown, this);
                ej2_base_1.EventHandler.add(this.inputElement, 'paste', this.pasteHandler, this);
                ej2_base_1.EventHandler.add(window, 'resize', this.windowResize, this);
            }
            this.bindCommonEvent();
        };
        ComboBox.prototype.preventBlur = function (e) {
            if ((!this.allowFiltering && document.activeElement !== this.inputElement &&
                !document.activeElement.classList.contains(drop_down_list_1.dropDownListClasses.input) && ej2_base_1.Browser.isDevice || !ej2_base_1.Browser.isDevice)) {
                e.preventDefault();
            }
        };
        ComboBox.prototype.onBlurHandler = function (e) {
            var inputValue = this.inputElement && this.inputElement.value === '' ?
                null : this.inputElement && this.inputElement.value;
            if (!ej2_base_2.isNullOrUndefined(this.listData) && !ej2_base_2.isNullOrUndefined(inputValue) && inputValue !== this.text) {
                this.customValue(e);
            }
            _super.prototype.onBlurHandler.call(this, e);
        };
        ComboBox.prototype.targetElement = function () {
            return this.inputElement;
        };
        ComboBox.prototype.setOldText = function (text) {
            ej2_inputs_1.Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
            this.customValue();
            this.removeSelection();
        };
        ComboBox.prototype.setOldValue = function (value) {
            if (this.allowCustom) {
                this.valueMuteChange(this.value);
            }
            else {
                this.valueMuteChange(null);
            }
            this.removeSelection();
            this.setHiddenValue();
        };
        ComboBox.prototype.valueMuteChange = function (value) {
            value = this.allowObjectBinding && !ej2_base_2.isNullOrUndefined(value) ? ej2_base_2.getValue((this.fields.value) ? this.fields.value : '', value) : value;
            var inputValue = ej2_base_2.isNullOrUndefined(value) ? null : value.toString();
            ej2_inputs_1.Input.setValue(inputValue, this.inputElement, this.floatLabelType, this.showClearButton);
            Iif (this.allowObjectBinding) {
                value = this.getDataByValue(value);
            }
            this.setProperties({ value: value, text: value, index: null }, true);
            this.activeIndex = this.index;
            var fields = this.fields;
            var dataItem = {};
            dataItem[fields.text] = ej2_base_2.isNullOrUndefined(value) ? null : value.toString();
            dataItem[fields.value] = ej2_base_2.isNullOrUndefined(value) ? null : value.toString();
            this.itemData = dataItem;
            this.item = null;
            if ((!this.allowObjectBinding && (this.previousValue !== this.value)) || (this.allowObjectBinding && this.previousValue && this.value && !this.isObjectInArray(this.previousValue, [this.value]))) {
                this.detachChangeEvent(null);
            }
        };
        ComboBox.prototype.updateValues = function () {
            if (this.fields.disabled) {
                if (this.value != null) {
                    this.value = !this.isDisableItemValue(this.value) ? this.value : null;
                }
                if (this.text != null) {
                    this.text = !this.isDisabledItemByIndex(this.getIndexByValue(this.getValueByText(this.text))) ? this.text : null;
                }
                if (this.index != null) {
                    this.index = !this.isDisabledItemByIndex(this.index) ? this.index : null;
                    this.activeIndex = this.index;
                }
            }
            if (!ej2_base_2.isNullOrUndefined(this.value)) {
                var currentValue = this.allowObjectBinding && !ej2_base_2.isNullOrUndefined(this.value) ? ej2_base_2.getValue((this.fields.value) ? this.fields.value : '', this.value) : this.value;
                var li = this.getElementByValue(currentValue);
                var doesItemExist = !ej2_base_2.isNullOrUndefined(li) ? true : false;
                if (this.enableVirtualization && this.value) {
                    var fields = (this.fields.value) ? this.fields.value : '';
                    var currentValue_1 = this.allowObjectBinding && !ej2_base_2.isNullOrUndefined(this.value) ? ej2_base_2.getValue((this.fields.value) ? this.fields.value : '', this.value) : this.value;
                    if (this.dataSource instanceof ej2_data_1.DataManager) {
                        var getItem = new ej2_data_1.DataManager(this.virtualGroupDataSource).executeLocal(new ej2_data_1.Query().where(new ej2_data_1.Predicate(fields, 'equal', currentValue_1)));
                        Iif (getItem && getItem.length > 0) {
                            this.itemData = getItem[0];
                            doesItemExist = true;
                            var dataItem = this.getItemData();
                            var value = this.allowObjectBinding ? this.getDataByValue(dataItem.value) : dataItem.value;
                            if ((this.value === dataItem.value && this.text !== dataItem.text) || (this.value !== dataItem.value && this.text === dataItem.text)) {
                                this.setProperties({ 'text': dataItem.text, 'value': value });
                            }
                        }
                    }
                    else {
                        var getItem = new ej2_data_1.DataManager(this.dataSource).executeLocal(new ej2_data_1.Query().where(new ej2_data_1.Predicate(fields, 'equal', currentValue_1)));
                        Eif (getItem && getItem.length > 0) {
                            this.itemData = getItem[0];
                            doesItemExist = true;
                            var dataItem = this.getItemData();
                            var value = this.allowObjectBinding ? this.getDataByValue(dataItem.value) : dataItem.value;
                            if ((this.value === dataItem.value && this.text !== dataItem.text) || (this.value !== dataItem.value && this.text === dataItem.text)) {
                                this.setProperties({ 'text': dataItem.text, 'value': value });
                            }
                        }
                    }
                }
                if (li) {
                    this.setSelection(li, null);
                }
                else if ((!this.enableVirtualization && this.allowCustom) || (this.allowCustom && this.enableVirtualization && !doesItemExist)) {
                    this.valueMuteChange(this.value);
                }
                else Eif (!this.enableVirtualization || (this.enableVirtualization && !doesItemExist)) {
                    this.valueMuteChange(null);
                }
            }
            else if (this.text && ej2_base_2.isNullOrUndefined(this.value)) {
                var li = this.getElementByText(this.text);
                if (li) {
                    this.setSelection(li, null);
                }
                else {
                    ej2_inputs_1.Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
                    this.customValue();
                }
            }
            else {
                this.setSelection(this.liCollections[this.activeIndex], null);
            }
            this.setHiddenValue();
            ej2_inputs_1.Input.setValue(this.text, this.inputElement, this.floatLabelType, this.showClearButton);
        };
        ComboBox.prototype.updateIconState = function () {
            Eif (this.showClearButton) {
                if (this.inputElement && this.inputElement.value !== '' && !this.readonly) {
                    ej2_base_1.removeClass([this.inputWrapper.clearButton], drop_down_list_1.dropDownListClasses.clearIconHide);
                }
                else {
                    ej2_base_1.addClass([this.inputWrapper.clearButton], drop_down_list_1.dropDownListClasses.clearIconHide);
                }
            }
        };
        ComboBox.prototype.getAriaAttributes = function () {
            var ariaAttributes = {
                'role': 'combobox',
                'aria-autocomplete': 'both',
                'aria-labelledby': this.hiddenElement.id,
                'aria-expanded': 'false',
                'aria-readonly': this.readonly.toString(),
                'autocomplete': 'off',
                'autocapitalize': 'off',
                'spellcheck': 'false'
            };
            return ariaAttributes;
        };
        ComboBox.prototype.searchLists = function (e) {
            this.isTyped = true;
            if (this.isFiltering()) {
                _super.prototype.searchLists.call(this, e);
                if (this.ulElement && this.filterInput.value.trim() === '') {
                    this.setHoverList(this.ulElement.querySelector('.' + drop_down_list_1.dropDownListClasses.li));
                }
            }
            else {
                if (this.ulElement && this.inputElement.value === '' && this.preventAutoFill) {
                    this.setHoverList(this.ulElement.querySelector('.' + drop_down_list_1.dropDownListClasses.li));
                }
                this.incrementalSearch(e);
            }
        };
        ComboBox.prototype.getNgDirective = function () {
            return 'EJS-COMBOBOX';
        };
        ComboBox.prototype.setSearchBox = function () {
            this.filterInput = this.inputElement;
            var searchBoxContainer = (this.isFiltering() || (this.isReact && this.getModuleName() === 'combobox')) ? this.inputWrapper : inputObject;
            return searchBoxContainer;
        };
        ComboBox.prototype.onActionComplete = function (ulElement, list, e, isUpdated) {
            var _this = this;
            _super.prototype.onActionComplete.call(this, ulElement, list, e);
            if (this.isSelectCustom) {
                this.removeSelection();
            }
            if (!this.preventAutoFill && this.getModuleName() === 'combobox' && this.isTyped && !this.enableVirtualization) {
                setTimeout(function () {
                    _this.inlineSearch();
                });
            }
        };
        ComboBox.prototype.getFocusElement = function () {
            var dataItem = this.isSelectCustom ? { text: '' } : this.getItemData();
            var selected = !ej2_base_2.isNullOrUndefined(this.list) ? this.list.querySelector('.' + drop_down_list_1.dropDownListClasses.selected) : this.list;
            var isSelected = dataItem.text && dataItem.text.toString() === this.inputElement.value && !ej2_base_2.isNullOrUndefined(selected);
            if (isSelected) {
                return selected;
            }
            if ((ej2_base_1.Browser.isDevice && !this.isDropDownClick || !ej2_base_1.Browser.isDevice) &&
                !ej2_base_2.isNullOrUndefined(this.liCollections) && this.liCollections.length > 0) {
                var inputValue = this.inputElement.value;
                var dataSource = this.sortedData;
                var type = this.typeOfData(dataSource).typeof;
                var activeItem = incremental_search_1.Search(inputValue, this.liCollections, this.filterType, true, dataSource, this.fields, type);
                if (this.enableVirtualization && inputValue !== '' && this.getModuleName() !== 'autocomplete' && this.isTyped && !this.allowFiltering) {
                    var updatingincrementalindex = false;
                    if ((this.viewPortInfo.endIndex >= this.incrementalEndIndex && this.incrementalEndIndex <= this.totalItemCount) || this.incrementalEndIndex == 0) {
                        updatingincrementalindex = true;
                        this.incrementalStartIndex = this.incrementalEndIndex;
                        Eif (this.incrementalEndIndex == 0) {
                            this.incrementalEndIndex = 100 > this.totalItemCount ? this.totalItemCount : 100;
                        }
                        else {
                            this.incrementalEndIndex = this.incrementalEndIndex + 100 > this.totalItemCount ? this.totalItemCount : this.incrementalEndIndex + 100;
                        }
                        this.updateIncrementalInfo(this.incrementalStartIndex, this.incrementalEndIndex);
                        updatingincrementalindex = true;
                    }
                    Eif (this.viewPortInfo.startIndex !== 0 || updatingincrementalindex) {
                        this.updateIncrementalView(0, this.itemCount);
                    }
                    activeItem = incremental_search_1.Search(inputValue, this.incrementalLiCollections, this.filterType, true, dataSource, this.fields, type);
                    while (ej2_base_2.isNullOrUndefined(activeItem.item) && this.incrementalEndIndex < this.totalItemCount) {
                        this.incrementalStartIndex = this.incrementalEndIndex;
                        this.incrementalEndIndex = this.incrementalEndIndex + 100 > this.totalItemCount ? this.totalItemCount : this.incrementalEndIndex + 100;
                        this.updateIncrementalInfo(this.incrementalStartIndex, this.incrementalEndIndex);
                        updatingincrementalindex = true;
                        Eif (this.viewPortInfo.startIndex !== 0 || updatingincrementalindex) {
                            this.updateIncrementalView(0, this.itemCount);
                        }
                        activeItem = incremental_search_1.Search(inputValue, this.incrementalLiCollections, this.filterType, true, dataSource, this.fields, type);
                        Eif (!ej2_base_2.isNullOrUndefined(activeItem)) {
                            activeItem.index = activeItem.index + this.incrementalStartIndex;
                            break;
                        }
                        if (ej2_base_2.isNullOrUndefined(activeItem) && this.incrementalEndIndex >= this.totalItemCount) {
                            this.incrementalStartIndex = 0;
                            this.incrementalEndIndex = 100 > this.totalItemCount ? this.totalItemCount : 100;
                            break;
                        }
                    }
                    if (activeItem.index) {
                        Eif ((!(this.viewPortInfo.startIndex >= activeItem.index)) || (!(activeItem.index >= this.viewPortInfo.endIndex))) {
                            var startIndex = activeItem.index - ((this.itemCount / 2) - 2) > 0 ? activeItem.index - ((this.itemCount / 2) - 2) : 0;
                            var endIndex = this.viewPortInfo.startIndex + this.itemCount > this.totalItemCount ? this.totalItemCount : this.viewPortInfo.startIndex + this.itemCount;
                            Eif (startIndex != this.viewPortInfo.startIndex) {
                                this.updateIncrementalView(startIndex, endIndex);
                            }
                        }
                    }
                    if (!ej2_base_2.isNullOrUndefined(activeItem.item)) {
                        var index_1 = this.getIndexByValue(activeItem.item.getAttribute('data-value')) - this.skeletonCount;
                        Iif (index_1 > this.itemCount / 2) {
                            var startIndex = this.viewPortInfo.startIndex + ((this.itemCount / 2) - 2) < this.totalItemCount ? this.viewPortInfo.startIndex + ((this.itemCount / 2) - 2) : this.totalItemCount;
                            var endIndex = this.viewPortInfo.startIndex + this.itemCount > this.totalItemCount ? this.totalItemCount : this.viewPortInfo.startIndex + this.itemCount;
                            this.updateIncrementalView(startIndex, endIndex);
                        }
                        activeItem.item = this.getElementByValue(activeItem.item.getAttribute('data-value'));
                    }
                    else {
                        this.updateIncrementalView(0, this.itemCount);
                        this.list.getElementsByClassName('e-virtual-ddl-content')[0].style = this.getTransformValues();
                        this.list.scrollTop = 0;
                    }
                    if (activeItem && activeItem.item) {
                        activeItem.item = this.getElementByValue(activeItem.item.getAttribute('data-value'));
                    }
                }
                var activeElement = activeItem.item;
                if (!ej2_base_2.isNullOrUndefined(activeElement)) {
                    var count = this.getIndexByValue(activeElement.getAttribute('data-value')) - 1;
                    var height = parseInt(getComputedStyle(this.liCollections[0], null).getPropertyValue('height'), 10);
                    if (!isNaN(height) && this.getModuleName() !== 'autocomplete') {
                        this.removeFocus();
                        var fixedHead = this.fields.groupBy ? this.liCollections[0].offsetHeight : 0;
                        if (!this.enableVirtualization) {
                            this.list.scrollTop = count * height + fixedHead;
                        }
                        else {
                            this.list.getElementsByClassName('e-virtual-ddl-content')[0].style = this.getTransformValues();
                            Eif (this.enableVirtualization && !this.fields.groupBy) {
                                var selectedLiOffsetTop = this.virtualListInfo && this.virtualListInfo.startIndex ? activeElement.offsetTop + (this.virtualListInfo.startIndex * activeElement.offsetHeight) : activeElement.offsetTop;
                                this.list.scrollTop = selectedLiOffsetTop - (this.list.querySelectorAll('.e-virtual-list').length * activeElement.offsetHeight);
                            }
                        }
                        ej2_base_1.addClass([activeElement], drop_down_list_1.dropDownListClasses.focus);
                    }
                }
                else {
                    if (this.isSelectCustom && this.inputElement.value.trim() !== '') {
                        this.removeFocus();
                        Eif (!this.enableVirtualization) {
                            this.list.scrollTop = 0;
                        }
                    }
                }
                return activeElement;
            }
            else {
                return null;
            }
        };
        ComboBox.prototype.setValue = function (e) {
            if ((e && e.type === 'keydown' && e.action === 'enter') || (e && e.type === 'click')) {
                this.removeFillSelection();
            }
            if (this.autofill && this.getModuleName() === 'combobox' && e && e.type === 'keydown' && e.action !== 'enter') {
                this.preventAutoFill = false;
                this.inlineSearch(e);
                return false;
            }
            else {
                return _super.prototype.setValue.call(this, e);
            }
        };
        ComboBox.prototype.checkCustomValue = function () {
            var value = this.allowObjectBinding && !ej2_base_2.isNullOrUndefined(this.value) ? ej2_base_2.getValue((this.fields.value) ? this.fields.value : '', this.value) : this.value;
            this.itemData = this.getDataByValue(value);
            var dataItem = this.getItemData();
            var setValue = this.allowObjectBinding ? this.itemData : dataItem.value;
            if (!(this.allowCustom && ej2_base_2.isNullOrUndefined(dataItem.value) && ej2_base_2.isNullOrUndefined(dataItem.text))) {
                this.setProperties({ 'value': setValue }, !this.allowCustom);
            }
        };
        ComboBox.prototype.showSpinner = function () {
            if (ej2_base_2.isNullOrUndefined(this.spinnerElement)) {
                this.spinnerElement = (this.getModuleName() === 'autocomplete') ? (this.inputWrapper.buttons[0] ||
                    this.inputWrapper.clearButton ||
                    ej2_inputs_1.Input.appendSpan('e-input-group-icon ' + SPINNER_CLASS, this.inputWrapper.container, this.createElement)) :
                    (this.inputWrapper.buttons[0] || this.inputWrapper.clearButton);
                ej2_base_1.addClass([this.spinnerElement], drop_down_list_1.dropDownListClasses.disableIcon);
                ej2_popups_1.createSpinner({
                    target: this.spinnerElement,
                    width: ej2_base_1.Browser.isDevice ? '16px' : '14px'
                }, this.createElement);
                ej2_popups_1.showSpinner(this.spinnerElement);
            }
        };
        ComboBox.prototype.hideSpinner = function () {
            if (!ej2_base_2.isNullOrUndefined(this.spinnerElement)) {
                ej2_popups_1.hideSpinner(this.spinnerElement);
                ej2_base_1.removeClass([this.spinnerElement], drop_down_list_1.dropDownListClasses.disableIcon);
                if (this.spinnerElement.classList.contains(SPINNER_CLASS)) {
                    ej2_base_1.detach(this.spinnerElement);
                }
                else {
                    this.spinnerElement.innerHTML = '';
                }
                this.spinnerElement = null;
            }
        };
        ComboBox.prototype.setAutoFill = function (activeElement, isHover) {
            if (!isHover) {
                this.setHoverList(activeElement);
            }
            if (this.autofill && !this.preventAutoFill) {
                var currentValue = this.getTextByValue(activeElement.getAttribute('data-value')).toString();
                var currentFillValue = this.getFormattedValue(activeElement.getAttribute('data-value'));
                if (this.getModuleName() === 'combobox') {
                    if (!this.isSelected && ((!this.allowObjectBinding && this.previousValue !== currentFillValue)) || (this.allowObjectBinding && this.previousValue && currentFillValue && !this.isObjectInArray(this.previousValue, [this.getDataByValue(currentFillValue)]))) {
                        this.updateSelectedItem(activeElement, null);
                        this.isSelected = true;
                        this.previousValue = this.allowObjectBinding ? this.getDataByValue(this.getFormattedValue(activeElement.getAttribute('data-value'))) : this.getFormattedValue(activeElement.getAttribute('data-value'));
                    }
                    else {
                        this.updateSelectedItem(activeElement, null, true);
                    }
                }
                if (!this.isAndroidAutoFill(currentValue)) {
                    this.setAutoFillSelection(currentValue, isHover);
                }
            }
        };
        ComboBox.prototype.isAndroidAutoFill = function (value) {
            if (ej2_base_1.Browser.isAndroid) {
                var currentPoints = this.getSelectionPoints();
                var prevEnd = this.prevSelectPoints.end;
                var curEnd = currentPoints.end;
                var prevStart = this.prevSelectPoints.start;
                var curStart = currentPoints.start;
                if (prevEnd !== 0 && ((prevEnd === value.length && prevStart === value.length) ||
                    (prevStart > curStart && prevEnd > curEnd) || (prevEnd === curEnd && prevStart === curStart))) {
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                return false;
            }
        };
        ComboBox.prototype.clearAll = function (e, property) {
            if (ej2_base_2.isNullOrUndefined(property) || (!ej2_base_2.isNullOrUndefined(property) && ej2_base_2.isNullOrUndefined(property.dataSource))) {
                _super.prototype.clearAll.call(this, e);
            }
            if (this.isFiltering() && !ej2_base_2.isNullOrUndefined(e) && e.target === this.inputWrapper.clearButton) {
                this.searchLists(e);
            }
        };
        ComboBox.prototype.isSelectFocusItem = function (element) {
            return !ej2_base_2.isNullOrUndefined(element);
        };
        ComboBox.prototype.inlineSearch = function (e) {
            var isKeyNavigate = (e && (e.action === 'down' || e.action === 'up' ||
                e.action === 'home' || e.action === 'end' || e.action === 'pageUp' || e.action === 'pageDown'));
            var activeElement = isKeyNavigate ? this.liCollections[this.activeIndex] : this.getFocusElement();
            if (!ej2_base_2.isNullOrUndefined(activeElement)) {
                if (!isKeyNavigate) {
                    var value = this.getFormattedValue(activeElement.getAttribute('data-value'));
                    this.activeIndex = this.getIndexByValue(value);
                    this.activeIndex = !ej2_base_2.isNullOrUndefined(this.activeIndex) ? this.activeIndex : null;
                }
                this.preventAutoFill = this.inputElement.value === '' ? false : this.preventAutoFill;
                this.setAutoFill(activeElement, isKeyNavigate);
            }
            else if (!ej2_base_2.isNullOrUndefined(this.inputElement) && this.inputElement.value === '') {
                this.activeIndex = null;
                Eif (!ej2_base_2.isNullOrUndefined(this.list)) {
                    Eif (!this.enableVirtualization) {
                        this.list.scrollTop = 0;
                    }
                    var focusItem = this.list.querySelector('.' + drop_down_list_1.dropDownListClasses.li);
                    this.setHoverList(focusItem);
                }
            }
            else {
                this.activeIndex = null;
                this.removeSelection();
                if (this.liCollections && this.liCollections.length > 0 && !this.isCustomFilter) {
                    this.removeFocus();
                }
            }
        };
        ComboBox.prototype.incrementalSearch = function (e) {
            this.showPopup(e);
            Eif (!ej2_base_2.isNullOrUndefined(this.listData)) {
                this.inlineSearch(e);
                e.preventDefault();
            }
        };
        ComboBox.prototype.setAutoFillSelection = function (currentValue, isKeyNavigate) {
            if (isKeyNavigate === void 0) { isKeyNavigate = false; }
            var selection = this.getSelectionPoints();
            var value = this.inputElement.value.substr(0, selection.start);
            if (value && (value.toLowerCase() === currentValue.substr(0, selection.start).toLowerCase())) {
                var inputValue = value + currentValue.substr(value.length, currentValue.length);
                ej2_inputs_1.Input.setValue(inputValue, this.inputElement, this.floatLabelType, this.showClearButton);
                this.inputElement.setSelectionRange(selection.start, this.inputElement.value.length);
            }
            else if (isKeyNavigate) {
                ej2_inputs_1.Input.setValue(currentValue, this.inputElement, this.floatLabelType, this.showClearButton);
                this.inputElement.setSelectionRange(0, this.inputElement.value.length);
            }
        };
        ComboBox.prototype.getValueByText = function (text) {
            return _super.prototype.getValueByText.call(this, text, true, this.ignoreAccent);
        };
        ComboBox.prototype.unWireEvent = function () {
            if (this.getModuleName() === 'combobox') {
                ej2_base_1.EventHandler.remove(this.inputWrapper.buttons[0], 'mousedown', this.preventBlur);
                ej2_base_1.EventHandler.remove(this.inputWrapper.container, 'blur', this.onBlurHandler);
            }
            if (!ej2_base_2.isNullOrUndefined(this.inputWrapper.buttons[0])) {
                ej2_base_1.EventHandler.remove(this.inputWrapper.buttons[0], 'mousedown', this.dropDownClick);
            }
            if (this.inputElement) {
                ej2_base_1.EventHandler.remove(this.inputElement, 'focus', this.targetFocus);
                if (!this.readonly) {
                    ej2_base_1.EventHandler.remove(this.inputElement, 'input', this.onInput);
                    ej2_base_1.EventHandler.remove(this.inputElement, 'keyup', this.onFilterUp);
                    ej2_base_1.EventHandler.remove(this.inputElement, 'keydown', this.onFilterDown);
                    ej2_base_1.EventHandler.remove(this.inputElement, 'paste', this.pasteHandler);
                    ej2_base_1.EventHandler.remove(window, 'resize', this.windowResize);
                }
            }
            this.unBindCommonEvent();
        };
        ComboBox.prototype.setSelection = function (li, e) {
            _super.prototype.setSelection.call(this, li, e);
            if (!ej2_base_2.isNullOrUndefined(li) && !this.autofill && !this.isDropDownClick) {
                this.removeFocus();
            }
        };
        ComboBox.prototype.selectCurrentItem = function (e) {
            var li;
            if (this.isPopupOpen) {
                if (this.isSelected) {
                    li = this.list.querySelector('.' + drop_down_list_1.dropDownListClasses.selected);
                }
                else {
                    li = this.list.querySelector('.' + drop_down_list_1.dropDownListClasses.focus);
                }
                Iif (this.isDisabledElement(li)) {
                    return;
                }
                if (li) {
                    this.setSelection(li, e);
                    this.isTyped = false;
                }
                Iif (this.isSelected) {
                    this.isSelectCustom = false;
                    this.onChangeEvent(e);
                }
            }
            if (e.action === 'enter' && this.inputElement.value.trim() === '') {
                this.clearAll(e);
            }
            else if (this.isTyped && !this.isSelected && ej2_base_2.isNullOrUndefined(li)) {
                this.customValue(e);
            }
            this.hidePopup(e);
        };
        ComboBox.prototype.setHoverList = function (li) {
            this.removeSelection();
            if (this.isValidLI(li) && !li.classList.contains(drop_down_list_1.dropDownListClasses.selected)) {
                this.removeFocus();
                li.classList.add(drop_down_list_1.dropDownListClasses.focus);
            }
        };
        ComboBox.prototype.targetFocus = function (e) {
            if (ej2_base_1.Browser.isDevice && !this.allowFiltering) {
                this.preventFocus = false;
            }
            this.onFocus(e);
            ej2_inputs_1.Input.calculateWidth(this.inputElement, this.inputWrapper.container);
        };
        ComboBox.prototype.dropDownClick = function (e) {
            e.preventDefault();
            if (ej2_base_1.Browser.isDevice && !this.isFiltering()) {
                this.preventFocus = true;
            }
            _super.prototype.dropDownClick.call(this, e);
        };
        ComboBox.prototype.customValue = function (e) {
            var _this = this;
            var value = this.getValueByText(this.inputElement.value);
            if (!this.allowCustom && this.inputElement.value !== '') {
                var previousValue = this.previousValue;
                var currentValue = this.value;
                value = this.allowObjectBinding ? this.getDataByValue(value) : value;
                this.setProperties({ value: value });
                if (ej2_base_2.isNullOrUndefined(this.value)) {
                    ej2_inputs_1.Input.setValue('', this.inputElement, this.floatLabelType, this.showClearButton);
                }
                var newValue = this.allowObjectBinding && !ej2_base_2.isNullOrUndefined(this.value) ? ej2_base_2.getValue((this.fields.value) ? this.fields.value : '', this.value) : this.value;
                if (this.autofill && ((!this.allowObjectBinding && previousValue === this.value) || (this.allowObjectBinding && previousValue && this.isObjectInArray(previousValue, [this.value]))) && ((!this.allowObjectBinding && currentValue !== this.value) || (this.allowObjectBinding && currentValue && !this.isObjectInArray(currentValue, [this.value])))) {
                    this.onChangeEvent(null);
                }
            }
            else if (this.inputElement.value.trim() !== '') {
                var previousValue_1 = this.value;
                if (ej2_base_2.isNullOrUndefined(value)) {
                    var value_1 = this.inputElement.value === '' ? null : this.inputElement.value;
                    var eventArgs = { text: value_1, item: {} };
                    this.isObjectCustomValue = true;
                    if (!this.initial) {
                        this.trigger('customValueSpecifier', eventArgs, function (eventArgs) {
                            _this.updateCustomValueCallback(value_1, eventArgs, previousValue_1, e);
                        });
                    }
                    else {
                        this.updateCustomValueCallback(value_1, eventArgs, previousValue_1);
                    }
                }
                else {
                    this.isSelectCustom = false;
                    value = this.allowObjectBinding ? this.getDataByValue(value) : value;
                    this.setProperties({ value: value });
                    if ((!this.allowObjectBinding && previousValue_1 !== this.value) || (this.allowObjectBinding && previousValue_1 && this.value && !this.isObjectInArray(previousValue_1, [this.value]))) {
                        this.onChangeEvent(e);
                    }
                }
            }
            else if (this.allowCustom) {
                this.isSelectCustom = true;
            }
        };
        ComboBox.prototype.updateCustomValueCallback = function (value, eventArgs, previousValue, e) {
            var _this = this;
            var fields = this.fields;
            var item = eventArgs.item;
            var dataItem = {};
            if (item && ej2_base_2.getValue(fields.text, item) && ej2_base_2.getValue(fields.value, item)) {
                dataItem = item;
            }
            else {
                ej2_base_2.setValue(fields.text, value, dataItem);
                ej2_base_2.setValue(fields.value, value, dataItem);
            }
            this.itemData = dataItem;
            var emptyObject = {};
            if (this.allowObjectBinding) {
                var keys = this.listData && this.listData.length > 0 ? Object.keys(this.listData[0]) : Object.keys(this.itemData);
                if ((!(this.listData && this.listData.length > 0)) && (this.getModuleName() === 'autocomplete' || (this.getModuleName() === 'combobox' && this.allowFiltering))) {
                    keys = this.firstItem ? Object.keys(this.firstItem) : Object.keys(this.itemData);
                }
                keys.forEach(function (key) {
                    emptyObject[key] = ((key === fields.value) || (key === fields.text)) ? ej2_base_2.getValue(fields.value, _this.itemData) : null;
                });
            }
            var changeData = {
                text: ej2_base_2.getValue(fields.text, this.itemData),
                value: this.allowObjectBinding ? emptyObject : ej2_base_2.getValue(fields.value, this.itemData),
                index: null
            };
            this.setProperties(changeData, true);
            this.setSelection(null, null);
            this.isSelectCustom = true;
            this.isObjectCustomValue = false;
            if ((!this.allowObjectBinding && (previousValue !== this.value)) || (this.allowObjectBinding && ((previousValue == null && this.value !== null) || (previousValue && !this.isObjectInArray(previousValue, [this.value]))))) {
                this.onChangeEvent(e, true);
            }
        };
        ComboBox.prototype.onPropertyChanged = function (newProp, oldProp) {
            if (this.getModuleName() === 'combobox') {
                this.checkData(newProp);
                this.setUpdateInitial(['fields', 'query', 'dataSource'], newProp, oldProp);
            }
            for (var _i = 0, _a = Object.keys(newProp); _i < _a.length; _i++) {
                var prop = _a[_i];
                switch (prop) {
                    case 'readonly':
                        ej2_inputs_1.Input.setReadonly(this.readonly, this.inputElement);
                        if (this.readonly) {
                            ej2_base_1.EventHandler.remove(this.inputElement, 'input', this.onInput);
                            ej2_base_1.EventHandler.remove(this.inputElement, 'keyup', this.onFilterUp);
                            ej2_base_1.EventHandler.remove(this.inputElement, 'keydown', this.onFilterDown);
                        }
                        else {
                            ej2_base_1.EventHandler.add(this.inputElement, 'input', this.onInput, this);
                            ej2_base_1.EventHandler.add(this.inputElement, 'keyup', this.onFilterUp, this);
                            ej2_base_1.EventHandler.add(this.inputElement, 'keydown', this.onFilterDown, this);
                        }
                        this.setReadOnly();
                        break;
                    case 'allowFiltering':
                        this.setSearchBox();
                        if (this.isFiltering() && this.getModuleName() === 'combobox' && ej2_base_2.isNullOrUndefined(this.list)) {
                            _super.prototype.renderList.call(this);
                        }
                        break;
                    case 'allowCustom':
                        break;
                    default: {
                        var comboProps = this.getPropObject(prop, newProp, oldProp);
                        _super.prototype.onPropertyChanged.call(this, comboProps.newProperty, comboProps.oldProperty);
                        if (this.isFiltering() && prop === 'dataSource' && ej2_base_2.isNullOrUndefined(this.list) && this.itemTemplate &&
                            this.getModuleName() === 'combobox') {
                            _super.prototype.renderList.call(this);
                        }
                        break;
                    }
                }
            }
        };
        ComboBox.prototype.render = function () {
            _super.prototype.render.call(this);
            this.setSearchBox();
            this.renderComplete();
        };
        ComboBox.prototype.getModuleName = function () {
            return 'combobox';
        };
        ComboBox.prototype.addItem = function (items, itemIndex) {
            _super.prototype.addItem.call(this, items, itemIndex);
        };
        ComboBox.prototype.filter = function (dataSource, query, fields) {
            _super.prototype.filter.call(this, dataSource, query, fields);
        };
        ComboBox.prototype.showPopup = function (e) {
            _super.prototype.showPopup.call(this, e);
        };
        ComboBox.prototype.hidePopup = function (e) {
            var inputValue = this.inputElement && this.inputElement.value === '' ? null
                : this.inputElement && this.inputElement.value;
            if (!ej2_base_2.isNullOrUndefined(this.listData)) {
                var isEscape = this.isEscapeKey;
                if (this.isEscapeKey) {
                    ej2_inputs_1.Input.setValue(this.typedString, this.inputElement, this.floatLabelType, this.showClearButton);
                    this.isEscapeKey = false;
                }
                if (this.autofill) {
                    this.removeFillSelection();
                }
                var dataItem = this.isSelectCustom ? { text: '' } : this.getItemData();
                var selected = !ej2_base_2.isNullOrUndefined(this.list) ? this.list.querySelector('.' + drop_down_list_1.dropDownListClasses.selected) : null;
                if (this.inputElement && dataItem.text === this.inputElement.value && !ej2_base_2.isNullOrUndefined(selected)) {
                    if (this.isSelected) {
                        this.onChangeEvent(e);
                        this.isSelectCustom = false;
                    }
                    _super.prototype.hidePopup.call(this, e);
                    return;
                }
                if (this.getModuleName() === 'combobox' && this.inputElement.value.trim() !== '') {
                    var dataSource = this.sortedData;
                    var type = this.typeOfData(dataSource).typeof;
                    var searchItem = incremental_search_1.Search(this.inputElement.value, this.liCollections, 'Equal', true, dataSource, this.fields, type);
                    this.selectedLI = searchItem.item;
                    if (ej2_base_2.isNullOrUndefined(searchItem.index)) {
                        searchItem.index = incremental_search_1.Search(this.inputElement.value, this.liCollections, 'StartsWith', true, dataSource, this.fields, type).index;
                    }
                    this.activeIndex = searchItem.index;
                    if (!ej2_base_2.isNullOrUndefined(this.selectedLI)) {
                        this.updateSelectedItem(this.selectedLI, null, true);
                    }
                    else if (isEscape) {
                        this.isSelectCustom = true;
                        this.removeSelection();
                    }
                }
                if (!this.isEscapeKey && this.isTyped && !this.isInteracted) {
                    this.customValue(e);
                }
            }
            var value = this.allowObjectBinding && !ej2_base_2.isNullOrUndefined(this.value) ? ej2_base_2.getValue((this.fields.value) ? this.fields.value : '', this.value) : this.value;
            if (ej2_base_2.isNullOrUndefined(this.listData) && this.allowCustom && !ej2_base_2.isNullOrUndefined(inputValue) && inputValue !== value) {
                this.customValue();
            }
            _super.prototype.hidePopup.call(this, e);
        };
        ComboBox.prototype.focusIn = function () {
            if (!this.enabled) {
                return;
            }
            if (ej2_base_1.Browser.isDevice && !this.isFiltering()) {
                this.preventFocus = true;
            }
            _super.prototype.focusIn.call(this);
        };
        ComboBox.prototype.clear = function () {
            this.value = null;
        };
        ComboBox.prototype.focusOut = function (e) {
            _super.prototype.focusOut.call(this, e);
        };
        ComboBox.prototype.getItems = function () {
            return _super.prototype.getItems.call(this);
        };
        ComboBox.prototype.getDataByValue = function (value) {
            return _super.prototype.getDataByValue.call(this, value);
        };
        ComboBox.prototype.renderHightSearch = function () {
        };
        __decorate([
            ej2_base_1.Property(false)
        ], ComboBox.prototype, "autofill", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], ComboBox.prototype, "allowCustom", void 0);
        __decorate([
            ej2_base_1.Property({})
        ], ComboBox.prototype, "htmlAttributes", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], ComboBox.prototype, "allowFiltering", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "query", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "index", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], ComboBox.prototype, "showClearButton", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], ComboBox.prototype, "enableRtl", void 0);
        __decorate([
            ej2_base_1.Event()
        ], ComboBox.prototype, "customValueSpecifier", void 0);
        __decorate([
            ej2_base_1.Event()
        ], ComboBox.prototype, "filtering", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "valueTemplate", void 0);
        __decorate([
            ej2_base_1.Property('Never')
        ], ComboBox.prototype, "floatLabelType", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "filterBarPlaceholder", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "cssClass", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "headerTemplate", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "footerTemplate", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "placeholder", void 0);
        __decorate([
            ej2_base_1.Property('100%')
        ], ComboBox.prototype, "width", void 0);
        __decorate([
            ej2_base_1.Property('300px')
        ], ComboBox.prototype, "popupHeight", void 0);
        __decorate([
            ej2_base_1.Property('100%')
        ], ComboBox.prototype, "popupWidth", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], ComboBox.prototype, "readonly", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "text", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], ComboBox.prototype, "value", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], ComboBox.prototype, "allowObjectBinding", void 0);
        ComboBox = __decorate([
            ej2_base_2.NotifyPropertyChanges
        ], ComboBox);
        return ComboBox;
    }(drop_down_list_1.DropDownList));
    exports.ComboBox = ComboBox;
});