From 8048ba9b860acad50da9398f22ec87c7d3860b5a Mon Sep 17 00:00:00 2001 From: mtvpls Date: Mon, 29 Dec 2025 16:40:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dvideocard=E6=AF=94=E6=94=B6?= =?UTF-8?q?=E8=97=8F=E5=BC=B9=E7=AA=97=E9=AB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/MobileActionSheet.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/MobileActionSheet.tsx b/src/components/MobileActionSheet.tsx index bc83f5f..3d3791d 100644 --- a/src/components/MobileActionSheet.tsx +++ b/src/components/MobileActionSheet.tsx @@ -1,6 +1,7 @@ import { Radio, X } from 'lucide-react'; import Image from 'next/image'; import React, { useEffect, useState } from 'react'; +import { createPortal } from 'react-dom'; interface ActionItem { id: string; @@ -40,6 +41,12 @@ const MobileActionSheet: React.FC = ({ }) => { const [isVisible, setIsVisible] = useState(false); const [isAnimating, setIsAnimating] = useState(false); + const [mounted, setMounted] = useState(false); + + // 确保组件在客户端挂载后才渲染 Portal + useEffect(() => { + setMounted(true); + }, []); // 控制动画状态 useEffect(() => { @@ -136,7 +143,7 @@ const MobileActionSheet: React.FC = ({ } }, [isVisible, onClose]); - if (!isVisible) return null; + if (!isVisible || !mounted) return null; const getActionColor = (color: ActionItem['color']) => { switch (color) { @@ -160,7 +167,7 @@ const MobileActionSheet: React.FC = ({ } }; - return ( + const content = (
{ @@ -344,6 +351,9 @@ const MobileActionSheet: React.FC = ({
); + + // 使用 Portal 将组件渲染到 document.body + return createPortal(content, document.body); }; export default MobileActionSheet;