2019-01-12 11:33:27 +08:00
|
|
|
import omit from 'omit.js';
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import Trigger from '../vc-trigger';
|
|
|
|
import KeyCode from '../_util/KeyCode';
|
|
|
|
import { connect } from '../_util/store';
|
|
|
|
import SubPopupMenu from './SubPopupMenu';
|
|
|
|
import placements from './placements';
|
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
2020-01-19 16:58:38 +08:00
|
|
|
import { getComponentFromProp, filterEmpty, getListeners } from '../_util/props-util';
|
2019-01-12 11:33:27 +08:00
|
|
|
import { requestAnimationTimeout, cancelAnimationTimeout } from '../_util/requestAnimationTimeout';
|
|
|
|
import { noop, loopMenuItemRecursively, getMenuIdFromSubMenuEventKey } from './util';
|
|
|
|
import getTransitionProps from '../_util/getTransitionProps';
|
|
|
|
|
|
|
|
let guid = 0;
|
2017-12-08 14:31:53 +08:00
|
|
|
|
|
|
|
const popupPlacementMap = {
|
|
|
|
horizontal: 'bottomLeft',
|
|
|
|
vertical: 'rightTop',
|
|
|
|
'vertical-left': 'rightTop',
|
|
|
|
'vertical-right': 'leftTop',
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2018-09-05 21:28:54 +08:00
|
|
|
const updateDefaultActiveFirst = (store, eventKey, defaultActiveFirst) => {
|
2019-01-12 11:33:27 +08:00
|
|
|
const menuId = getMenuIdFromSubMenuEventKey(eventKey);
|
|
|
|
const state = store.getState();
|
2018-09-05 21:28:54 +08:00
|
|
|
store.setState({
|
|
|
|
defaultActiveFirst: {
|
|
|
|
...state.defaultActiveFirst,
|
|
|
|
[menuId]: defaultActiveFirst,
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
|
|
|
};
|
2018-09-05 21:28:54 +08:00
|
|
|
|
|
|
|
const SubMenu = {
|
2017-12-29 18:45:11 +08:00
|
|
|
name: 'SubMenu',
|
|
|
|
props: {
|
2018-09-05 21:28:54 +08:00
|
|
|
parentMenu: PropTypes.object,
|
2018-01-17 16:12:53 +08:00
|
|
|
title: PropTypes.any,
|
2018-01-03 18:30:12 +08:00
|
|
|
selectedKeys: PropTypes.array.def([]),
|
|
|
|
openKeys: PropTypes.array.def([]),
|
|
|
|
openChange: PropTypes.func.def(noop),
|
2017-12-08 14:31:53 +08:00
|
|
|
rootPrefixCls: PropTypes.string,
|
2018-02-22 12:07:37 +08:00
|
|
|
eventKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2017-12-08 14:31:53 +08:00
|
|
|
multiple: PropTypes.bool,
|
|
|
|
active: PropTypes.bool, // TODO: remove
|
2018-09-05 21:28:54 +08:00
|
|
|
isRootMenu: PropTypes.bool.def(false),
|
2018-01-09 14:21:15 +08:00
|
|
|
index: PropTypes.number,
|
2017-12-08 14:31:53 +08:00
|
|
|
triggerSubMenuAction: PropTypes.string,
|
2018-01-02 19:05:02 +08:00
|
|
|
popupClassName: PropTypes.string,
|
2018-01-03 18:30:12 +08:00
|
|
|
getPopupContainer: PropTypes.func,
|
2018-01-04 19:06:54 +08:00
|
|
|
forceSubMenuRender: PropTypes.bool,
|
|
|
|
openAnimation: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
|
|
disabled: PropTypes.bool,
|
2018-01-29 19:05:36 +08:00
|
|
|
subMenuOpenDelay: PropTypes.number.def(0.1),
|
2018-01-08 18:31:04 +08:00
|
|
|
subMenuCloseDelay: PropTypes.number.def(0.1),
|
|
|
|
level: PropTypes.number.def(1),
|
|
|
|
inlineIndent: PropTypes.number.def(24),
|
2018-01-17 16:12:53 +08:00
|
|
|
openTransitionName: PropTypes.string,
|
2018-09-05 21:28:54 +08:00
|
|
|
popupOffset: PropTypes.array,
|
|
|
|
isOpen: PropTypes.bool,
|
|
|
|
store: PropTypes.object,
|
2019-01-12 11:33:27 +08:00
|
|
|
mode: PropTypes.oneOf([
|
|
|
|
'horizontal',
|
|
|
|
'vertical',
|
|
|
|
'vertical-left',
|
|
|
|
'vertical-right',
|
|
|
|
'inline',
|
|
|
|
]).def('vertical'),
|
2018-09-05 21:28:54 +08:00
|
|
|
manualRef: PropTypes.func.def(noop),
|
2020-03-07 19:45:13 +08:00
|
|
|
builtinPlacements: PropTypes.object.def(() => ({})),
|
2018-11-05 21:03:25 +08:00
|
|
|
itemIcon: PropTypes.any,
|
|
|
|
expandIcon: PropTypes.any,
|
2020-05-21 23:11:20 +08:00
|
|
|
subMenuKey: PropTypes.string,
|
2018-01-08 18:31:04 +08:00
|
|
|
},
|
2018-01-12 16:10:41 +08:00
|
|
|
mixins: [BaseMixin],
|
2018-01-04 19:06:54 +08:00
|
|
|
isSubMenu: true,
|
2019-01-12 11:33:27 +08:00
|
|
|
data() {
|
|
|
|
const props = this.$props;
|
|
|
|
const store = props.store;
|
|
|
|
const eventKey = props.eventKey;
|
|
|
|
const defaultActiveFirst = store.getState().defaultActiveFirst;
|
|
|
|
let value = false;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
|
|
|
if (defaultActiveFirst) {
|
2019-01-12 11:33:27 +08:00
|
|
|
value = defaultActiveFirst[eventKey];
|
2018-09-05 21:28:54 +08:00
|
|
|
}
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
updateDefaultActiveFirst(store, eventKey, value);
|
2017-12-08 14:31:53 +08:00
|
|
|
return {
|
2018-09-05 21:28:54 +08:00
|
|
|
// defaultActiveFirst: false,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2017-12-08 14:31:53 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
mounted() {
|
2018-02-02 19:09:38 +08:00
|
|
|
this.$nextTick(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
this.handleUpdated();
|
|
|
|
});
|
2017-12-08 14:31:53 +08:00
|
|
|
},
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
updated() {
|
2018-02-02 19:09:38 +08:00
|
|
|
this.$nextTick(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
this.handleUpdated();
|
|
|
|
});
|
2017-12-08 14:31:53 +08:00
|
|
|
},
|
|
|
|
|
2020-06-11 16:13:09 +08:00
|
|
|
beforeUnmount() {
|
2019-01-12 11:33:27 +08:00
|
|
|
const { eventKey } = this;
|
|
|
|
this.__emit('destroy', eventKey);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
|
|
|
/* istanbul ignore if */
|
2018-01-17 16:12:53 +08:00
|
|
|
if (this.minWidthTimeout) {
|
2019-01-12 11:33:27 +08:00
|
|
|
cancelAnimationTimeout(this.minWidthTimeout);
|
|
|
|
this.minWidthTimeout = null;
|
2018-01-17 16:12:53 +08:00
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
|
|
|
/* istanbul ignore if */
|
2018-01-17 16:12:53 +08:00
|
|
|
if (this.mouseenterTimeout) {
|
2019-01-12 11:33:27 +08:00
|
|
|
cancelAnimationTimeout(this.mouseenterTimeout);
|
|
|
|
this.mouseenterTimeout = null;
|
2018-01-08 18:31:04 +08:00
|
|
|
}
|
2017-12-08 14:31:53 +08:00
|
|
|
},
|
2018-01-02 19:05:02 +08:00
|
|
|
methods: {
|
2019-01-12 11:33:27 +08:00
|
|
|
handleUpdated() {
|
|
|
|
const { mode, parentMenu, manualRef } = this.$props;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
|
|
|
// invoke customized ref to expose component to mixin
|
|
|
|
if (manualRef) {
|
2019-01-12 11:33:27 +08:00
|
|
|
manualRef(this);
|
2018-09-05 21:28:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mode !== 'horizontal' || !parentMenu.isRootMenu || !this.isOpen) {
|
2019-01-12 11:33:27 +08:00
|
|
|
return;
|
2018-01-02 19:05:02 +08:00
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
this.minWidthTimeout = requestAnimationTimeout(() => this.adjustWidth(), 0);
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
onKeyDown(e) {
|
|
|
|
const keyCode = e.keyCode;
|
|
|
|
const menu = this.menuInstance;
|
|
|
|
const { store, isOpen } = this.$props;
|
2018-01-02 19:05:02 +08:00
|
|
|
|
|
|
|
if (keyCode === KeyCode.ENTER) {
|
2019-01-12 11:33:27 +08:00
|
|
|
this.onTitleClick(e);
|
|
|
|
updateDefaultActiveFirst(store, this.eventKey, true);
|
|
|
|
return true;
|
2017-12-08 14:31:53 +08:00
|
|
|
}
|
2018-01-02 19:05:02 +08:00
|
|
|
|
|
|
|
if (keyCode === KeyCode.RIGHT) {
|
|
|
|
if (isOpen) {
|
2019-01-12 11:33:27 +08:00
|
|
|
menu.onKeyDown(e);
|
2018-01-02 19:05:02 +08:00
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
this.triggerOpenChange(true);
|
2018-09-05 21:28:54 +08:00
|
|
|
// need to update current menu's defaultActiveFirst value
|
2019-01-12 11:33:27 +08:00
|
|
|
updateDefaultActiveFirst(store, this.eventKey, true);
|
2018-01-02 19:05:02 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
return true;
|
2017-12-08 14:31:53 +08:00
|
|
|
}
|
2018-01-02 19:05:02 +08:00
|
|
|
if (keyCode === KeyCode.LEFT) {
|
2019-01-12 11:33:27 +08:00
|
|
|
let handled;
|
2018-01-02 19:05:02 +08:00
|
|
|
if (isOpen) {
|
2019-01-12 11:33:27 +08:00
|
|
|
handled = menu.onKeyDown(e);
|
2018-01-02 19:05:02 +08:00
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
return undefined;
|
2018-01-02 19:05:02 +08:00
|
|
|
}
|
|
|
|
if (!handled) {
|
2019-01-12 11:33:27 +08:00
|
|
|
this.triggerOpenChange(false);
|
|
|
|
handled = true;
|
2018-01-02 19:05:02 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
return handled;
|
2017-12-08 14:31:53 +08:00
|
|
|
}
|
|
|
|
|
2018-01-02 19:05:02 +08:00
|
|
|
if (isOpen && (keyCode === KeyCode.UP || keyCode === KeyCode.DOWN)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
return menu.onKeyDown(e);
|
2018-01-02 19:05:02 +08:00
|
|
|
}
|
2020-03-07 19:45:13 +08:00
|
|
|
return undefined;
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
onPopupVisibleChange(visible) {
|
|
|
|
this.triggerOpenChange(visible, visible ? 'mouseenter' : 'mouseleave');
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
onMouseEnter(e) {
|
|
|
|
const { eventKey: key, store } = this.$props;
|
|
|
|
updateDefaultActiveFirst(store, key, false);
|
2018-01-12 16:10:41 +08:00
|
|
|
this.__emit('mouseenter', {
|
2018-01-02 19:05:02 +08:00
|
|
|
key,
|
2017-12-08 14:31:53 +08:00
|
|
|
domEvent: e,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
onMouseLeave(e) {
|
|
|
|
const { eventKey, parentMenu } = this;
|
|
|
|
parentMenu.subMenuInstance = this;
|
2018-09-05 21:28:54 +08:00
|
|
|
// parentMenu.subMenuLeaveFn = () => {
|
2018-01-17 16:12:53 +08:00
|
|
|
// // trigger mouseleave
|
|
|
|
// this.__emit('mouseleave', {
|
|
|
|
// key: eventKey,
|
|
|
|
// domEvent: e,
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
this.__emit('mouseleave', {
|
|
|
|
key: eventKey,
|
|
|
|
domEvent: e,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-01-02 19:05:02 +08:00
|
|
|
// prevent popup menu and submenu gap
|
2018-09-05 21:28:54 +08:00
|
|
|
// parentMenu.subMenuLeaveTimer = setTimeout(parentMenu.subMenuLeaveFn, 100)
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
onTitleMouseEnter(domEvent) {
|
|
|
|
const { eventKey: key } = this.$props;
|
2018-01-17 16:12:53 +08:00
|
|
|
// this.clearSubMenuTitleLeaveTimer()
|
2018-01-12 16:10:41 +08:00
|
|
|
this.__emit('itemHover', {
|
2018-01-02 19:05:02 +08:00
|
|
|
key,
|
|
|
|
hover: true,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-01-12 16:10:41 +08:00
|
|
|
this.__emit('titleMouseenter', {
|
2018-01-02 19:05:02 +08:00
|
|
|
key,
|
|
|
|
domEvent,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
onTitleMouseLeave(e) {
|
|
|
|
const { eventKey, parentMenu } = this;
|
|
|
|
parentMenu.subMenuInstance = this;
|
2018-01-17 16:12:53 +08:00
|
|
|
this.__emit('itemHover', {
|
|
|
|
key: eventKey,
|
|
|
|
hover: false,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-01-17 16:12:53 +08:00
|
|
|
this.__emit('titleMouseleave', {
|
|
|
|
key: eventKey,
|
|
|
|
domEvent: e,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
onTitleClick(e) {
|
|
|
|
const { triggerSubMenuAction, eventKey, isOpen, store } = this.$props;
|
2018-12-19 12:22:55 +08:00
|
|
|
this.__emit('titleClick', {
|
2018-01-02 19:05:02 +08:00
|
|
|
key: eventKey,
|
|
|
|
domEvent: e,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-01-02 19:05:02 +08:00
|
|
|
if (triggerSubMenuAction === 'hover') {
|
2019-01-12 11:33:27 +08:00
|
|
|
return;
|
2018-01-02 19:05:02 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
this.triggerOpenChange(!isOpen, 'click');
|
|
|
|
updateDefaultActiveFirst(store, eventKey, false);
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
onSubMenuClick(info) {
|
|
|
|
this.__emit('click', this.addKeyPath(info));
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
getPrefixCls() {
|
|
|
|
return `${this.$props.rootPrefixCls}-submenu`;
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
getActiveClassName() {
|
|
|
|
return `${this.getPrefixCls()}-active`;
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
getDisabledClassName() {
|
|
|
|
return `${this.getPrefixCls()}-disabled`;
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
getSelectedClassName() {
|
|
|
|
return `${this.getPrefixCls()}-selected`;
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
getOpenClassName() {
|
|
|
|
return `${this.$props.rootPrefixCls}-submenu-open`;
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
saveMenuInstance(c) {
|
2018-09-05 21:28:54 +08:00
|
|
|
// children menu instance
|
2019-01-12 11:33:27 +08:00
|
|
|
this.menuInstance = c;
|
2018-09-05 21:28:54 +08:00
|
|
|
},
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
addKeyPath(info) {
|
2018-01-02 19:05:02 +08:00
|
|
|
return {
|
|
|
|
...info,
|
|
|
|
keyPath: (info.keyPath || []).concat(this.$props.eventKey),
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
|
|
|
|
2018-01-17 16:12:53 +08:00
|
|
|
// triggerOpenChange (open, type) {
|
|
|
|
// const key = this.$props.eventKey
|
|
|
|
// this.__emit('openChange', {
|
|
|
|
// key,
|
|
|
|
// item: this,
|
|
|
|
// trigger: type,
|
|
|
|
// open,
|
|
|
|
// })
|
|
|
|
// },
|
2019-01-12 11:33:27 +08:00
|
|
|
triggerOpenChange(open, type) {
|
|
|
|
const key = this.$props.eventKey;
|
2018-01-17 16:12:53 +08:00
|
|
|
const openChange = () => {
|
|
|
|
this.__emit('openChange', {
|
|
|
|
key,
|
|
|
|
item: this,
|
|
|
|
trigger: type,
|
|
|
|
open,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
|
|
|
};
|
2018-01-17 16:12:53 +08:00
|
|
|
if (type === 'mouseenter') {
|
2019-01-12 11:33:27 +08:00
|
|
|
// make sure mouseenter happen after other menu item's mouseleave
|
2018-03-01 19:09:45 +08:00
|
|
|
this.mouseenterTimeout = requestAnimationTimeout(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
openChange();
|
|
|
|
}, 0);
|
2018-01-17 16:12:53 +08:00
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
openChange();
|
2018-01-02 19:05:02 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
isChildrenSelected() {
|
|
|
|
const ret = { find: false };
|
|
|
|
loopMenuItemRecursively(this.$slots.default, this.$props.selectedKeys, ret);
|
|
|
|
return ret.find;
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2018-09-05 21:28:54 +08:00
|
|
|
// isOpen () {
|
|
|
|
// return this.$props.openKeys.indexOf(this.$props.eventKey) !== -1
|
|
|
|
// },
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
adjustWidth() {
|
2018-09-05 21:28:54 +08:00
|
|
|
/* istanbul ignore if */
|
|
|
|
if (!this.$refs.subMenuTitle || !this.menuInstance) {
|
2019-01-12 11:33:27 +08:00
|
|
|
return;
|
2018-09-05 21:28:54 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
const popupMenu = this.menuInstance.$el;
|
2018-09-05 21:28:54 +08:00
|
|
|
if (popupMenu.offsetWidth >= this.$refs.subMenuTitle.offsetWidth) {
|
2019-01-12 11:33:27 +08:00
|
|
|
return;
|
2018-09-05 21:28:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* istanbul ignore next */
|
2019-01-12 11:33:27 +08:00
|
|
|
popupMenu.style.minWidth = `${this.$refs.subMenuTitle.offsetWidth}px`;
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
renderChildren(children) {
|
|
|
|
const props = this.$props;
|
2020-01-19 16:58:38 +08:00
|
|
|
const { select, deselect, openChange } = getListeners(this);
|
2018-01-02 19:05:02 +08:00
|
|
|
const subPopupMenuProps = {
|
|
|
|
props: {
|
|
|
|
mode: props.mode === 'horizontal' ? 'vertical' : props.mode,
|
2018-09-05 21:28:54 +08:00
|
|
|
visible: props.isOpen,
|
2018-01-02 19:05:02 +08:00
|
|
|
level: props.level + 1,
|
|
|
|
inlineIndent: props.inlineIndent,
|
|
|
|
focusable: false,
|
|
|
|
selectedKeys: props.selectedKeys,
|
|
|
|
eventKey: `${props.eventKey}-menu-`,
|
|
|
|
openKeys: props.openKeys,
|
|
|
|
openTransitionName: props.openTransitionName,
|
|
|
|
openAnimation: props.openAnimation,
|
|
|
|
subMenuOpenDelay: props.subMenuOpenDelay,
|
2018-09-05 21:28:54 +08:00
|
|
|
parentMenu: this,
|
2018-01-02 19:05:02 +08:00
|
|
|
subMenuCloseDelay: props.subMenuCloseDelay,
|
|
|
|
forceSubMenuRender: props.forceSubMenuRender,
|
|
|
|
triggerSubMenuAction: props.triggerSubMenuAction,
|
2018-11-05 21:03:25 +08:00
|
|
|
builtinPlacements: props.builtinPlacements,
|
2019-01-12 11:33:27 +08:00
|
|
|
defaultActiveFirst: props.store.getState().defaultActiveFirst[
|
|
|
|
getMenuIdFromSubMenuEventKey(props.eventKey)
|
|
|
|
],
|
2018-01-02 19:05:02 +08:00
|
|
|
multiple: props.multiple,
|
|
|
|
prefixCls: props.rootPrefixCls,
|
2018-09-05 21:28:54 +08:00
|
|
|
manualRef: this.saveMenuInstance,
|
2018-11-05 21:03:25 +08:00
|
|
|
itemIcon: getComponentFromProp(this, 'itemIcon'),
|
|
|
|
expandIcon: getComponentFromProp(this, 'expandIcon'),
|
2018-09-05 21:28:54 +08:00
|
|
|
children,
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
|
|
|
on: {
|
|
|
|
click: this.onSubMenuClick,
|
2019-01-12 11:33:27 +08:00
|
|
|
select,
|
|
|
|
deselect,
|
|
|
|
openChange,
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2020-03-07 19:45:13 +08:00
|
|
|
id: this.internalMenuId,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
const baseProps = subPopupMenuProps.props;
|
|
|
|
const haveRendered = this.haveRendered;
|
|
|
|
this.haveRendered = true;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
this.haveOpened = this.haveOpened || baseProps.visible || baseProps.forceSubMenuRender;
|
2018-09-05 21:28:54 +08:00
|
|
|
// never rendered not planning to, don't render
|
|
|
|
if (!this.haveOpened) {
|
2019-01-12 11:33:27 +08:00
|
|
|
return <div />;
|
2018-09-05 21:28:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// don't show transition on first rendering (no animation for opened menu)
|
|
|
|
// show appear transition if it's not visible (not sure why)
|
|
|
|
// show appear transition if it's not inline mode
|
2019-01-12 11:33:27 +08:00
|
|
|
const transitionAppear = haveRendered || !baseProps.visible || !baseProps.mode === 'inline';
|
|
|
|
subPopupMenuProps.class = ` ${baseProps.prefixCls}-sub`;
|
|
|
|
let animProps = { appear: transitionAppear, css: false };
|
2018-09-05 21:28:54 +08:00
|
|
|
let transitionProps = {
|
|
|
|
props: animProps,
|
|
|
|
on: {},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-09-05 21:28:54 +08:00
|
|
|
if (baseProps.openTransitionName) {
|
2019-01-12 11:33:27 +08:00
|
|
|
transitionProps = getTransitionProps(baseProps.openTransitionName, {
|
|
|
|
appear: transitionAppear,
|
|
|
|
});
|
2018-09-05 21:28:54 +08:00
|
|
|
} else if (typeof baseProps.openAnimation === 'object') {
|
2019-01-12 11:33:27 +08:00
|
|
|
animProps = { ...animProps, ...(baseProps.openAnimation.props || {}) };
|
2018-09-05 21:28:54 +08:00
|
|
|
if (!transitionAppear) {
|
2019-01-12 11:33:27 +08:00
|
|
|
animProps.appear = false;
|
2018-09-05 21:28:54 +08:00
|
|
|
}
|
|
|
|
} else if (typeof baseProps.openAnimation === 'string') {
|
2019-01-12 11:33:27 +08:00
|
|
|
transitionProps = getTransitionProps(baseProps.openAnimation, { appear: transitionAppear });
|
2018-09-05 21:28:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof baseProps.openAnimation === 'object' && baseProps.openAnimation.on) {
|
2019-01-12 11:33:27 +08:00
|
|
|
transitionProps.on = baseProps.openAnimation.on;
|
2018-09-05 21:28:54 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
return (
|
|
|
|
<transition {...transitionProps}>
|
|
|
|
<SubPopupMenu v-show={props.isOpen} {...subPopupMenuProps} />
|
|
|
|
</transition>
|
|
|
|
);
|
2018-01-02 19:05:02 +08:00
|
|
|
},
|
2017-12-08 14:31:53 +08:00
|
|
|
},
|
|
|
|
|
2019-02-01 17:23:00 +08:00
|
|
|
render() {
|
2019-01-12 11:33:27 +08:00
|
|
|
const props = this.$props;
|
2020-01-19 16:58:38 +08:00
|
|
|
const { rootPrefixCls, parentMenu } = this;
|
2019-01-12 11:33:27 +08:00
|
|
|
const isOpen = props.isOpen;
|
|
|
|
const prefixCls = this.getPrefixCls();
|
|
|
|
const isInlineMode = props.mode === 'inline';
|
2017-12-29 18:45:11 +08:00
|
|
|
const className = {
|
2018-01-02 19:05:02 +08:00
|
|
|
[prefixCls]: true,
|
2017-12-29 18:45:11 +08:00
|
|
|
[`${prefixCls}-${props.mode}`]: true,
|
2017-12-08 14:31:53 +08:00
|
|
|
[this.getOpenClassName()]: isOpen,
|
|
|
|
[this.getActiveClassName()]: props.active || (isOpen && !isInlineMode),
|
|
|
|
[this.getDisabledClassName()]: props.disabled,
|
|
|
|
[this.getSelectedClassName()]: this.isChildrenSelected(),
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
if (!this.internalMenuId) {
|
2017-12-08 14:31:53 +08:00
|
|
|
if (props.eventKey) {
|
2020-03-07 19:45:13 +08:00
|
|
|
this.internalMenuId = `${props.eventKey}$Menu`;
|
2017-12-08 14:31:53 +08:00
|
|
|
} else {
|
2020-03-07 19:45:13 +08:00
|
|
|
this.internalMenuId = `$__$${++guid}$Menu`;
|
2017-12-08 14:31:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
let mouseEvents = {};
|
|
|
|
let titleClickEvents = {};
|
|
|
|
let titleMouseEvents = {};
|
2017-12-08 14:31:53 +08:00
|
|
|
if (!props.disabled) {
|
|
|
|
mouseEvents = {
|
2018-01-02 19:05:02 +08:00
|
|
|
mouseleave: this.onMouseLeave,
|
|
|
|
mouseenter: this.onMouseEnter,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2017-12-08 14:31:53 +08:00
|
|
|
|
|
|
|
// only works in title, not outer li
|
|
|
|
titleClickEvents = {
|
2018-01-02 19:05:02 +08:00
|
|
|
click: this.onTitleClick,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2017-12-08 14:31:53 +08:00
|
|
|
titleMouseEvents = {
|
2018-01-02 19:05:02 +08:00
|
|
|
mouseenter: this.onTitleMouseEnter,
|
|
|
|
mouseleave: this.onTitleMouseLeave,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2017-12-08 14:31:53 +08:00
|
|
|
}
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const style = {};
|
2017-12-08 14:31:53 +08:00
|
|
|
if (isInlineMode) {
|
2019-01-12 11:33:27 +08:00
|
|
|
style.paddingLeft = `${props.inlineIndent * props.level}px`;
|
2018-01-02 19:05:02 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
let ariaOwns = {};
|
2018-09-05 21:28:54 +08:00
|
|
|
// only set aria-owns when menu is open
|
|
|
|
// otherwise it would be an invalid aria-owns value
|
|
|
|
// since corresponding node cannot be found
|
|
|
|
if (isOpen) {
|
|
|
|
ariaOwns = {
|
2020-03-07 19:45:13 +08:00
|
|
|
'aria-owns': this.internalMenuId,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-09-05 21:28:54 +08:00
|
|
|
}
|
2018-01-02 19:05:02 +08:00
|
|
|
const titleProps = {
|
|
|
|
attrs: {
|
|
|
|
'aria-expanded': isOpen,
|
2018-09-05 21:28:54 +08:00
|
|
|
...ariaOwns,
|
2018-01-02 19:05:02 +08:00
|
|
|
'aria-haspopup': 'true',
|
|
|
|
title: typeof props.title === 'string' ? props.title : undefined,
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
...titleMouseEvents,
|
|
|
|
...titleClickEvents,
|
|
|
|
},
|
|
|
|
style,
|
|
|
|
class: `${prefixCls}-title`,
|
|
|
|
ref: 'subMenuTitle',
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-11-05 21:03:25 +08:00
|
|
|
// expand custom icon should NOT be displayed in menu with horizontal mode.
|
2019-01-12 11:33:27 +08:00
|
|
|
let icon = null;
|
2018-11-05 21:03:25 +08:00
|
|
|
if (props.mode !== 'horizontal') {
|
2019-01-12 11:33:27 +08:00
|
|
|
icon = getComponentFromProp(this, 'expandIcon', props);
|
2018-11-05 21:03:25 +08:00
|
|
|
}
|
2017-12-08 14:31:53 +08:00
|
|
|
const title = (
|
2018-09-05 21:28:54 +08:00
|
|
|
<div {...titleProps}>
|
2018-01-18 10:43:39 +08:00
|
|
|
{getComponentFromProp(this, 'title')}
|
2018-11-05 21:03:25 +08:00
|
|
|
{icon || <i class={`${prefixCls}-arrow`} />}
|
2017-12-08 14:31:53 +08:00
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
|
|
|
const children = this.renderChildren(filterEmpty(this.$slots.default));
|
2017-12-08 14:31:53 +08:00
|
|
|
|
2018-09-05 21:28:54 +08:00
|
|
|
const getPopupContainer = this.parentMenu.isRootMenu
|
2019-01-12 11:33:27 +08:00
|
|
|
? this.parentMenu.getPopupContainer
|
|
|
|
: triggerNode => triggerNode.parentNode;
|
|
|
|
const popupPlacement = popupPlacementMap[props.mode];
|
|
|
|
const popupAlign = props.popupOffset ? { offset: props.popupOffset } : {};
|
|
|
|
const popupClassName = props.mode === 'inline' ? '' : props.popupClassName;
|
2018-01-02 19:05:02 +08:00
|
|
|
const liProps = {
|
2020-01-19 16:58:38 +08:00
|
|
|
on: { ...omit(getListeners(this), ['click']), ...mouseEvents },
|
2018-01-02 19:05:02 +08:00
|
|
|
class: className,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-01-04 19:06:54 +08:00
|
|
|
|
2017-12-08 14:31:53 +08:00
|
|
|
return (
|
2019-01-12 11:33:27 +08:00
|
|
|
<li {...liProps} role="menuitem">
|
2017-12-08 14:31:53 +08:00
|
|
|
{isInlineMode && title}
|
2018-09-05 21:28:54 +08:00
|
|
|
{isInlineMode && children}
|
2017-12-08 14:31:53 +08:00
|
|
|
{!isInlineMode && (
|
|
|
|
<Trigger
|
|
|
|
prefixCls={prefixCls}
|
2019-01-12 11:33:27 +08:00
|
|
|
popupClassName={`${prefixCls}-popup ${rootPrefixCls}-${
|
|
|
|
parentMenu.theme
|
|
|
|
} ${popupClassName || ''}`}
|
2018-01-03 18:30:12 +08:00
|
|
|
getPopupContainer={getPopupContainer}
|
2017-12-08 14:31:53 +08:00
|
|
|
builtinPlacements={placements}
|
2018-11-05 21:03:25 +08:00
|
|
|
builtinPlacements={Object.assign({}, placements, props.builtinPlacements)}
|
2017-12-08 14:31:53 +08:00
|
|
|
popupPlacement={popupPlacement}
|
|
|
|
popupVisible={isOpen}
|
2018-09-05 21:28:54 +08:00
|
|
|
popupAlign={popupAlign}
|
2017-12-08 14:31:53 +08:00
|
|
|
action={props.disabled ? [] : [props.triggerSubMenuAction]}
|
|
|
|
mouseEnterDelay={props.subMenuOpenDelay}
|
|
|
|
mouseLeaveDelay={props.subMenuCloseDelay}
|
|
|
|
onPopupVisibleChange={this.onPopupVisibleChange}
|
|
|
|
forceRender={props.forceSubMenuRender}
|
2018-01-04 19:06:54 +08:00
|
|
|
// popupTransitionName='rc-menu-open-slide-up'
|
2018-09-05 21:28:54 +08:00
|
|
|
// popupAnimation={transitionProps}
|
2017-12-08 14:31:53 +08:00
|
|
|
>
|
2019-01-12 11:33:27 +08:00
|
|
|
<template slot="popup">{children}</template>
|
2017-12-08 14:31:53 +08:00
|
|
|
{title}
|
|
|
|
</Trigger>
|
|
|
|
)}
|
|
|
|
</li>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2017-12-08 14:31:53 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-19 10:16:27 +08:00
|
|
|
|
2018-09-05 21:28:54 +08:00
|
|
|
const connected = connect(({ openKeys, activeKey, selectedKeys }, { eventKey, subMenuKey }) => ({
|
|
|
|
isOpen: openKeys.indexOf(eventKey) > -1,
|
|
|
|
active: activeKey[subMenuKey] === eventKey,
|
|
|
|
selectedKeys,
|
2019-01-12 11:33:27 +08:00
|
|
|
}))(SubMenu);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
connected.isSubMenu = true;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export default connected;
|