ngx-render-material-forms 1.5.1 → 1.5.3

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.
@@ -2594,20 +2594,27 @@ class MaterialSelectComponent extends MaterialComponent {
2594
2594
  });
2595
2595
  }
2596
2596
  registerPanelScrollEvent(selectElem) {
2597
- const panelElement = selectElem?.panel?.nativeElement;
2598
- panelElement.addEventListener('scroll', this.onScroll.bind(this));
2597
+ if (selectElem && selectElem?.panel) {
2598
+ // const panelElement = selectElem.panel.nativeElement;
2599
+ this.currentPanelElement = selectElem.panel.nativeElement;
2600
+ this.currentPanelElement.addEventListener('scroll', this.onScroll.bind(this));
2601
+ }
2599
2602
  }
2600
2603
  onScroll(event) {
2601
2604
  if (this.instance.component.key.toLowerCase() === 'vendorproductid') {
2602
2605
  const scrollElement = event.target;
2606
+ if (!scrollElement)
2607
+ return; // Ensure scrollElement is not undefined
2603
2608
  const trackHeight = scrollElement.scrollHeight - scrollElement.offsetHeight;
2609
+ if (isNaN(trackHeight) || trackHeight <= 0)
2610
+ return; // Check if trackHeight is valid
2604
2611
  if (this.openCounter < 2) {
2605
2612
  const retrievedObject = JSON.parse(localStorage.getItem('storageObject'));
2606
2613
  this.totalPages = Number(retrievedObject?.totalPages);
2607
2614
  this.productsloadingFlag = true;
2608
2615
  this.productList = retrievedObject?.dataSource;
2609
2616
  }
2610
- if (this.productsloadingFlag && Math.floor(scrollElement.scrollTop / trackHeight * 100) > 50) {
2617
+ if (this.productsloadingFlag && Math.floor(scrollElement?.scrollTop / trackHeight * 100) > 50) {
2611
2618
  this.productsloadingFlag = false;
2612
2619
  this.openCounter = this.openCounter + 1;
2613
2620
  if (this.pageNumber < this.totalPages) {
@@ -2692,9 +2699,14 @@ class MaterialSelectComponent extends MaterialComponent {
2692
2699
  this.productsloadingFlag = true;
2693
2700
  setTimeout(() => {
2694
2701
  const ele = this.selectElem?.panel?.nativeElement;
2695
- const trackHeight = ele.scrollHeight - ele.offsetHeight;
2696
- const middlePosition = trackHeight / 2 - 50;
2697
- ele.scrollTo({ top: middlePosition, behavior: 'auto' });
2702
+ if (ele) {
2703
+ const trackHeight = ele.scrollHeight - ele.offsetHeight;
2704
+ const middlePosition = trackHeight / 2 - 50;
2705
+ ele.scrollTo({ top: middlePosition, behavior: 'auto' });
2706
+ }
2707
+ else {
2708
+ console.log('Panel element is not available yet.');
2709
+ }
2698
2710
  }, 250);
2699
2711
  }
2700
2712
  }
@@ -2730,6 +2742,9 @@ class MaterialSelectComponent extends MaterialComponent {
2730
2742
  ngOnDestroy() {
2731
2743
  this._onDestroy.next('');
2732
2744
  this._onDestroy.complete();
2745
+ if (this.currentPanelElement) {
2746
+ this.currentPanelElement.removeEventListener('scroll', this.onScroll.bind(this));
2747
+ }
2733
2748
  }
2734
2749
  /*End*/
2735
2750
  setInstance(instance) {
@@ -2761,7 +2776,7 @@ class MaterialSelectComponent extends MaterialComponent {
2761
2776
  this.removePanelScrollEvent();
2762
2777
  this.searching = false;
2763
2778
  let selectedValue = this.getValue();
2764
- if ((selectedValue.toString().length == 0 && this.searchQuery == '') || this.productList?.length === 0) {
2779
+ if (selectedValue?.toString().length == '' || this.searchQuery == '' || this.productList?.length === 0) {
2765
2780
  this.productList = [];
2766
2781
  this.pageNumber = 1;
2767
2782
  this.pageSize = 20;