Skip to content

Commit

Permalink
refactor: remove timer
Browse files Browse the repository at this point in the history
  • Loading branch information
wewoor committed Nov 24, 2020
1 parent d716817 commit 05099b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { classNames, prefixClaName } from 'mo/common/className';
import { MenuItem } from './menuItem';
import { ISubMenu, MenuMode, SubMenu } from './subMenu';


export interface IMenu extends ISubMenu {}

export const defaultMenuClassName = 'menu';
Expand Down
19 changes: 11 additions & 8 deletions src/components/menu/subMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function isHorizontal(mode: MenuMode) {
export function isVertical(mode: MenuMode) {
return mode === MenuMode.Horizontal;
}

export interface ISubMenu extends IMenuItem {
/**
* The event of show subMenu, default value is 'hover'
Expand Down Expand Up @@ -57,7 +56,7 @@ const hideAfterLeftWindow = () => {
}
};

let timer;
// let timer;

export function SubMenu(props: React.PropsWithChildren<ISubMenu>) {
const {
Expand All @@ -75,7 +74,7 @@ export function SubMenu(props: React.PropsWithChildren<ISubMenu>) {

const events = {
onMouseOver: (event: React.MouseEvent<any, any>) => {
clearTimeout(timer);
// clearTimeout(timer);

const nextMenuItem = findParentByClassName<HTMLLIElement>(
event.target,
Expand All @@ -95,9 +94,14 @@ export function SubMenu(props: React.PropsWithChildren<ISubMenu>) {
);

if (
prevMenuItem &&
prevSubMenu &&
!prevMenuItem.contains(nextMenuItem)
(
prevMenuItem &&
prevSubMenu &&
!prevMenuItem.contains(nextMenuItem)
) ||
(
!prevMenuItem && !prevSubMenu
)
) {
hideAll();
}
Expand Down Expand Up @@ -147,7 +151,6 @@ export function SubMenu(props: React.PropsWithChildren<ISubMenu>) {
!prevMenuItem.contains(nextMenuItem)
) {
hideAll();
// delayHide(prevMenuItem);
}
},
onClick: function (event: React.MouseEvent) {
Expand All @@ -163,7 +166,7 @@ export function SubMenu(props: React.PropsWithChildren<ISubMenu>) {
document.removeEventListener('contextmenu', hideAll);
window.removeEventListener('click', hideAll);
window.removeEventListener('visibilitychange', hideAfterLeftWindow);
clearTimeout(timer);
// clearTimeout(timer);
};
}, []);

Expand Down

0 comments on commit 05099b0

Please sign in to comment.