Skip to content

Commit 77f1b58

Browse files
committed
chore: directly use triggerElement for querySelector instead of children
1 parent 8fc31af commit 77f1b58

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

packages/components/popup/Popup.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export interface PopupRef {
4040
setVisible: (visible: boolean) => void;
4141
}
4242

43+
// 默认动画时长
44+
const DEFAULT_TRANSITION_TIMEOUT = 180;
45+
4346
const Popup = forwardRef<PopupRef, PopupProps>((originalProps, ref) => {
4447
const props = useDefaultProps<PopupProps>(originalProps, popupDefaultProps);
4548
const {
@@ -78,9 +81,6 @@ const Popup = forwardRef<PopupRef, PopupProps>((originalProps, ref) => {
7881
const contentRef = useRef(null); // 内容部分
7982
const popperRef = useRef(null); // 保存 popper 实例
8083

81-
// 默认动画时长
82-
const DEFAULT_TRANSITION_TIMEOUT = 180;
83-
8484
// 处理切换 panel 为 null 和正常内容动态切换的情况
8585
useEffect(() => {
8686
if (!content && hideEmptyPopup) {
@@ -101,7 +101,6 @@ const Popup = forwardRef<PopupRef, PopupProps>((originalProps, ref) => {
101101
);
102102

103103
const { triggerElementIsString, getTriggerElement, getTriggerNode } = useTrigger({
104-
children,
105104
triggerElement,
106105
content,
107106
disabled,

packages/components/popup/hooks/useTrigger.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ import useConfig from '../../hooks/useConfig';
55

66
const ESC_KEY = 'Escape';
77

8-
export default function useTrigger({
9-
children,
10-
triggerElement,
11-
content,
12-
disabled,
13-
trigger,
14-
visible,
15-
onVisibleChange,
16-
delay,
17-
}) {
8+
export default function useTrigger({ triggerElement, content, disabled, trigger, visible, onVisibleChange, delay }) {
189
const { classPrefix } = useConfig();
1910

2011
const triggerElementIsString = typeof triggerElement === 'string';
@@ -47,14 +38,16 @@ export default function useTrigger({
4738
const getTriggerElement = useCallback(() => {
4839
let element: HTMLElement | null = null;
4940
if (triggerElementIsString) {
50-
element = document.querySelector(children);
41+
element = document.querySelector(triggerElement);
5142
} else {
5243
element = getRefDom(triggerRef);
5344
}
5445
return element;
5546
// eslint-disable-next-line react-hooks/exhaustive-deps
5647
}, []);
5748

49+
useEffect(() => clearTimeout(visibleTimer.current), []);
50+
5851
useEffect(() => {
5952
if (!shouldToggle) return;
6053

@@ -205,13 +198,6 @@ export default function useTrigger({
205198
};
206199
}, [visible, classPrefix, getTriggerElement]);
207200

208-
useEffect(
209-
() => () => {
210-
clearTimeout(visibleTimer.current);
211-
},
212-
[],
213-
);
214-
215201
function getTriggerNode(children: React.ReactNode) {
216202
if (triggerElementIsString) return;
217203

0 commit comments

Comments
 (0)