fix: layout problem after adding transition

This commit is contained in:
Mahyar Khanbolooki
2025-07-31 20:19:16 +03:30
parent 7466822c70
commit a090c27e4b
3 changed files with 9 additions and 7 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
import ClientSideWrapper from "@/components/wrapper/ClientSideWrapper";
import ClientMenuRouteWrapper from "@/components/wrapper/ClientMenuRouteWrapper.tsx"; import ClientMenuRouteWrapper from "@/components/wrapper/ClientMenuRouteWrapper.tsx";
import ClientSideWrapper from "@/components/wrapper/ClientSideWrapper";
export const metadata = { export const metadata = {
title: 'Menu', title: 'Menu',
@@ -13,7 +13,7 @@ export default function MenuLayout({
return ( return (
<ClientMenuRouteWrapper> <ClientMenuRouteWrapper>
<ClientSideWrapper> <ClientSideWrapper className=''>
{children} {children}
</ClientSideWrapper> </ClientSideWrapper>
</ClientMenuRouteWrapper> </ClientMenuRouteWrapper>
+3 -3
View File
@@ -160,9 +160,9 @@ const MenuIndex = () => {
const [smallCategoriesVisible, setSmallCategoriesVisibility] = useState(false); const [smallCategoriesVisible, setSmallCategoriesVisibility] = useState(false);
const onScroll = useCallback(() => { const onScroll = useCallback(() => {
if (!wrapperRef?.current?.parentElement?.scrollTop || !smallCategoriesRef.current?.offsetTop) return; if (!wrapperRef?.current?.parentElement?.parentElement?.scrollTop || !smallCategoriesRef.current?.offsetTop) return;
if (wrapperRef.current.parentElement.scrollTop >= smallCategoriesRef.current.offsetTop) { if (wrapperRef.current.parentElement?.parentElement.scrollTop >= smallCategoriesRef.current.offsetTop) {
setSmallCategoriesVisibility(true); setSmallCategoriesVisibility(true);
} else { } else {
setSmallCategoriesVisibility(false); setSmallCategoriesVisibility(false);
@@ -172,7 +172,7 @@ const MenuIndex = () => {
useEffect(() => { useEffect(() => {
if (!wrapperRef.current) return; if (!wrapperRef.current) return;
const parent = wrapperRef.current.parentElement; const parent = wrapperRef.current.parentElement?.parentElement;
if (!parent) return; if (!parent) return;
parent.addEventListener('scroll', onScroll); parent.addEventListener('scroll', onScroll);
+4 -2
View File
@@ -1,14 +1,16 @@
'use client' 'use client'
import clsx from 'clsx'
import { AnimatePresence, motion } from 'framer-motion' import { AnimatePresence, motion } from 'framer-motion'
import { usePathname } from 'next/navigation' import { usePathname } from 'next/navigation'
import React from 'react' import React from 'react'
type Props = { type Props = {
children: React.ReactNode children: React.ReactNode
className?: string
} }
function ClientSideWrapper({ children }: Props) { function ClientSideWrapper({ children, className = 'h-full' }: Props) {
const pathname = usePathname() const pathname = usePathname()
return ( return (
@@ -19,7 +21,7 @@ function ClientSideWrapper({ children }: Props) {
animate={{ opacity: 1, y: 0 }} animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 0, transition: { duration: 0 } }} exit={{ opacity: 0, y: 0, transition: { duration: 0 } }}
transition={{ duration: 0.3 }} transition={{ duration: 0.3 }}
className="h-full" className={clsx(className)}
> >
{children} {children}
</motion.div> </motion.div>