Skip to content

Commit 30b43f9

Browse files
committed
fix: click outside
1 parent ef5c9f3 commit 30b43f9

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/components/Menu/index.tsx

+10-11
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,16 @@ export const SubMenu: FunctionComponent<
5252
data-testid={testId}
5353
>
5454
<div>{label}</div>
55-
{open && (
56-
<div
57-
className={classnames(
58-
styles.subMenuContainer,
59-
styles.portal,
60-
portalClassName,
61-
)}
62-
>
63-
<ul className={styles.menu}>{children}</ul>
64-
</div>
65-
)}
55+
<div
56+
className={classnames(
57+
styles.subMenuContainer,
58+
styles.portal,
59+
portalClassName,
60+
)}
61+
hidden={!open}
62+
>
63+
<ul className={styles.menu}>{children}</ul>
64+
</div>
6665
</li>
6766
);
6867
};

src/components/Select/index.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { OptionItem } from '../../types';
1010
import styles from './index.module.css';
1111
import { Icon } from '../BaseIcon';
1212
import { Button } from '../Button';
13+
import { useClickOutside } from '../../containers/hooks';
1314

1415
export interface SelectProps {
1516
value?: string | number;
@@ -158,8 +159,12 @@ export const SelectList: FunctionComponent<
158159
},
159160
[onChange],
160161
);
162+
const ref = useClickOutside(true, () => {
163+
setActive(false);
164+
});
161165
return (
162166
<div
167+
ref={ref}
163168
className={classnames(styles['select-list-container'], className, {
164169
[styles.active]: active,
165170
})}

src/containers/SheetBar/index.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Button, Icon, SelectPopup } from '../../components';
99
import { SheetBarContextMenu } from './SheetBarContextMenu';
1010
import styles from './index.module.css';
1111
import { useCoreStore, useExcel } from '../../containers/store';
12+
import { useClickOutside } from '../hooks';
1213

1314
export const SheetBarContainer: React.FunctionComponent<React.PropsWithChildren> =
1415
memo(({ children }) => {
@@ -66,9 +67,14 @@ export const SheetBarContainer: React.FunctionComponent<React.PropsWithChildren>
6667
const togglePopup = useCallback(() => {
6768
setPopupActive((v) => !v);
6869
}, []);
70+
71+
const ref = useClickOutside(popupActive, () => {
72+
setPopupActive(false);
73+
});
74+
6975
return (
7076
<div className={styles['sheet-bar-wrapper']} data-testid="sheet-bar">
71-
<div>
77+
<div ref={ref}>
7278
<Button
7379
onClick={togglePopup}
7480
className={styles['menu-button']}

src/containers/ToolBar/Border.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export const BorderToolBar = memo(() => {
172172
};
173173
record[type]();
174174
};
175+
175176
return (
176177
<div className={styles['container']}>
177178
<Button

0 commit comments

Comments
 (0)