import { Box, HStack, Pressable, Text } from '../../primitives'; import React, { useEffect, useState } from 'react'; import { findPageById } from '../../utils/helperFunction'; import { LayoutContext } from '../Layout/LayoutContext'; export const HeadingTabs = ({ ...props }: any) => { const { isOpenSidebar, sidebarItems, router, colorMode } = React.useContext(LayoutContext); let result = findPageById(router.pathname, sidebarItems); const [active, setActive] = useState(0); useEffect(() => { setActive(0); }, [router.pathname]); function handleTabPress(index: number) { //commented it out because it was causing toggle in active tab // setActive(index); let x: any = document.querySelectorAll('h2'); if (x[index]) { x[index].style.scrollMargin = '130px'; x[index].scrollIntoView({ block: 'start', behavior: 'smooth', }); } } useEffect(() => { const container = document.querySelector('#layout-content') as HTMLElement; const headings = document.querySelectorAll('h2'); const handleScroll = () => { let index = 0; for (let i = 0; i < headings.length; i++) { if (container.scrollTop >= headings[i].offsetTop + 100) { index = i; } } setActive(index); }; container?.addEventListener('scroll', handleScroll); return () => container?.removeEventListener('scroll', () => {}); }, [router.pathname, colorMode]); return result?.metaData?.showHeader ? ( {result?.h2Tags ? ( {result?.h2Tags.map((item: any, index: any) => { return ( { handleTabPress(index); }} sx={{ _web: { boxShadow: 'none', _dark: { boxShadow: 'none', }, _light: { boxShadow: 'none', }, }, }} > {item} ); })} ) : null} ) : null; };