Skip to content

Commit 851b78a

Browse files
flopsbenax-se
authored andcommitted
fix(Drawer): initial hidden state when keepMouted enabled (#324)
* fix(Drawer): initial hidden state when keepMouted true * chore(Drawer): update test screenshots
1 parent b857445 commit 851b78a

7 files changed

+17
-4
lines changed

src/components/Drawer/Drawer.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ $block: '.#{variables.$ns}drawer';
7777
}
7878

7979
&__item-transition-exit-done,
80-
&__item-transition_direction_right-exit-done {
80+
&__item-transition_direction_right-exit-done,
81+
&__item_hidden {
8182
visibility: hidden;
8283
}
8384

src/components/Drawer/Drawer.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ export const DrawerItem = React.forwardRef<HTMLDivElement, DrawerItemProps>(
8080
keepMounted = false,
8181
} = props;
8282

83+
const [isInitialRender, setInitialRender] = React.useState(true);
8384
const itemRef = React.useRef<HTMLDivElement>(null);
8485
const handleRef = useForkRef(ref, itemRef);
86+
8587
const cssDirection = direction === 'left' ? undefined : direction;
8688

8789
const {resizedWidth, resizerHandlers} = useResizableDrawerItem({
@@ -92,6 +94,10 @@ export const DrawerItem = React.forwardRef<HTMLDivElement, DrawerItemProps>(
9294
onResize,
9395
});
9496

97+
React.useEffect(() => {
98+
setInitialRender(true);
99+
}, [direction]);
100+
95101
const resizerElement = resizable ? (
96102
<div className={b('resizer', {direction})} {...resizerHandlers}>
97103
<div className={b('resizer-handle')} />
@@ -106,10 +112,16 @@ export const DrawerItem = React.forwardRef<HTMLDivElement, DrawerItemProps>(
106112
unmountOnExit={!keepMounted}
107113
classNames={b('item-transition', {direction: cssDirection})}
108114
nodeRef={itemRef}
115+
onEnter={() => setInitialRender(false)}
116+
onExit={() => setInitialRender(false)}
109117
>
110118
<div
111119
ref={handleRef}
112-
className={b('item', {direction: cssDirection}, className)}
120+
className={b(
121+
'item',
122+
{direction: cssDirection, hidden: isInitialRender && !visible},
123+
[className],
124+
)}
113125
style={{width: resizable ? `${resizedWidth}px` : undefined}}
114126
>
115127
{resizerElement}

src/components/Drawer/__stories__/DrawerShowcase.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export function DrawerShowcase() {
1616
const [direction, setDirection] = React.useState<string>('left');
1717
const [direction2, setDirection2] = React.useState<string>('left');
1818

19-
const [keepMountedGlobal, setKeepMountedGlobal] = React.useState<boolean>(false);
20-
const [keepMounted1, setKeepMounted1] = React.useState<boolean>(false);
19+
const [keepMountedGlobal, setKeepMountedGlobal] = React.useState<boolean>(true);
20+
const [keepMounted1, setKeepMounted1] = React.useState<boolean>(true);
2121

2222
const hideAll = React.useCallback(() => {
2323
setVisible1(false);

0 commit comments

Comments
 (0)