Skip to content

Commit 8b55a14

Browse files
oustnZeng Kun
andauthored
feat: Remove menuItem scroll-into-view feature (#318)
* feat: Remove menuItem scroll-into-view feature * test: add MemuItem onDestroy prop test spec Co-authored-by: Zeng Kun <[email protected]>
1 parent 4abc2ca commit 8b55a14

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"rc-trigger": "^4.0.0",
5252
"rc-util": "^4.13.0",
5353
"resize-observer-polyfill": "^1.5.0",
54-
"scroll-into-view-if-needed": "^2.2.20",
5554
"shallowequal": "^1.1.0"
5655
},
5756
"devDependencies": {

src/MenuItem.tsx

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
32
import KeyCode from 'rc-util/lib/KeyCode';
43
import classNames from 'classnames';
5-
import scrollIntoView from 'scroll-into-view-if-needed';
64
import { connect } from 'mini-store';
75
import { noop, menuAllProps } from './util';
86
import {
@@ -66,27 +64,7 @@ export class MenuItem extends React.Component<MenuItemProps> {
6664
this.callRef();
6765
}
6866

69-
componentDidUpdate(prevProps: MenuItemProps) {
70-
const { active, parentMenu, eventKey } = this.props;
71-
// 在 parentMenu 上层保存滚动状态,避免重复的 MenuItem key 导致滚动跳动
72-
// https://github.com/ant-design/ant-design/issues/16181
73-
if (
74-
!prevProps.active &&
75-
active &&
76-
(!parentMenu || !parentMenu[`scrolled-${eventKey}`])
77-
) {
78-
if (this.node) {
79-
scrollIntoView(this.node, {
80-
scrollMode: 'if-needed',
81-
// eslint-disable-next-line react/no-find-dom-node
82-
boundary: ReactDOM.findDOMNode(parentMenu) as Element,
83-
block: 'nearest',
84-
});
85-
parentMenu[`scrolled-${eventKey}`] = true;
86-
}
87-
} else if (parentMenu && parentMenu[`scrolled-${eventKey}`]) {
88-
delete parentMenu[`scrolled-${eventKey}`];
89-
}
67+
componentDidUpdate() {
9068
this.callRef();
9169
}
9270

tests/MenuItem.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,21 @@ describe('MenuItem', () => {
209209

210210
expect(wrapper.render()).toMatchSnapshot();
211211
});
212+
213+
it('should call onDestroy before unmount', () => {
214+
const callback = jest.fn();
215+
216+
const wrapper = mount(
217+
<Menu>
218+
<MenuItem role="option" key="item" onDestroy={callback}>
219+
<span>Item content</span>
220+
</MenuItem>
221+
</Menu>,
222+
);
223+
224+
wrapper.unmount();
225+
226+
expect(callback).toHaveBeenCalled();
227+
});
212228
});
213229
});

0 commit comments

Comments
 (0)