@klippa/ngx-enhancy-forms 14.22.6 → 14.22.7

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,20 +668,33 @@ 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 {
678
679
  return this.getScrollableParent(node.parentNode);
679
680
  }
680
681
  }
682
+ getPageOffset(elem) {
683
+ let topOffset = elem.getBoundingClientRect().top;
684
+ while (elem !== document.documentElement) {
685
+ elem = elem.parentElement;
686
+ topOffset += elem.scrollTop;
687
+ }
688
+ return topOffset;
689
+ }
681
690
  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);
691
+ const parent = this.getScrollableParent(this.internalComponentRef.nativeElement);
692
+ const pageOffsetElement = this.getPageOffset(this.internalComponentRef.nativeElement);
693
+ const pageOffsetParent = parent === window.document.documentElement ? 0 : this.getPageOffset(parent);
694
+ parent.scrollTo({
695
+ top: pageOffsetElement - pageOffsetParent - 30,
696
+ behavior: 'smooth'
697
+ });
685
698
  }
686
699
  isRequired() {
687
700
  if (isValueSet(this.input)) {