From da0d14c1708307b6eb543422bc4e6c64943e3b23 Mon Sep 17 00:00:00 2001 From: Anton Vikulov Date: Thu, 22 Feb 2024 09:34:11 +0500 Subject: [PATCH 1/2] use node 18 --- .nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nvmrc b/.nvmrc index da2d398..3c03207 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -14 \ No newline at end of file +18 From 23b194e2df2818ac0d73297b0534cbde3de125c3 Mon Sep 17 00:00:00 2001 From: Anton Vikulov Date: Thu, 22 Feb 2024 15:17:02 +0500 Subject: [PATCH 2/2] Reset scroll with scrollTop changes --- src/runtime/TabsController.ts | 12 ++++++++---- src/runtime/utils.ts | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/runtime/TabsController.ts b/src/runtime/TabsController.ts index 161f519..5233344 100644 --- a/src/runtime/TabsController.ts +++ b/src/runtime/TabsController.ts @@ -98,11 +98,11 @@ export class TabsController { const updatedTabs = this.updateHTML({group, key}); if (updatedTabs > 0) { + this.fireSelectTabEvent({group, key}, targetTab?.dataset.diplodocId); + if (previousTargetOffset) { this.resetScroll(targetTab, scrollableParent, previousTargetOffset); } - - this.fireSelectTabEvent({group, key}, targetTab?.dataset.diplodocId); } } @@ -155,9 +155,13 @@ export class TabsController { previousTargetOffset: ElementOffset, ) { const targetOffset = getOffsetByScrollableParent(target, scrollableParent); + const topDelta = targetOffset.top - previousTargetOffset.top; + const leftDelta = targetOffset.left - previousTargetOffset.left; + const scrollTopDelta = targetOffset.scrollTop - previousTargetOffset.scrollTop; + const scrollLeftDelta = targetOffset.scrollLeft - previousTargetOffset.scrollLeft; scrollableParent.scrollTo( - targetOffset.left + scrollableParent.scrollLeft - previousTargetOffset.left, - targetOffset.top + scrollableParent.scrollTop - previousTargetOffset.top, + scrollableParent.scrollLeft + leftDelta - scrollLeftDelta, + scrollableParent.scrollTop + topDelta - scrollTopDelta, ); } diff --git a/src/runtime/utils.ts b/src/runtime/utils.ts index bb190c7..8ed673e 100644 --- a/src/runtime/utils.ts +++ b/src/runtime/utils.ts @@ -19,6 +19,8 @@ export const getClosestScrollableParent = (element: HTMLElement): HTMLElement | export interface ElementOffset { top: number; left: number; + scrollTop: number; + scrollLeft: number; } export const getOffsetByScrollableParent = ( @@ -30,5 +32,7 @@ export const getOffsetByScrollableParent = ( return { top: elementBounds.top - scrollableParentBounds.top, left: elementBounds.left - scrollableParentBounds.left, + scrollTop: scrollableParent.scrollTop, + scrollLeft: scrollableParent.scrollLeft, }; };