Skip to content

Commit

Permalink
fix close animation flash #219 #218
Browse files Browse the repository at this point in the history
  • Loading branch information
fkhadra committed Nov 3, 2022
1 parent 6c1e043 commit 59ad34f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/Menu.tsx
Expand Up @@ -27,6 +27,7 @@ import {
isFn,
isStr,
} from './utils';
import { flushSync } from 'react-dom';

export interface MenuProps
extends Omit<React.HTMLAttributes<HTMLElement>, 'id'> {
Expand Down Expand Up @@ -236,7 +237,7 @@ export const Menu: React.FC<MenuProps> = ({

// prevent react from batching the state update
// if the menu is already visible we have to recompute bounding rect based on position
setTimeout(() => {
flushSync(() => {
setState({
visible: true,
willLeave: false,
Expand All @@ -245,7 +246,7 @@ export const Menu: React.FC<MenuProps> = ({
triggerEvent: event,
propsFromTrigger: props,
});
}, 0);
});
}

function hide(event?: Event) {
Expand All @@ -268,7 +269,7 @@ export const Menu: React.FC<MenuProps> = ({

function handleAnimationEnd() {
if (state.willLeave && state.visible) {
setState({ visible: false, willLeave: false });
flushSync(() => setState({ visible: false, willLeave: false }));
}
}

Expand Down

0 comments on commit 59ad34f

Please sign in to comment.