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

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.
@@ -906,24 +906,44 @@ class PepInputAutoWidthDirective {
906
906
  this.el = el;
907
907
  this.includePadding = true;
908
908
  this.input = null;
909
+ this.lastValue = null;
910
+ this.onBlurHandler = () => this.setWidthUsingText();
911
+ this.onKeyupHandler = () => this.setWidthUsingText();
909
912
  }
910
913
  ngAfterViewInit() {
911
- if (this.el.nativeElement.tagName.toLowerCase() === 'input') {
912
- this.input = this.el;
914
+ var _a, _b, _c;
915
+ if (((_b = (_a = this.el.nativeElement) === null || _a === void 0 ? void 0 : _a.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'input') {
916
+ this.input = this.el.nativeElement;
913
917
  }
914
918
  else {
915
- const list = this.el.nativeElement.querySelectorAll('input');
916
- this.input = list.length > 0 ? list[0] : null;
919
+ const list = ((_c = this.el.nativeElement) === null || _c === void 0 ? void 0 : _c.querySelectorAll)
920
+ ? this.el.nativeElement.querySelectorAll('input')
921
+ : null;
922
+ this.input = list && list.length > 0 ? list[0] : null;
917
923
  }
918
924
  if (this.input) {
919
- this.input.addEventListener('blur', this.setWidthUsingText.bind(this));
920
- this.input.addEventListener('keyup', this.setWidthUsingText.bind(this));
925
+ this.input.addEventListener('blur', this.onBlurHandler);
926
+ this.input.addEventListener('keyup', this.onKeyupHandler);
921
927
  }
922
928
  this.setWidthUsingText();
923
929
  }
930
+ ngDoCheck() {
931
+ if (!this.input) {
932
+ return;
933
+ }
934
+ // Keep the width in sync when value is updated programmatically (Angular bindings),
935
+ // not only on user key events.
936
+ if (this.input.value !== this.lastValue) {
937
+ this.setWidthUsingText();
938
+ }
939
+ }
924
940
  ngOnDestroy() {
925
- this.input.removeEventListener('blur', this.setWidthUsingText.bind(this));
926
- this.input.removeEventListener('keyup', this.setWidthUsingText.bind(this));
941
+ if (!this.input) {
942
+ return;
943
+ }
944
+ this.input.removeEventListener('blur', this.onBlurHandler);
945
+ this.input.removeEventListener('keyup', this.onKeyupHandler);
946
+ this.input = null;
927
947
  }
928
948
  get paddingWidth() {
929
949
  return this.includePadding
@@ -940,6 +960,7 @@ class PepInputAutoWidthDirective {
940
960
  if (this.input) {
941
961
  const text = this.input.value;
942
962
  this.setWidth(this.textWidth(text) + this.paddingWidth);
963
+ this.lastValue = text;
943
964
  }
944
965
  }
945
966
  _sumPropertyValues(properties) {