From 1a1e61eb0c843cce1b4f266e4443513d9a07c14b Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Thu, 7 Sep 2023 12:09:13 +0530 Subject: [PATCH] fix(nocohub): Fixed view scroll not coming and auto scroll on active view --- .../components/smartsheet/sidebar/MenuTop.vue | 28 ++++++++++++++++++- .../components/smartsheet/sidebar/index.vue | 2 +- packages/nc-gui/utils/domUtils.ts | 5 ++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue b/packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue index 451577c05f..94031e9ecf 100644 --- a/packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue +++ b/packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue @@ -297,13 +297,38 @@ const setIcon = async (icon: string, view: ViewType) => { message.error(await extractSdkResponseErrorMsg(e)) } } + +const scrollViewNode = () => { + const activeViewDom = document.querySelector(`.nc-views-menu [data-view-id="${activeView.value?.id}"]`) as HTMLElement + if (!activeViewDom) return + + if (isElementInvisible(activeViewDom)) { + // Scroll to the view node + activeViewDom?.scrollIntoView({ behavior: 'auto', inline: 'start' }) + } +} + +watch( + () => activeView.value?.id, + () => { + if (!activeView.value?.id) return + + // TODO: Find a better way to scroll to the view node + setTimeout(() => { + scrollViewNode() + }, 800) + }, + { + immediate: true, + }, +)