@klippa/ngx-enhancy-forms 14.22.6 → 14.22.8

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.
@@ -668,10 +668,11 @@ class FormElementComponent {
668
668
  return this.getErrorToShow() === error && !this.customErrorHandlers.some((e) => e.error === error);
669
669
  }
670
670
  getScrollableParent(node) {
671
- if (node == null) {
672
- return null;
671
+ if (node === window.document.documentElement) {
672
+ return window.document.documentElement;
673
673
  }
674
- if (node.scrollHeight > node.clientHeight) {
674
+ const overflowY = getComputedStyle(node).overflowY;
675
+ if (node.clientHeight < node.scrollHeight && (overflowY === 'auto' || overflowY === 'scroll')) {
675
676
  return node;
676
677
  }
677
678
  else {
@@ -679,9 +680,17 @@ class FormElementComponent {
679
680
  }
680
681
  }
681
682
  scrollTo() {
682
- this.internalComponentRef.nativeElement.scrollIntoView(true);
683
- // to give some breathing room, we scroll 100px more to the top
684
- this.getScrollableParent(this.internalComponentRef.nativeElement)?.scrollBy(0, -100);
683
+ const parent = this.getScrollableParent(this.internalComponentRef.nativeElement);
684
+ const parentTop = parent === window.document.documentElement ? 0 : parent.getBoundingClientRect().top;
685
+ const elementTop = this.internalComponentRef.nativeElement.getBoundingClientRect().top;
686
+ const parentScrollTop = parent.scrollTop;
687
+ const answer = elementTop - parentTop + parentScrollTop;
688
+ console.log('answer', parentTop, elementTop, parentScrollTop, answer);
689
+ console.log(parent, this.internalComponentRef.nativeElement);
690
+ parent.scrollTo({
691
+ top: answer - 30,
692
+ behavior: 'smooth'
693
+ });
685
694
  }
686
695
  isRequired() {
687
696
  if (isValueSet(this.input)) {