Skip to content

Commit 0c71552

Browse files
committed
fix: motion should mark as init for first mount
1 parent 6b021c8 commit 0c71552

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

.dumirc.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ export default defineConfig({
1212
name: 'Trigger',
1313
logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
1414
},
15+
styles: [
16+
`
17+
.dumi-default-previewer-demo {
18+
position: relative;
19+
min-height: 300px;
20+
}
21+
`,
22+
]
1523
});

docs/examples/inside.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default () => {
5151
return (
5252
<div
5353
style={{
54-
position: 'fixed',
54+
position: 'absolute',
5555
inset: 64,
5656
overflow: `auto`,
5757
border: '1px solid red',

src/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ export interface TriggerProps {
121121
// mobile?: MobileConfig;
122122
}
123123

124-
export function generateTrigger(PortalComponent: React.ComponentType<any> = Portal) {
124+
export function generateTrigger(
125+
PortalComponent: React.ComponentType<any> = Portal,
126+
) {
125127
const Trigger = React.forwardRef<TriggerRef, TriggerProps>((props, ref) => {
126128
const {
127129
prefixCls = 'rc-trigger-popup',
@@ -303,9 +305,13 @@ export function generateTrigger(PortalComponent: React.ComponentType<any> = Port
303305

304306
// ========================== Motion ============================
305307
const [inMotion, setInMotion] = React.useState(false);
308+
const mountRef = React.useRef(true);
306309

307310
useLayoutEffect(() => {
308-
setInMotion(true);
311+
if (!mountRef.current || mergedOpen) {
312+
setInMotion(true);
313+
}
314+
mountRef.current = true;
309315
}, [mergedOpen]);
310316

311317
const [motionPrepareResolve, setMotionPrepareResolve] =

tests/motion.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Trigger.Motion', () => {
3939
fireEvent.click(target);
4040

4141
expect(document.querySelector('.rc-trigger-popup')).toHaveClass(
42-
'bamboo-enter',
42+
'bamboo-appear',
4343
);
4444

4545
expect(

0 commit comments

Comments
 (0)