Skip to content

Perf menu #3177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const FormProps = {
prefixCls: PropTypes.string,
hideRequiredMark: PropTypes.looseBool,
model: PropTypes.object,
rules: { type: Object as PropType<{[k: string]: ValidationRule[] | ValidationRule}> },
rules: { type: Object as PropType<{ [k: string]: ValidationRule[] | ValidationRule }> },
validateMessages: PropTypes.object,
validateOnRuleChange: PropTypes.looseBool,
// 提交失败自动滚动到第一个错误字段
Expand Down
214 changes: 191 additions & 23 deletions components/menu/__tests__/__snapshots__/demo.test.js.snap

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion components/menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ const Menu = defineComponent({
onMouseenter: this.handleMouseEnter,
onTransitionend: this.handleTransitionEnd,
children: getSlot(this),
openTransitionName: '', //issue解决后可去掉openTransitionName https://github.com/vuejs/vue-next/issues/1412
};
if (!hasProp(this, 'selectedKeys')) {
delete menuProps.selectedKeys;
Expand Down
2 changes: 1 addition & 1 deletion components/style/themes/default.less
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
@ease-base-in: cubic-bezier(0.9, 0, 0.3, 0.7);
@ease-out: cubic-bezier(0.215, 0.61, 0.355, 1);
@ease-in: cubic-bezier(0.55, 0.055, 0.675, 0.19);
@ease-in-out: cubic-bezier(0.645, 0.045, 0.355, 1);
@ease-in-out: cubic-bezier(0.25, 0.8, 0.5, 1);
@ease-out-back: cubic-bezier(0.12, 0.4, 0.29, 1.46);
@ease-in-back: cubic-bezier(0.71, -0.46, 0.88, 0.6);
@ease-in-out-back: cubic-bezier(0.71, -0.46, 0.29, 1.46);
Expand Down
12 changes: 11 additions & 1 deletion components/vc-menu/MenuItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ const MenuItem = {
// invoke customized ref to expose component to mixin
this.callRef();
},
mounted() {
this.updateParentMenuSelectedStatus();
},
updated() {
this.updateParentMenuSelectedStatus();
this.$nextTick(() => {
const { active, parentMenu, eventKey } = this;
if (!this.prevActive && active && (!parentMenu || !parentMenu[`scrolled-${eventKey}`])) {
Expand All @@ -58,10 +62,16 @@ const MenuItem = {
this.callRef();
},
beforeUnmount() {
this.updateParentMenuSelectedStatus(false);
const props = this.$props;
this.__emit('destroy', props.eventKey);
},
methods: {
updateParentMenuSelectedStatus(status = this.isSelected) {
if (this.parentMenu && this.parentMenu.setChildrenSelectedStatus) {
this.parentMenu.setChildrenSelectedStatus(this.eventKey, status);
}
},
onKeyDown(e) {
const keyCode = e.keyCode;
if (keyCode === KeyCode.ENTER) {
Expand Down Expand Up @@ -99,7 +109,7 @@ const MenuItem = {
const info = {
key: eventKey,
keyPath: [eventKey],
item: this,
item: { ...this.$props },
domEvent: e,
};

Expand Down
40 changes: 30 additions & 10 deletions components/vc-menu/SubMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import placements from './placements';
import BaseMixin from '../_util/BaseMixin';
import { getComponent, filterEmpty, getSlot, splitAttrs, findDOMNode } from '../_util/props-util';
import { requestAnimationTimeout, cancelAnimationTimeout } from '../_util/requestAnimationTimeout';
import { noop, loopMenuItemRecursively, getMenuIdFromSubMenuEventKey } from './util';
import { noop, getMenuIdFromSubMenuEventKey } from './util';
import { getTransitionProps, Transition } from '../_util/transition';
import { injectExtraPropsKey } from './FunctionProvider';

Expand Down Expand Up @@ -49,7 +49,7 @@ const SubMenu = {
triggerSubMenuAction: PropTypes.string,
popupClassName: PropTypes.string,
getPopupContainer: PropTypes.func,
forceSubMenuRender: PropTypes.looseBool,
forceSubMenuRender: PropTypes.looseBool.def(true),
openAnimation: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
disabled: PropTypes.looseBool,
subMenuOpenDelay: PropTypes.number.def(0.1),
Expand Down Expand Up @@ -100,21 +100,30 @@ const SubMenu = {
this.subMenuTitle = undefined;
return {
// defaultActiveFirst: false,
childrenSelectedStatus: {},
};
},
computed: {
isChildrenSelected() {
return Object.values(this.childrenSelectedStatus).find(status => status);
},
},
mounted() {
this.$nextTick(() => {
this.handleUpdated();
});
this.updateParentMenuSelectedStatus();
},

updated() {
this.$nextTick(() => {
this.handleUpdated();
});
this.updateParentMenuSelectedStatus();
},

beforeUnmount() {
this.updateParentMenuSelectedStatus(false);
const { eventKey } = this;
this.__emit('destroy', eventKey);

Expand All @@ -131,6 +140,18 @@ const SubMenu = {
}
},
methods: {
updateParentMenuSelectedStatus(status = this.isChildrenSelected) {
if (this.parentMenu && this.parentMenu.setChildrenSelectedStatus) {
this.parentMenu.setChildrenSelectedStatus(this.eventKey, status);
}
},
setChildrenSelectedStatus(key, status) {
if (!status) {
delete this.childrenSelectedStatus[key];
} else {
this.childrenSelectedStatus[key] = status;
}
},
handleUpdated() {
const { mode, parentMenu, manualRef } = this;

Expand Down Expand Up @@ -310,11 +331,11 @@ const SubMenu = {
}
},

isChildrenSelected(children) {
const ret = { find: false };
loopMenuItemRecursively(children, this.$props.selectedKeys, ret);
return ret.find;
},
// isChildrenSelected(children) {
// const ret = { find: false };
// loopMenuItemRecursively(children, this.$props.selectedKeys, ret);
// return ret.find;
// },
// isOpen () {
// return this.$props.openKeys.indexOf(this.$props.eventKey) !== -1
// },
Expand Down Expand Up @@ -412,7 +433,6 @@ const SubMenu = {
render() {
const props = { ...this.$props, ...this.$attrs };
const { onEvents } = splitAttrs(props);
const { rootPrefixCls } = this;
const isOpen = props.isOpen;
const prefixCls = this.getPrefixCls();
const isInlineMode = props.mode === 'inline';
Expand All @@ -425,7 +445,7 @@ const SubMenu = {
[this.getOpenClassName()]: isOpen,
[this.getActiveClassName()]: props.active || (isOpen && !isInlineMode),
[this.getDisabledClassName()]: props.disabled,
[this.getSelectedClassName()]: this.isChildrenSelected(childrenTemp),
[this.getSelectedClassName()]: this.isChildrenSelected,
};

if (!this.internalMenuId) {
Expand Down Expand Up @@ -498,7 +518,7 @@ const SubMenu = {
const popupPlacement = popupPlacementMap[props.mode];
const popupAlign = props.popupOffset ? { offset: props.popupOffset } : {};
let popupClassName = props.mode === 'inline' ? '' : props.popupClassName || '';
popupClassName = `${prefixCls}-popup ${rootPrefixCls} ${popupClassName}`;
popupClassName = `${prefixCls}-popup ${popupClassName}`;
const liProps = {
...omit(onEvents, ['onClick']),
...mouseEvents,
Expand Down
2 changes: 1 addition & 1 deletion components/vc-menu/SubPopupMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const SubPopupMenu = {
expandIcon: PropTypes.any,
overflowedIndicator: PropTypes.any,
children: PropTypes.any.def([]),
forceSubMenuRender: PropTypes.looseBool,
forceSubMenuRender: PropTypes.looseBool.def(true),
},
{
prefixCls: 'rc-menu',
Expand Down
2 changes: 1 addition & 1 deletion components/vc-menu/commonPropsType.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {
theme: PropTypes.oneOf(['light', 'dark']).def('light'),
getPopupContainer: PropTypes.func,
openTransitionName: PropTypes.string,
forceSubMenuRender: PropTypes.looseBool,
forceSubMenuRender: PropTypes.looseBool.def(true),
selectable: PropTypes.looseBool,
isRootMenu: PropTypes.looseBool.def(true),
builtinPlacements: PropTypes.object.def(() => ({})),
Expand Down