all files / textbox/ textbox.js

98.26% Statements 396/403
90.97% Branches 282/310
100% Functions 40/40
98.24% Lines 390/397
22 statements, 7 functions, 40 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                                                  195× 195× 195× 195× 195× 195× 195× 195× 195×                   145× 146× 146×   39× 39× 39×         57× 57× 57× 24×   57× 57× 57× 24×   57×   57×   57×   57×     57×     13× 13× 13× 13×   13×                                             482×   57×   199× 199× 199×     199×             199× 199× 199× 148×   199× 199× 199× 199× 199× 66×   199×   199× 193×   199× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 192× 192×     12× 12×           212×   212× 1221× 1221× 95×   11×     11×   12×     12×   19× 16×   19×   16× 10× 10×   16×   13× 10×   13×   13× 11×   13×                     199× 199× 11×   199× 199×                       199× 199× 60×   199× 199× 68× 68× 19×     199× 68× 68×   199× 10×   189×   199× 199× 199× 199× 199×   214× 214× 102× 102× 27× 19× 19× 17×                     213× 213× 97× 97× 72×           36× 36× 34×   36×   68× 68×     199× 199× 199× 199× 199×   199× 199×                                           33×         33×   34×     34×         34×                         66×               66× 66× 66×   206× 12× 10×                             86× 86× 86× 86× 86×   86×                         86× 86× 10× 10× 10×   86× 86× 86× 86× 86× 86×   86× 86×                                                                             93× 354× 354×   353×   352×     351×                                                                                                                                    
/* 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;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    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;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../input/input"], function (require, exports, ej2_base_1, ej2_base_2, ej2_base_3, input_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var HIDE_CLEAR = 'e-clear-icon-hide';
    var TEXTBOX_FOCUS = 'e-input-focus';
    var containerAttr = ['title', 'style', 'class'];
    /**
     * Represents the TextBox component that allows the user to enter the values based on it's type.
     * ```html
     * <input name='images' id='textbox'/>
     * ```
     * ```typescript
     * <script>
     *   var textboxObj = new TextBox();
     *   textboxObj.appendTo('#textbox');
     * </script>
     * ```
     */
    var TextBox = /** @class */ (function (_super) {
        __extends(TextBox, _super);
        /**
         *
         * @param {TextBoxModel} options - Specifies the TextBox model.
         * @param {string | HTMLInputElement | HTMLTextAreaElement} element - Specifies the element to render as component.
         * @private
         */
        function TextBox(options, element) {
            var _this = _super.call(this, options, element) || this;
            _this.previousValue = null;
            _this.isAngular = false;
            _this.isHiddenInput = false;
            _this.isForm = false;
            _this.inputPreviousValue = null;
            _this.isVue = false;
            _this.textboxOptions = options;
            return _this;
        }
        /**
         * Calls internally if any of the property value is changed.
         *
         * @param {TextBoxModel} newProp - Returns the dynamic property value of the component.
         * @param {TextBoxModel} oldProp - Returns the previous property value of the component.
         * @returns {void}
         * @private
         */
        TextBox.prototype.onPropertyChanged = function (newProp, oldProp) {
            for (var _i = 0, _a = Object.keys(newProp); _i < _a.length; _i++) {
                var prop = _a[_i];
                switch (prop) {
                    case 'floatLabelType':
                        input_1.Input.removeFloating(this.textboxWrapper);
                        input_1.Input.addFloating(this.respectiveElement, this.floatLabelType, this.placeholder);
                        break;
                    case 'enabled':
                        input_1.Input.setEnabled(this.enabled, this.respectiveElement, this.floatLabelType, this.textboxWrapper.container);
                        this.bindClearEvent();
                        break;
                    case 'width':
                        input_1.Input.setWidth(newProp.width, this.textboxWrapper.container);
                        break;
                    case 'value':
                        {
                            var prevOnChange = this.isProtectedOnChange;
                            this.isProtectedOnChange = true;
                            if (!this.isBlank(this.value)) {
                                this.value = this.value.toString();
                            }
                            this.isProtectedOnChange = prevOnChange;
                            input_1.Input.setValue(this.value, this.respectiveElement, this.floatLabelType, this.showClearButton);
                            if (this.isHiddenInput) {
                                this.element.value = this.respectiveElement.value;
                            }
                            this.inputPreviousValue = this.respectiveElement.value;
                            /* istanbul ignore next */
                            Iif ((this.isAngular || this.isVue) && this.preventChange === true) {
                                this.previousValue = this.isAngular ? this.value : this.previousValue;
                                this.preventChange = false;
                            }
                            else Eif (ej2_base_1.isNullOrUndefined(this.isAngular) || !this.isAngular
                                || (this.isAngular && !this.preventChange) || (this.isAngular && ej2_base_1.isNullOrUndefined(this.preventChange))) {
                                this.raiseChangeEvent();
                            }
                        }
                        break;
                    case 'htmlAttributes':
                        {
                            this.updateHTMLAttrToElement();
                            this.updateHTMLAttrToWrapper();
                            this.checkAttributes(true);
                            input_1.Input.validateInputType(this.textboxWrapper.container, this.element);
                        }
                        break;
                    case 'readonly':
                        input_1.Input.setReadonly(this.readonly, this.respectiveElement);
                        break;
                    case 'type':
                        if (this.respectiveElement.tagName !== 'TEXTAREA') {
                            this.respectiveElement.setAttribute('type', this.type);
                            input_1.Input.validateInputType(this.textboxWrapper.container, this.element);
                            this.raiseChangeEvent();
                        }
                        break;
                    case 'showClearButton':
                        Eif (this.respectiveElement.tagName !== 'TEXTAREA') {
                            input_1.Input.setClearButton(this.showClearButton, this.respectiveElement, this.textboxWrapper);
                            this.bindClearEvent();
                        }
                        break;
                    case 'enableRtl':
                        input_1.Input.setEnableRtl(this.enableRtl, [this.textboxWrapper.container]);
                        break;
                    case 'placeholder':
                        input_1.Input.setPlaceholder(this.placeholder, this.respectiveElement);
                        break;
                    case 'autocomplete':
                        if (this.autocomplete !== 'on' && this.autocomplete !== '') {
                            this.respectiveElement.autocomplete = this.autocomplete;
                        }
                        else {
                            this.removeAttributes(['autocomplete']);
                        }
                        break;
                    case 'cssClass':
                        this.updateCssClass(newProp.cssClass, oldProp.cssClass);
                        break;
                    case 'locale':
                        this.globalize = new ej2_base_2.Internationalization(this.locale);
                        this.l10n.setLocale(this.locale);
                        this.setProperties({ placeholder: this.l10n.getConstant('placeholder') }, true);
                        input_1.Input.setPlaceholder(this.placeholder, this.respectiveElement);
                        break;
                }
            }
        };
        /**
         * Gets the component name
         *
         * @returns {string} Returns the component name.
         * @private
         */
        TextBox.prototype.getModuleName = function () {
            return 'textbox';
        };
        TextBox.prototype.isBlank = function (str) {
            return (!str || /^\s*$/.test(str));
        };
        TextBox.prototype.preRender = function () {
            this.cloneElement = this.element.cloneNode(true);
            this.formElement = ej2_base_2.closest(this.element, 'form');
            if (!ej2_base_1.isNullOrUndefined(this.formElement)) {
                this.isForm = true;
            }
            /* istanbul ignore next */
            if (this.element.tagName === 'EJS-TEXTBOX') {
                var ejInstance = ej2_base_1.getValue('ej2_instances', this.element);
                var inputElement = this.multiline ?
                    this.createElement('textarea') :
                    this.createElement('input');
                var index = 0;
                for (index; index < this.element.attributes.length; index++) {
                    var attributeName = this.element.attributes[index].nodeName;
                    if (attributeName !== 'id') {
                        inputElement.setAttribute(attributeName, this.element.attributes[index].nodeValue);
                        inputElement.innerHTML = this.element.innerHTML;
                        Eif (attributeName === 'name') {
                            this.element.removeAttribute('name');
                        }
                    }
                }
                this.element.appendChild(inputElement);
                this.element = inputElement;
                ej2_base_1.setValue('ej2_instances', ejInstance, this.element);
            }
            this.updateHTMLAttrToElement();
            this.checkAttributes(false);
            if (this.element.tagName !== 'TEXTAREA') {
                this.element.setAttribute('type', this.type);
            }
            this.element.setAttribute('role', 'textbox');
            this.globalize = new ej2_base_2.Internationalization(this.locale);
            var localeText = { placeholder: this.placeholder };
            this.l10n = new ej2_base_1.L10n('textbox', localeText, this.locale);
            if (this.l10n.getConstant('placeholder') !== '') {
                this.setProperties({ placeholder: this.placeholder || this.l10n.getConstant('placeholder') }, true);
            }
            if (!this.element.hasAttribute('id')) {
                this.element.setAttribute('id', ej2_base_2.getUniqueID('textbox'));
            }
            if (!this.element.hasAttribute('name')) {
                this.element.setAttribute('name', this.element.getAttribute('id'));
            }
            if (this.element.tagName === 'INPUT' && this.multiline) {
                this.isHiddenInput = true;
                this.textarea = this.createElement('textarea');
                this.element.parentNode.insertBefore(this.textarea, this.element);
                this.element.setAttribute('type', 'hidden');
                this.textarea.setAttribute('name', this.element.getAttribute('name'));
                this.element.removeAttribute('name');
                this.textarea.setAttribute('role', this.element.getAttribute('role'));
                this.element.removeAttribute('role');
                this.textarea.setAttribute('id', ej2_base_2.getUniqueID('textarea'));
                var apiAttributes = ['placeholder', 'disabled', 'value', 'readonly', 'type', 'autocomplete'];
                for (var index = 0; index < this.element.attributes.length; index++) {
                    var attributeName = this.element.attributes[index].nodeName;
                    if (this.element.hasAttribute(attributeName) && containerAttr.indexOf(attributeName) < 0 &&
                        !(attributeName === 'id' || attributeName === 'type' || attributeName === 'e-mappinguid')) {
                        // e-mappinguid attribute is handled for Grid component.
                        this.textarea.setAttribute(attributeName, this.element.attributes[index].nodeValue);
                        if (apiAttributes.indexOf(attributeName) < 0) {
                            this.element.removeAttribute(attributeName);
                            index--;
                        }
                    }
                }
            }
        };
        TextBox.prototype.checkAttributes = function (isDynamic) {
            var attrs = isDynamic ? ej2_base_1.isNullOrUndefined(this.htmlAttributes) ? [] : Object.keys(this.htmlAttributes) :
                ['placeholder', 'disabled', 'value', 'readonly', 'type', 'autocomplete'];
            for (var _i = 0, attrs_1 = attrs; _i < attrs_1.length; _i++) {
                var key = attrs_1[_i];
                if (!ej2_base_1.isNullOrUndefined(this.element.getAttribute(key))) {
                    switch (key) {
                        case 'disabled':
                            if ((ej2_base_1.isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['enabled'] === undefined)) || isDynamic) {
                                var enabled = this.element.getAttribute(key) === 'disabled' || this.element.getAttribute(key) === '' ||
                                    this.element.getAttribute(key) === 'true' ? false : true;
                                this.setProperties({ enabled: enabled }, !isDynamic);
                            }
                            break;
                        case 'readonly':
                            if ((ej2_base_1.isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['readonly'] === undefined)) || isDynamic) {
                                var readonly = this.element.getAttribute(key) === 'readonly' || this.element.getAttribute(key) === ''
                                    || this.element.getAttribute(key) === 'true' ? true : false;
                                this.setProperties({ readonly: readonly }, !isDynamic);
                            }
                            break;
                        case 'placeholder':
                            if ((ej2_base_1.isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['placeholder'] === undefined)) || isDynamic) {
                                this.setProperties({ placeholder: this.element.placeholder }, !isDynamic);
                            }
                            break;
                        case 'autocomplete':
                            if ((ej2_base_1.isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['autocomplete'] === undefined)) || isDynamic) {
                                var autoCompleteTxt = this.element.autocomplete === 'off' ? 'off' : 'on';
                                this.setProperties({ autocomplete: autoCompleteTxt }, !isDynamic);
                            }
                            break;
                        case 'value':
                            if ((ej2_base_1.isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['value'] === undefined)) || isDynamic) {
                                this.setProperties({ value: this.element.value }, !isDynamic);
                            }
                            break;
                        case 'type':
                            if ((ej2_base_1.isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['type'] === undefined)) || isDynamic) {
                                this.setProperties({ type: this.element.type }, !isDynamic);
                            }
                            break;
                    }
                }
            }
        };
        /**
         * To Initialize the control rendering
         *
         * @returns {void}
         * @private
         */
        TextBox.prototype.render = function () {
            var updatedCssClassValue = this.cssClass;
            if (!ej2_base_1.isNullOrUndefined(this.cssClass) && this.cssClass !== '') {
                updatedCssClassValue = this.getInputValidClassList(this.cssClass);
            }
            this.respectiveElement = (this.isHiddenInput) ? this.textarea : this.element;
            this.textboxWrapper = input_1.Input.createInput({
                element: this.respectiveElement,
                floatLabelType: this.floatLabelType,
                properties: {
                    enabled: this.enabled,
                    enableRtl: this.enableRtl,
                    cssClass: updatedCssClassValue,
                    readonly: this.readonly,
                    placeholder: this.placeholder,
                    showClearButton: this.showClearButton
                }
            });
            this.updateHTMLAttrToWrapper();
            if (this.isHiddenInput) {
                this.respectiveElement.parentNode.insertBefore(this.element, this.respectiveElement);
            }
            this.wireEvents();
            if (!ej2_base_1.isNullOrUndefined(this.value)) {
                input_1.Input.setValue(this.value, this.respectiveElement, this.floatLabelType, this.showClearButton);
                if (this.isHiddenInput) {
                    this.element.value = this.respectiveElement.value;
                }
            }
            if (!ej2_base_1.isNullOrUndefined(this.value)) {
                this.initialValue = this.value;
                this.setInitialValue();
            }
            if (this.autocomplete !== 'on' && this.autocomplete !== '') {
                this.respectiveElement.autocomplete = this.autocomplete;
            }
            else if (!ej2_base_1.isNullOrUndefined(this.textboxOptions) && (this.textboxOptions['autocomplete'] !== undefined)) {
                this.removeAttributes(['autocomplete']);
            }
            this.previousValue = this.value;
            this.inputPreviousValue = this.value;
            this.respectiveElement.defaultValue = this.respectiveElement.value;
            input_1.Input.setWidth(this.width, this.textboxWrapper.container);
            this.renderComplete();
        };
        TextBox.prototype.updateHTMLAttrToWrapper = function () {
            Eif (!ej2_base_1.isNullOrUndefined(this.htmlAttributes)) {
                for (var _i = 0, _a = Object.keys(this.htmlAttributes); _i < _a.length; _i++) {
                    var key = _a[_i];
                    if (containerAttr.indexOf(key) > -1) {
                        if (key === 'class') {
                            var updatedClassValues = this.getInputValidClassList(this.htmlAttributes[key]);
                            if (updatedClassValues !== '') {
                                ej2_base_3.addClass([this.textboxWrapper.container], updatedClassValues.split(' '));
                            }
                        }
                        else if (key === 'style') {
                            var setStyle = this.textboxWrapper.container.getAttribute(key);
                            setStyle = !ej2_base_1.isNullOrUndefined(setStyle) ? (setStyle + this.htmlAttributes[key]) :
                                this.htmlAttributes[key];
                            this.textboxWrapper.container.setAttribute(key, setStyle);
                        }
                        else {
                            this.textboxWrapper.container.setAttribute(key, this.htmlAttributes[key]);
                        }
                    }
                }
            }
        };
        TextBox.prototype.updateHTMLAttrToElement = function () {
            Eif (!ej2_base_1.isNullOrUndefined(this.htmlAttributes)) {
                for (var _i = 0, _a = Object.keys(this.htmlAttributes); _i < _a.length; _i++) {
                    var key = _a[_i];
                    if (containerAttr.indexOf(key) < 0) {
                        this.element.setAttribute(key, this.htmlAttributes[key]);
                    }
                }
            }
        };
        TextBox.prototype.updateCssClass = function (newClass, oldClass) {
            input_1.Input.setCssClass(this.getInputValidClassList(newClass), [this.textboxWrapper.container], this.getInputValidClassList(oldClass));
        };
        TextBox.prototype.getInputValidClassList = function (inputClassName) {
            var result = inputClassName;
            if (!ej2_base_1.isNullOrUndefined(inputClassName) && inputClassName !== '') {
                result = (inputClassName.replace(/\s+/g, ' ')).trim();
            }
            return result;
        };
        TextBox.prototype.setInitialValue = function () {
            Eif (!this.isAngular) {
                this.respectiveElement.setAttribute('value', this.initialValue);
            }
        };
        TextBox.prototype.wireEvents = function () {
            ej2_base_1.EventHandler.add(this.respectiveElement, 'focus', this.focusHandler, this);
            ej2_base_1.EventHandler.add(this.respectiveElement, 'blur', this.focusOutHandler, this);
            ej2_base_1.EventHandler.add(this.respectiveElement, 'input', this.inputHandler, this);
            ej2_base_1.EventHandler.add(this.respectiveElement, 'change', this.changeHandler, this);
            if (this.isForm) {
                ej2_base_1.EventHandler.add(this.formElement, 'reset', this.resetForm, this);
            }
            this.bindClearEvent();
            Iif (!ej2_base_1.isNullOrUndefined(this.textboxWrapper.container.querySelector('.e-float-text')) && this.floatLabelType === 'Auto'
                && this.textboxWrapper.container.classList.contains('e-autofill') &&
                this.textboxWrapper.container.classList.contains('e-outline')) {
                ej2_base_1.EventHandler.add((this.textboxWrapper.container.querySelector('.e-float-text')), 'animationstart', this.animationHandler, this);
            }
        };
        TextBox.prototype.animationHandler = function () {
            this.textboxWrapper.container.classList.add('e-valid-input');
            var label = this.textboxWrapper.container.querySelector('.e-float-text');
            Iif (!ej2_base_1.isNullOrUndefined(label)) {
                label.classList.add('e-label-top');
                if (label.classList.contains('e-label-bottom')) {
                    label.classList.remove('e-label-bottom');
                }
            }
        };
        TextBox.prototype.resetValue = function (value) {
            var prevOnChange = this.isProtectedOnChange;
            this.isProtectedOnChange = true;
            this.value = value;
            this.isProtectedOnChange = prevOnChange;
        };
        TextBox.prototype.resetForm = function () {
            Iif (this.isAngular) {
                this.resetValue('');
            }
            else {
                this.resetValue(this.initialValue);
            }
            Eif (!ej2_base_1.isNullOrUndefined(this.textboxWrapper)) {
                var label = this.textboxWrapper.container.querySelector('.e-float-text');
                if (!ej2_base_1.isNullOrUndefined(label)) {
                    if ((ej2_base_1.isNullOrUndefined(this.initialValue) || this.initialValue === '')) {
                        label.classList.add('e-label-bottom');
                        label.classList.remove('e-label-top');
                    }
                    else Eif (this.initialValue !== '') {
                        label.classList.add('e-label-top');
                        label.classList.remove('e-label-bottom');
                    }
                }
            }
        };
        TextBox.prototype.focusHandler = function (args) {
            var eventArgs = {
                container: this.textboxWrapper.container,
                event: args,
                value: this.value
            };
            this.trigger('focus', eventArgs);
        };
        TextBox.prototype.focusOutHandler = function (args) {
            if (!(this.previousValue === null && this.value === null && this.respectiveElement.value === '') &&
                (this.previousValue !== this.respectiveElement.value)) {
                this.raiseChangeEvent(args, true);
            }
            var eventArgs = {
                container: this.textboxWrapper.container,
                event: args,
                value: this.value
            };
            this.trigger('blur', eventArgs);
        };
        TextBox.prototype.inputHandler = function (args) {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-this-alias
            var textboxObj = this;
            var eventArgs = {
                event: args,
                value: this.respectiveElement.value,
                previousValue: this.inputPreviousValue,
                container: this.textboxWrapper.container
            };
            this.inputPreviousValue = this.respectiveElement.value;
            /* istanbul ignore next */
            Iif (this.isAngular) {
                textboxObj.localChange({ value: this.respectiveElement.value });
                this.preventChange = true;
            }
            if (this.isVue) {
                this.preventChange = true;
            }
            this.trigger('input', eventArgs);
            args.stopPropagation();
        };
        TextBox.prototype.changeHandler = function (args) {
            this.setProperties({ value: this.respectiveElement.value }, true);
            this.raiseChangeEvent(args, true);
            args.stopPropagation();
        };
        TextBox.prototype.raiseChangeEvent = function (event, interaction) {
            var eventArgs = {
                event: event,
                value: this.value,
                previousValue: this.previousValue,
                container: this.textboxWrapper.container,
                isInteraction: interaction ? interaction : false,
                isInteracted: interaction ? interaction : false
            };
            this.preventChange = false;
            this.trigger('change', eventArgs);
            this.previousValue = this.value;
        };
        TextBox.prototype.bindClearEvent = function () {
            if (this.showClearButton && this.respectiveElement.tagName !== 'TEXTAREA') {
                if (this.enabled) {
                    ej2_base_1.EventHandler.add(this.textboxWrapper.clearButton, 'mousedown touchstart', this.resetInputHandler, this);
                }
                else {
                    ej2_base_1.EventHandler.remove(this.textboxWrapper.clearButton, 'mousedown touchstart', this.resetInputHandler);
                }
            }
        };
        TextBox.prototype.resetInputHandler = function (event) {
            event.preventDefault();
            if (!(this.textboxWrapper.clearButton.classList.contains(HIDE_CLEAR)) || this.textboxWrapper.container.classList.contains('e-static-clear')) {
                input_1.Input.setValue('', this.respectiveElement, this.floatLabelType, this.showClearButton);
                Iif (this.isHiddenInput) {
                    this.element.value = this.respectiveElement.value;
                }
                this.setProperties({ value: this.respectiveElement.value }, true);
                var eventArgs = {
                    event: event,
                    value: this.respectiveElement.value,
                    previousValue: this.inputPreviousValue,
                    container: this.textboxWrapper.container
                };
                this.trigger('input', eventArgs);
                this.inputPreviousValue = this.respectiveElement.value;
                this.raiseChangeEvent(event, true);
            }
        };
        TextBox.prototype.unWireEvents = function () {
            ej2_base_1.EventHandler.remove(this.respectiveElement, 'focus', this.focusHandler);
            ej2_base_1.EventHandler.remove(this.respectiveElement, 'blur', this.focusOutHandler);
            ej2_base_1.EventHandler.remove(this.respectiveElement, 'input', this.inputHandler);
            ej2_base_1.EventHandler.remove(this.respectiveElement, 'change', this.changeHandler);
            if (this.isForm) {
                ej2_base_1.EventHandler.remove(this.formElement, 'reset', this.resetForm);
            }
            Iif (!ej2_base_1.isNullOrUndefined(this.textboxWrapper.container.querySelector('.e-float-text')) && this.floatLabelType === 'Auto'
                && this.textboxWrapper.container.classList.contains('e-outline') &&
                this.textboxWrapper.container.classList.contains('e-autofill')) {
                ej2_base_1.EventHandler.remove((this.textboxWrapper.container.querySelector('.e-float-text')), 'animationstart', this.animationHandler);
            }
        };
        /**
         * Removes the component from the DOM and detaches all its related event handlers.
         * Also, it maintains the initial TextBox element from the DOM.
         *
         * @method destroy
         * @returns {void}
         */
        TextBox.prototype.destroy = function () {
            this.unWireEvents();
            if (this.element.tagName === 'INPUT' && this.multiline) {
                ej2_base_2.detach(this.textboxWrapper.container.getElementsByTagName('textarea')[0]);
                this.respectiveElement = this.element;
                this.element.removeAttribute('type');
            }
            this.respectiveElement.value = this.respectiveElement.defaultValue;
            this.respectiveElement.classList.remove('e-input');
            this.removeAttributes(['aria-placeholder', 'aria-disabled', 'aria-readonly', 'aria-labelledby']);
            Eif (!ej2_base_1.isNullOrUndefined(this.textboxWrapper)) {
                this.textboxWrapper.container.insertAdjacentElement('afterend', this.respectiveElement);
                ej2_base_2.detach(this.textboxWrapper.container);
            }
            this.textboxWrapper = null;
            _super.prototype.destroy.call(this);
        };
        /**
         * Adding the icons to the TextBox component.
         *
         * @param { string } position - Specify the icon placement on the TextBox. Possible values are append and prepend.
         * @param { string | string[] } icons - Icon classes which are need to add to the span element which is going to created.
         * Span element acts as icon or button element for TextBox.
         * @returns {void}
         */
        TextBox.prototype.addIcon = function (position, icons) {
            input_1.Input.addIcon(position, icons, this.textboxWrapper.container, this.respectiveElement, this.createElement);
        };
        /* eslint-disable valid-jsdoc, jsdoc/require-returns */
        /**
         * Gets the properties to be maintained in the persisted state.
         *
         */
        TextBox.prototype.getPersistData = function () {
            var keyEntity = ['value'];
            return this.addOnPersist(keyEntity);
        };
        /* eslint-enable valid-jsdoc, jsdoc/require-returns */
        /**
         * Adding the multiple attributes as key-value pair to the TextBox element.
         *
         * @param {string} attributes - Specifies the attributes to be add to TextBox element.
         * @returns {void}
         */
        TextBox.prototype.addAttributes = function (attributes) {
            for (var _i = 0, _a = Object.keys(attributes); _i < _a.length; _i++) {
                var key = _a[_i];
                if (key === 'disabled') {
                    this.setProperties({ enabled: false }, true);
                    input_1.Input.setEnabled(this.enabled, this.respectiveElement, this.floatLabelType, this.textboxWrapper.container);
                }
                else if (key === 'readonly') {
                    this.setProperties({ readonly: true }, true);
                    input_1.Input.setReadonly(this.readonly, this.respectiveElement);
                }
                else if (key === 'class') {
                    this.respectiveElement.classList.add(attributes[key]);
                }
                else if (key === 'placeholder') {
                    this.setProperties({ placeholder: attributes[key] }, true);
                    input_1.Input.setPlaceholder(this.placeholder, this.respectiveElement);
                }
                else if (key === 'rows' && this.respectiveElement.tagName === 'TEXTAREA') {
                    this.respectiveElement.setAttribute(key, attributes[key]);
                }
                else {
                    this.respectiveElement.setAttribute(key, attributes[key]);
                }
            }
        };
        /**
         * Removing the multiple attributes as key-value pair to the TextBox element.
         *
         * @param { string[] } attributes - Specifies the attributes name to be removed from TextBox element.
         * @returns {void}
         */
        TextBox.prototype.removeAttributes = function (attributes) {
            for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
                var key = attributes_1[_i];
                if (key === 'disabled') {
                    this.setProperties({ enabled: true }, true);
                    input_1.Input.setEnabled(this.enabled, this.respectiveElement, this.floatLabelType, this.textboxWrapper.container);
                }
                else if (key === 'readonly') {
                    this.setProperties({ readonly: false }, true);
                    input_1.Input.setReadonly(this.readonly, this.respectiveElement);
                }
                else if (key === 'placeholder') {
                    this.setProperties({ placeholder: null }, true);
                    input_1.Input.setPlaceholder(this.placeholder, this.respectiveElement);
                }
                else {
                    this.respectiveElement.removeAttribute(key);
                }
            }
        };
        /**
         * Sets the focus to widget for interaction.
         *
         * @returns {void}
         */
        TextBox.prototype.focusIn = function () {
            Eif (document.activeElement !== this.respectiveElement && this.enabled) {
                this.respectiveElement.focus();
                Eif (this.textboxWrapper.container.classList.contains('e-input-group')
                    || this.textboxWrapper.container.classList.contains('e-outline')
                    || this.textboxWrapper.container.classList.contains('e-filled')) {
                    ej2_base_3.addClass([this.textboxWrapper.container], [TEXTBOX_FOCUS]);
                }
            }
        };
        /**
         * Remove the focus from widget, if the widget is in focus state.
         *
         * @returns {void}
         */
        TextBox.prototype.focusOut = function () {
            Eif (document.activeElement === this.respectiveElement && this.enabled) {
                this.respectiveElement.blur();
                Eif (this.textboxWrapper.container.classList.contains('e-input-group')
                    || this.textboxWrapper.container.classList.contains('e-outline')
                    || this.textboxWrapper.container.classList.contains('e-filled')) {
                    ej2_base_3.removeClass([this.textboxWrapper.container], [TEXTBOX_FOCUS]);
                }
            }
        };
        __decorate([
            ej2_base_1.Property('text')
        ], TextBox.prototype, "type", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], TextBox.prototype, "readonly", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], TextBox.prototype, "value", void 0);
        __decorate([
            ej2_base_1.Property('Never')
        ], TextBox.prototype, "floatLabelType", void 0);
        __decorate([
            ej2_base_1.Property('')
        ], TextBox.prototype, "cssClass", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], TextBox.prototype, "placeholder", void 0);
        __decorate([
            ej2_base_1.Property('on')
        ], TextBox.prototype, "autocomplete", void 0);
        __decorate([
            ej2_base_1.Property({})
        ], TextBox.prototype, "htmlAttributes", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], TextBox.prototype, "multiline", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], TextBox.prototype, "enabled", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], TextBox.prototype, "showClearButton", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], TextBox.prototype, "enablePersistence", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], TextBox.prototype, "width", void 0);
        __decorate([
            ej2_base_1.Event()
        ], TextBox.prototype, "created", void 0);
        __decorate([
            ej2_base_1.Event()
        ], TextBox.prototype, "destroyed", void 0);
        __decorate([
            ej2_base_1.Event()
        ], TextBox.prototype, "change", void 0);
        __decorate([
            ej2_base_1.Event()
        ], TextBox.prototype, "blur", void 0);
        __decorate([
            ej2_base_1.Event()
        ], TextBox.prototype, "focus", void 0);
        __decorate([
            ej2_base_1.Event()
        ], TextBox.prototype, "input", void 0);
        TextBox = __decorate([
            ej2_base_2.NotifyPropertyChanges
        ], TextBox);
        return TextBox;
    }(ej2_base_1.Component));
    exports.TextBox = TextBox;
});