@pepperi-addons/ngx-lib 0.4.2-beta.317 → 0.4.2-beta.318

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -899,24 +899,32 @@ class PepInputAutoWidthDirective {
899
899
  this.el = el;
900
900
  this.includePadding = true;
901
901
  this.input = null;
902
+ this.onBlurHandler = () => this.setWidthUsingText();
903
+ this.onKeyupHandler = () => this.setWidthUsingText();
902
904
  }
903
905
  ngAfterViewInit() {
904
- if (this.el.nativeElement.tagName.toLowerCase() === 'input') {
905
- this.input = this.el;
906
+ if (this.el.nativeElement?.tagName?.toLowerCase() === 'input') {
907
+ this.input = this.el.nativeElement;
906
908
  }
907
909
  else {
908
- const list = this.el.nativeElement.querySelectorAll('input');
909
- this.input = list.length > 0 ? list[0] : null;
910
+ const list = this.el.nativeElement?.querySelectorAll
911
+ ? this.el.nativeElement.querySelectorAll('input')
912
+ : null;
913
+ this.input = list && list.length > 0 ? list[0] : null;
910
914
  }
911
915
  if (this.input) {
912
- this.input.addEventListener('blur', this.setWidthUsingText.bind(this));
913
- this.input.addEventListener('keyup', this.setWidthUsingText.bind(this));
916
+ this.input.addEventListener('blur', this.onBlurHandler);
917
+ this.input.addEventListener('keyup', this.onKeyupHandler);
914
918
  }
915
919
  this.setWidthUsingText();
916
920
  }
917
921
  ngOnDestroy() {
918
- this.input.removeEventListener('blur', this.setWidthUsingText.bind(this));
919
- this.input.removeEventListener('keyup', this.setWidthUsingText.bind(this));
922
+ if (!this.input) {
923
+ return;
924
+ }
925
+ this.input.removeEventListener('blur', this.onBlurHandler);
926
+ this.input.removeEventListener('keyup', this.onKeyupHandler);
927
+ this.input = null;
920
928
  }
921
929
  get paddingWidth() {
922
930
  return this.includePadding