Просмотр исходного кода

Merge pull request #5283 from weseek/fix/sidebar-collapsing-2

fix: Sidebar collapsing (for v4.5.x)
Yuki Takei 4 лет назад
Родитель
Сommit
2698e29087
2 измененных файлов с 30 добавлено и 6 удалено
  1. 30 3
      packages/app/src/components/Sidebar.tsx
  2. 0 3
      packages/app/src/styles/_sidebar.scss

+ 30 - 3
packages/app/src/components/Sidebar.tsx

@@ -20,12 +20,18 @@ import StickyStretchableScroller from './StickyStretchableScroller';
 
 
 const sidebarMinWidth = 240;
 const sidebarMinWidth = 240;
 const sidebarMinimizeWidth = 20;
 const sidebarMinimizeWidth = 20;
+const sidebarFixedWidthInDrawerMode = 320;
+
 
 
 const GlobalNavigation = () => {
 const GlobalNavigation = () => {
+  const { data: isDrawerMode } = useDrawerMode();
   const { data: currentContents } = useCurrentSidebarContents();
   const { data: currentContents } = useCurrentSidebarContents();
   const { data: isCollapsed, mutate: mutateSidebarCollapsed } = useSidebarCollapsed();
   const { data: isCollapsed, mutate: mutateSidebarCollapsed } = useSidebarCollapsed();
 
 
   const itemSelectedHandler = useCallback((selectedContents) => {
   const itemSelectedHandler = useCallback((selectedContents) => {
+    if (isDrawerMode) {
+      return;
+    }
 
 
     let newValue = false;
     let newValue = false;
 
 
@@ -38,7 +44,7 @@ const GlobalNavigation = () => {
     mutateSidebarCollapsed(newValue, false);
     mutateSidebarCollapsed(newValue, false);
     scheduleToPutUserUISettings({ isSidebarCollapsed: newValue });
     scheduleToPutUserUISettings({ isSidebarCollapsed: newValue });
 
 
-  }, [currentContents, isCollapsed, mutateSidebarCollapsed]);
+  }, [currentContents, isCollapsed, isDrawerMode, mutateSidebarCollapsed]);
 
 
   return <SidebarNav onItemSelected={itemSelectedHandler} />;
   return <SidebarNav onItemSelected={itemSelectedHandler} />;
 };
 };
@@ -244,6 +250,10 @@ const Sidebar: FC<Props> = (props: Props) => {
 
 
   // open/close resizable container
   // open/close resizable container
   useEffect(() => {
   useEffect(() => {
+    if (!isCollapsed) {
+      return;
+    }
+
     if (isHoverOnResizableContainer) {
     if (isHoverOnResizableContainer) {
       // schedule to open
       // schedule to open
       timeoutIdRef.current = setTimeout(() => {
       timeoutIdRef.current = setTimeout(() => {
@@ -262,7 +272,24 @@ const Sidebar: FC<Props> = (props: Props) => {
       setContentWidth(sidebarMinimizeWidth);
       setContentWidth(sidebarMinimizeWidth);
       timeoutIdRef.current = undefined;
       timeoutIdRef.current = undefined;
     }
     }
-  }, [isHover, isHoverOnResizableContainer, currentProductNavWidth, setContentWidth]);
+  }, [isCollapsed, isHover, isHoverOnResizableContainer, currentProductNavWidth, setContentWidth]);
+
+  // open/close resizable container when drawer mode
+  useEffect(() => {
+    if (isDrawerMode) {
+      setContentWidth(sidebarFixedWidthInDrawerMode);
+    }
+    else if (isCollapsed) {
+      setContentWidth(sidebarMinimizeWidth);
+    }
+    else {
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      setContentWidth(currentProductNavWidth!);
+    }
+  }, [currentProductNavWidth, isCollapsed, isDrawerMode, setContentWidth]);
+
+
+  const showContents = isDrawerMode || isHover || !isCollapsed;
 
 
   return (
   return (
     <>
     <>
@@ -285,7 +312,7 @@ const Sidebar: FC<Props> = (props: Props) => {
                 style={{ width: isCollapsed ? sidebarMinimizeWidth : currentProductNavWidth }}
                 style={{ width: isCollapsed ? sidebarMinimizeWidth : currentProductNavWidth }}
               >
               >
                 <div className="grw-contextual-navigation-child">
                 <div className="grw-contextual-navigation-child">
-                  <div role="group" className={`grw-contextual-navigation-sub ${!isHover && isCollapsed ? 'collapsed' : ''}`}>
+                  <div role="group" className={`grw-contextual-navigation-sub ${showContents ? '' : 'd-none'}`}>
                     <SidebarContentsWrapper></SidebarContentsWrapper>
                     <SidebarContentsWrapper></SidebarContentsWrapper>
                   </div>
                   </div>
                 </div>
                 </div>

+ 0 - 3
packages/app/src/styles/_sidebar.scss

@@ -129,9 +129,6 @@
             width: 100%;
             width: 100%;
             height: 100%;
             height: 100%;
             overflow: hidden auto;
             overflow: hidden auto;
-            &.collapsed {
-              display: none;
-            }
           }
           }
         }
         }
       }
       }