From 64d06e5a1fa07ad6782f4b597035fecb42a84c40 Mon Sep 17 00:00:00 2001 From: Dark_Phoenix_ <92178883+0DarkPhoenix@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:04:32 +0100 Subject: [PATCH] feat(Sidebar): added backgroundcolor for active category and scroll-to logic for active tool (#309) * Added color to component group when a tool inside that group is currently selected, and changed resistor-calculator icon from a hammer to the omega icon * - Added scrollto functionality for active tool in sidebar - Improved icon diversity and correctness for multiple tools * - Changed scrollto behaviour to trigger on mount and on url path change - Restored the IT-Tools banner to stick to the top of the screen while scrolling * Swapped nextTick for setTimeout to fix a delay issue where it didn't scroll to the active tool * Reduced bottom padding of sidebar to fix an issue where the sidebar was scrollable with all categories closed Fix #298 --------- Co-authored-by: ShareVB --- src/components/CollapsibleToolMenu.vue | 58 ++++++++++++++++++-- src/layouts/base.layout.vue | 7 ++- src/tools/folder-structure-diagram/index.ts | 6 +- src/tools/force-converter/index.ts | 6 +- src/tools/fortune-wheel/index.ts | 6 +- src/tools/geo-coordinates-converter/index.ts | 6 +- src/tools/illuminance-converter/index.ts | 6 +- src/tools/jq-memo/index.ts | 6 +- src/tools/json-to-typescript/index.ts | 6 +- src/tools/jsonpath-memo/index.ts | 6 +- src/tools/length-converter/index.ts | 6 +- src/tools/mailto-generator/index.ts | 6 +- src/tools/mongo-objectid-converter/index.ts | 6 +- src/tools/passphrase-generator/index.ts | 6 +- src/tools/pressure-converter/index.ts | 6 +- src/tools/resistor-calculator/index.ts | 4 +- src/tools/sql-minifier/index.ts | 6 +- src/tools/sql-parameters/index.ts | 6 +- src/tools/sql-prettify/index.ts | 6 +- src/tools/svg-placeholder-generator/index.ts | 6 +- src/tools/text-to-unicode-names/index.ts | 6 +- src/tools/translator/index.ts | 6 +- src/tools/volume-converter/index.ts | 6 +- 23 files changed, 120 insertions(+), 69 deletions(-) diff --git a/src/components/CollapsibleToolMenu.vue b/src/components/CollapsibleToolMenu.vue index f2ffb0af..ca21e257 100644 --- a/src/components/CollapsibleToolMenu.vue +++ b/src/components/CollapsibleToolMenu.vue @@ -10,9 +10,9 @@ const props = withDefaults(defineProps<{ toolsByCategory?: ToolCategory[] }>(), const { toolsByCategory } = toRefs(props); const route = useRoute(); -// Memoize component creation functions -const makeLabel = (tool: Tool) => () => h(MenuItemWithTooltip, { tool, key: tool.path }); -const makeIcon = (tool: Tool) => () => h(MenuIconItem, { tool, key: tool.path }); +// Memoize component creation functions - wrap in markRaw to prevent reactivity +const makeLabel = (tool: Tool) => () => markRaw(h(MenuItemWithTooltip, { tool, key: tool.path })); +const makeIcon = (tool: Tool) => () => markRaw(h(MenuIconItem, { tool, key: tool.path })); const collapsedCategories = useStorage>( 'menu-tool-option:collapsed-categories', @@ -45,6 +45,7 @@ watchEffect(() => { }); const isToggling = ref(false); +const menuContainerRefs = ref>({}); function toggleCategoryCollapse({ name }: { name: string }) { collapsedCategories.value[name] = !collapsedCategories.value[name]; @@ -84,10 +85,16 @@ function getAnimationDuration(itemCount: number): number { return baseDuration + (Math.min(itemCount, 30) * durationIncrement); } +// Function to check if any tool in the category is active +function isCategoryActive(components: Tool[]): boolean { + return components.some(tool => tool.path === route.path); +} + const menuOptions = computed(() => toolsByCategory.value.map(({ name, components }) => ({ name, isCollapsed: collapsedCategories.value[name], + isActive: isCategoryActive(components), animationDuration: getAnimationDuration(components.length), tools: components.map(tool => ({ label: makeLabel(tool), @@ -97,6 +104,37 @@ const menuOptions = computed(() => })), ); +async function scrollToActiveItem() { + const activeCategory = toolsByCategory.value.find(({ components }) => + isCategoryActive(components), + ); + + if (activeCategory) { + // Expand the active category + collapsedCategories.value[activeCategory.name] = false; + + // Wait for the entire animation to complete + await new Promise(resolve => setTimeout(resolve, getAnimationDuration(activeCategory.components.length) + 50)); + + // Scroll to the active menu item + const menuContainer = menuContainerRefs.value[activeCategory.name]; + if (menuContainer) { + const activeItem = menuContainer.querySelector('.router-link-exact-active, .router-link-active'); + if (activeItem) { + activeItem.scrollIntoView({ behavior: 'smooth', block: 'center' }); + } + } + } +} + +onMounted(() => { + scrollToActiveItem(); +}); + +watch(() => route.path, () => { + scrollToActiveItem(); +}); + const themeVars = useThemeVars(); @@ -112,9 +150,10 @@ const themeVars = useThemeVars(); -
+