Skip to content

Commit faf59eb

Browse files
committed
leave animation
1 parent ee3a18b commit faf59eb

File tree

4 files changed

+16
-43
lines changed

4 files changed

+16
-43
lines changed

examples/custom-icon.js

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable no-console, no-param-reassign */
22
import * as React from 'react';
3-
import animate from 'css-animation';
43
import Menu, { SubMenu, Item as MenuItem, Divider } from '../src';
54
import '../assets/index.less';
65

@@ -45,42 +44,17 @@ function expandIcon(props) {
4544
});
4645
}
4746

48-
const animation = {
49-
enter(node, done) {
50-
let height;
51-
return animate(node, 'rc-menu-collapse', {
52-
start() {
53-
height = node.offsetHeight;
54-
node.style.height = 0;
55-
},
56-
active() {
57-
node.style.height = `${height}px`;
58-
},
59-
end() {
60-
node.style.height = '';
61-
done();
62-
},
63-
});
64-
},
65-
66-
appear(...args) {
67-
return this.enter(...args);
68-
},
47+
const collapseNode = () => ({ height: 0 });
48+
const expandNode = node => ({ height: node.scrollHeight });
6949

70-
leave(node, done) {
71-
return animate(node, 'rc-menu-collapse', {
72-
start() {
73-
node.style.height = `${node.offsetHeight}px`;
74-
},
75-
active() {
76-
node.style.height = 0;
77-
},
78-
end() {
79-
node.style.height = '';
80-
done();
81-
},
82-
});
83-
},
50+
const inlineMotion = {
51+
motionName: 'rc-menu-collapse',
52+
onAppearStart: collapseNode,
53+
onAppearActive: expandNode,
54+
onEnterStart: collapseNode,
55+
onEnterActive: expandNode,
56+
onLeaveStart: expandNode,
57+
onLeaveActive: collapseNode,
8458
};
8559

8660
class Demo extends React.Component {
@@ -149,7 +123,7 @@ class Demo extends React.Component {
149123
const inlineMenu = this.renderCommonMenu({
150124
mode: 'inline',
151125
defaultOpenKeys: ['1'],
152-
openAnimation: animation,
126+
motion: inlineMotion,
153127
itemIcon,
154128
expandIcon,
155129
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"rc-animate": "^2.10.1",
5353
"rc-trigger": "^2.3.0",
5454
"rc-util": "^4.13.0",
55-
"resize-observer-polyfill": "^1.5.0"
55+
"resize-observer-polyfill": "^1.5.0",
56+
"shallowequal": "^1.1.0"
5657
},
5758
"devDependencies": {
5859
"@types/jest": "^24.0.18",

src/SubMenu.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ export interface SubMenuProps {
102102
className?: string;
103103
popupClassName?: string;
104104

105-
// [Legacy]
106-
// openTransitionName?: string;
107-
// openAnimation?: OpenAnimation;
108105
motion?: MotionType;
109106
}
110107

src/SubPopupMenu.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { connect } from 'mini-store';
33
import KeyCode from 'rc-util/lib/KeyCode';
44
import createChainedFunction from 'rc-util/lib/createChainedFunction';
5+
import shallowEqual from 'shallowequal';
56
import classNames from 'classnames';
67
import {
78
getKeyFromChildrenIndex,
@@ -15,7 +16,6 @@ import {
1516
SelectEventHandler,
1617
OpenEventHandler,
1718
DestroyEventHandler,
18-
OpenAnimation,
1919
MiniStore,
2020
MenuMode,
2121
LegacyFunctionRef,
@@ -193,7 +193,8 @@ export class SubPopupMenu extends React.Component<SubPopupMenuProps> {
193193
return (
194194
this.props.visible ||
195195
nextProps.visible ||
196-
this.props.className !== nextProps.className
196+
this.props.className !== nextProps.className ||
197+
!shallowEqual(this.props.style, nextProps.style)
197198
);
198199
}
199200

0 commit comments

Comments
 (0)