diff --git a/src/components/Drawer/Drawer.tsx b/src/components/Drawer/Drawer.tsx index 5db957419..95defbbcf 100644 --- a/src/components/Drawer/Drawer.tsx +++ b/src/components/Drawer/Drawer.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {Xmark} from '@gravity-ui/icons'; import {DrawerItem, Drawer as GravityDrawer} from '@gravity-ui/navigation'; -import {ActionTooltip, Button, Flex, Icon, Text} from '@gravity-ui/uikit'; +import {ActionTooltip, Button, Flex, Icon, Portal, Text} from '@gravity-ui/uikit'; import {cn} from '../../utils/cn'; import {isNumeric} from '../../utils/utils'; @@ -52,7 +52,7 @@ const DrawerPaneContentWrapper = ({ }); const drawerRef = React.useRef(null); - const {containerWidth} = useDrawerContext(); + const {containerWidth, itemContainerRef} = useDrawerContext(); // Calculate drawer width based on container width percentage if specified const calculatedWidth = React.useMemo(() => { if (isPercentageWidth && containerWidth > 0) { @@ -103,29 +103,36 @@ const DrawerPaneContentWrapper = ({ (event.nativeEvent as DrawerEvent)._capturedInsideDrawer = true; }; + const itemContainer = itemContainerRef?.current; + if (!itemContainer) { + return null; + } + return ( - - + -
- {children} -
-
-
+ +
+ {children} +
+
+ + ); }; diff --git a/src/components/Drawer/DrawerContext.tsx b/src/components/Drawer/DrawerContext.tsx index b54d06e39..495f28e8a 100644 --- a/src/components/Drawer/DrawerContext.tsx +++ b/src/components/Drawer/DrawerContext.tsx @@ -8,11 +8,13 @@ const b = cn('ydb-drawer'); export interface DrawerContextType { containerWidth: number; + itemContainerRef: React.RefObject | null; setContainerWidth: React.Dispatch>; } const DrawerContext = React.createContext({ containerWidth: 0, + itemContainerRef: null, setContainerWidth: () => {}, }); @@ -24,6 +26,7 @@ interface DrawerContextProviderProps { export const DrawerContextProvider = ({children, className}: DrawerContextProviderProps) => { const [containerWidth, setContainerWidth] = React.useState(0); const containerRef = React.useRef(null); + const itemContainerRef = React.useRef(null); React.useEffect(() => { if (!containerRef.current) { @@ -55,6 +58,7 @@ export const DrawerContextProvider = ({children, className}: DrawerContextProvid () => ({ containerWidth, setContainerWidth, + itemContainerRef, }), [containerWidth], ); @@ -63,6 +67,11 @@ export const DrawerContextProvider = ({children, className}: DrawerContextProvid
{children} + {/* + Children styles should not affect drawer container behaviour + So we mount it out of children in a separate portal + */} +
);