Skip to content

Commit

Permalink
fix: motion should mark as init for first mount
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Feb 15, 2023
1 parent 6b021c8 commit 0c71552
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ export default defineConfig({
name: 'Trigger',
logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
},
styles: [
`
.dumi-default-previewer-demo {
position: relative;
min-height: 300px;
}
`,
]
});
2 changes: 1 addition & 1 deletion docs/examples/inside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default () => {
return (
<div
style={{
position: 'fixed',
position: 'absolute',
inset: 64,
overflow: `auto`,
border: '1px solid red',
Expand Down
10 changes: 8 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ export interface TriggerProps {
// mobile?: MobileConfig;
}

export function generateTrigger(PortalComponent: React.ComponentType<any> = Portal) {
export function generateTrigger(
PortalComponent: React.ComponentType<any> = Portal,
) {
const Trigger = React.forwardRef<TriggerRef, TriggerProps>((props, ref) => {
const {
prefixCls = 'rc-trigger-popup',
Expand Down Expand Up @@ -303,9 +305,13 @@ export function generateTrigger(PortalComponent: React.ComponentType<any> = Port

// ========================== Motion ============================
const [inMotion, setInMotion] = React.useState(false);
const mountRef = React.useRef(true);

useLayoutEffect(() => {
setInMotion(true);
if (!mountRef.current || mergedOpen) {
setInMotion(true);
}
mountRef.current = true;
}, [mergedOpen]);

const [motionPrepareResolve, setMotionPrepareResolve] =
Expand Down
2 changes: 1 addition & 1 deletion tests/motion.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Trigger.Motion', () => {
fireEvent.click(target);

expect(document.querySelector('.rc-trigger-popup')).toHaveClass(
'bamboo-enter',
'bamboo-appear',
);

expect(
Expand Down

0 comments on commit 0c71552

Please sign in to comment.