Skip to content

Commit fa17559

Browse files
committed
fix: animation transition
1 parent 1b876d7 commit fa17559

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

src/containers/AsideNavigation/AsideNavigation.tsx

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,45 @@ enum Panel {
6969
Hotkeys = 'Hotkeys',
7070
}
7171

72+
/**
73+
* HotkeysPanelWrapper creates a render cycle separation between mounting and visibility change.
74+
* This is necessary for smooth animations as HotkeysPanel uses CSSTransition internally.
75+
*
76+
* When a component is both mounted and set to visible at once, CSSTransition can't
77+
* properly sequence its transition classes (panel → panel-active) because it's already active when mounted
78+
* and counts transition as it has already happened.
79+
* This wrapper ensures the component mounts first, then sets visible=true in a subsequent render cycle
80+
* to make transition actually happen.
81+
*/
82+
function HotkeysPanelWrapper({
83+
visiblePanel,
84+
closePanel,
85+
}: {
86+
visiblePanel?: Panel;
87+
closePanel: () => void;
88+
}) {
89+
const [visible, setVisible] = React.useState(false);
90+
91+
React.useEffect(() => {
92+
setVisible(visiblePanel === Panel.Hotkeys);
93+
}, [visiblePanel]);
94+
95+
return (
96+
<HotkeysPanel
97+
visible={visible}
98+
hotkeys={HOTKEYS}
99+
className={b('hotkeys-panel')}
100+
title={
101+
<div className={b('hotkeys-panel-title')}>
102+
{i18n('help-center.footer.shortcuts')}
103+
<Hotkey value={SHORTCUTS_HOTKEY} />
104+
</div>
105+
}
106+
onClose={closePanel}
107+
/>
108+
);
109+
}
110+
72111
export function AsideNavigation(props: AsideNavigationProps) {
73112
const history = useHistory();
74113

@@ -173,17 +212,9 @@ export function AsideNavigation(props: AsideNavigationProps) {
173212
visible: visiblePanel === Panel.Hotkeys,
174213
keepMounted: true,
175214
content: (
176-
<HotkeysPanel
177-
visible={visiblePanel === Panel.Hotkeys}
178-
hotkeys={HOTKEYS}
179-
className={b('hotkeys-panel')}
180-
title={
181-
<div className={b('hotkeys-panel-title')}>
182-
{i18n('help-center.footer.shortcuts')}
183-
<Hotkey value={SHORTCUTS_HOTKEY} />
184-
</div>
185-
}
186-
onClose={closePanel}
215+
<HotkeysPanelWrapper
216+
visiblePanel={visiblePanel}
217+
closePanel={closePanel}
187218
/>
188219
),
189220
},

0 commit comments

Comments
 (0)