From ffae5d2f209963bf08ca18ee561c1f11b866cad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=85=E7=BA=AF=E7=9A=84=E5=B0=8F=E9=BB=84=E7=93=9C?= Date: Mon, 30 Sep 2024 20:21:44 +0800 Subject: [PATCH] fix: sidebar cannot display correctly on mobile, when collapsed is true (#7694) --- app/components/Sidebar/Sidebar.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/components/Sidebar/Sidebar.tsx b/app/components/Sidebar/Sidebar.tsx index 66becdd1f0..bff82e4072 100644 --- a/app/components/Sidebar/Sidebar.tsx +++ b/app/components/Sidebar/Sidebar.tsx @@ -8,6 +8,7 @@ import { Avatar } from "~/components/Avatar"; import Flex from "~/components/Flex"; import useCurrentUser from "~/hooks/useCurrentUser"; import useMenuContext from "~/hooks/useMenuContext"; +import useMobile from "~/hooks/useMobile"; import usePrevious from "~/hooks/usePrevious"; import useStores from "~/hooks/useStores"; import AccountMenu from "~/menus/AccountMenu"; @@ -39,6 +40,7 @@ const Sidebar = React.forwardRef(function _Sidebar( const previousLocation = usePrevious(location); const { isMenuOpen } = useMenuContext(); const user = useCurrentUser({ rejectOnEmpty: false }); + const isMobile = useMobile(); const width = ui.sidebarWidth; const collapsed = ui.sidebarIsClosed && !isMenuOpen; const maxWidth = theme.sidebarMaxWidth; @@ -189,6 +191,7 @@ const Sidebar = React.forwardRef(function _Sidebar( $isSmallerThanMinimum={isSmallerThanMinimum} $mobileSidebarVisible={ui.mobileSidebarVisible} $collapsed={collapsed} + $isMobile={isMobile} className={className} onPointerMove={handlePointerMove} onPointerLeave={handlePointerLeave} @@ -256,6 +259,7 @@ type ContainerProps = { $isHovering: boolean; $collapsed: boolean; $hidden: boolean; + $isMobile: boolean; }; const hoverStyles = (props: ContainerProps) => ` @@ -298,8 +302,19 @@ const Container = styled(Flex)` & > div { transition: opacity 150ms ease-in-out; - opacity: ${(props) => - props.$hidden || (props.$collapsed && !props.$isHovering) ? "0" : "1"}; + opacity: ${(props) => { + if (props.$hidden) { + return "0"; + } + if (props.$isHovering) { + return "1"; + } + if (props.$isMobile) { + return props.$mobileSidebarVisible ? "1" : "0"; + } else { + return props.$collapsed ? "0" : "1"; + } + }}; } ${breakpoint("tablet")`