fix: layout problem after adding transition
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user