Skip to content

Commit 12c41b6

Browse files
committed
chore: update demo
1 parent 0161493 commit 12c41b6

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

docs/examples/two-buttons.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ const builtinPlacements = {
2121
},
2222
};
2323

24-
function getPopupContainer(trigger) {
25-
return trigger.parentNode;
26-
}
27-
2824
const MovingPopupDemo = () => {
2925
const [useUniqueProvider, setUseUniqueProvider] = useState(true);
30-
26+
3127
const content = (
3228
<div style={{ margin: 100 }}>
3329
<div style={{ marginBottom: 20 }}>
@@ -42,10 +38,10 @@ const MovingPopupDemo = () => {
4238
</div>
4339
<div style={{ display: 'flex', gap: 20 }}>
4440
<Trigger
41+
mouseLeaveDelay={0.3}
4542
action={['hover']}
4643
popupPlacement="top"
4744
builtinPlacements={builtinPlacements}
48-
getPopupContainer={getPopupContainer}
4945
popupMotion={{
5046
motionName: 'rc-trigger-popup-zoom',
5147
}}
@@ -59,12 +55,12 @@ const MovingPopupDemo = () => {
5955
>
6056
<button type="button">左侧按钮</button>
6157
</Trigger>
62-
58+
6359
<Trigger
60+
mouseLeaveDelay={0.3}
6461
action={['hover']}
6562
popupPlacement="top"
6663
builtinPlacements={builtinPlacements}
67-
getPopupContainer={getPopupContainer}
6864
popupMotion={{
6965
motionName: 'rc-trigger-popup-zoom',
7066
}}
@@ -81,8 +77,12 @@ const MovingPopupDemo = () => {
8177
</div>
8278
</div>
8379
);
84-
85-
return useUniqueProvider ? <UniqueProvider>{content}</UniqueProvider> : content;
80+
81+
return useUniqueProvider ? (
82+
<UniqueProvider>{content}</UniqueProvider>
83+
) : (
84+
content
85+
);
8686
};
8787

8888
export default MovingPopupDemo;

src/UniqueProvider/index.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import TriggerContext, {
99
import useDelay from '../hooks/useDelay';
1010
import useAlign from '../hooks/useAlign';
1111
import Popup from '../Popup';
12+
import { useEvent } from '@rc-component/util';
1213

1314
export interface UniqueProviderProps {
1415
children: React.ReactNode;
@@ -36,9 +37,19 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
3637
const hide = (delay: number) => {
3738
delayInvoke(() => {
3839
setOpen(false);
40+
// 不要立即清空 target, currentNode, options,等动画结束后再清空
3941
}, delay);
4042
};
4143

44+
// 动画完成后的回调
45+
const onVisibleChanged = useEvent((visible: boolean) => {
46+
if (!visible) {
47+
setTarget(null);
48+
setCurrentNode(null);
49+
setOptions(null);
50+
}
51+
});
52+
4253
// =========================== Align ============================
4354
const [
4455
ready,
@@ -48,9 +59,9 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
4859
offsetB,
4960
arrowX,
5061
arrowY, // scaleX - not used in UniqueProvider
51-
// scaleY - not used in UniqueProvider
5262
,
5363
,
64+
// scaleY - not used in UniqueProvider
5465
alignInfo,
5566
onAlign,
5667
] = useAlign(
@@ -95,15 +106,16 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
95106
<Popup
96107
ref={setPopupEle}
97108
portal={Portal}
98-
prefixCls={options.prefixCls || 'rc-trigger-popup'}
109+
prefixCls={options.prefixCls}
99110
popup={currentNode}
100111
className={options.popupClassName}
101112
style={options.popupStyle}
102113
target={target}
103114
open={open}
104-
keepDom={false}
115+
keepDom={true}
105116
fresh={true}
106-
onVisibleChanged={() => {}}
117+
autoDestroy={false}
118+
onVisibleChanged={onVisibleChanged}
107119
ready={ready}
108120
offsetX={offsetX}
109121
offsetY={offsetY}

0 commit comments

Comments
 (0)