2019-01-12 03:33:27 +00:00
|
|
|
|
import omit from 'omit.js';
|
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
|
import { connect } from '../_util/store';
|
|
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
|
|
|
|
import KeyCode from '../_util/KeyCode';
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
import { getKeyFromChildrenIndex, loopMenuItem, noop, isMobileDevice } from './util';
|
|
|
|
|
import DOMWrap from './DOMWrap';
|
|
|
|
|
import { cloneElement } from '../_util/vnode';
|
|
|
|
|
import {
|
|
|
|
|
initDefaultProps,
|
|
|
|
|
getOptionProps,
|
|
|
|
|
getPropsData,
|
|
|
|
|
getEvents,
|
|
|
|
|
getComponentFromProp,
|
2020-01-19 08:58:38 +00:00
|
|
|
|
getListeners,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
} from '../_util/props-util';
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
function allDisabled(arr) {
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (!arr.length) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return true;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
return arr.every(c => {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return !!c.disabled;
|
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
function updateActiveKey(store, menuId, activeKey) {
|
|
|
|
|
const state = store.getState();
|
2018-09-05 13:28:54 +00:00
|
|
|
|
store.setState({
|
|
|
|
|
activeKey: {
|
|
|
|
|
...state.activeKey,
|
|
|
|
|
[menuId]: activeKey,
|
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
function getEventKey(props) {
|
2018-11-05 13:03:25 +00:00
|
|
|
|
// when eventKey not available ,it's menu and return menu id '0-menu-'
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return props.eventKey || '0-menu-';
|
2018-11-05 13:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
export function saveRef(key, c) {
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (c) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const index = this.instanceArrayKeyIndexMap[key];
|
|
|
|
|
this.instanceArray[index] = c;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
export function getActiveKey(props, originalActiveKey) {
|
|
|
|
|
let activeKey = originalActiveKey;
|
|
|
|
|
const { eventKey, defaultActiveFirst, children } = props;
|
2018-09-19 05:14:46 +00:00
|
|
|
|
if (activeKey !== undefined && activeKey !== null) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
let found;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
loopMenuItem(children, (c, i) => {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const propsData = c.componentOptions.propsData || {};
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (c && !propsData.disabled && activeKey === getKeyFromChildrenIndex(c, eventKey, i)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
found = true;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (found) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return activeKey;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
activeKey = null;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (defaultActiveFirst) {
|
|
|
|
|
loopMenuItem(children, (c, i) => {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const propsData = c.componentOptions.propsData || {};
|
2020-04-04 07:07:59 +00:00
|
|
|
|
const noActiveKey = activeKey === null || activeKey === undefined;
|
|
|
|
|
if (noActiveKey && c && !propsData.disabled) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
activeKey = getKeyFromChildrenIndex(c, eventKey, i);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
});
|
|
|
|
|
return activeKey;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return activeKey;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SubPopupMenu = {
|
2017-12-29 10:45:11 +00:00
|
|
|
|
name: 'SubPopupMenu',
|
2019-01-12 03:33:27 +00:00
|
|
|
|
props: initDefaultProps(
|
|
|
|
|
{
|
|
|
|
|
// onSelect: PropTypes.func,
|
|
|
|
|
// onClick: PropTypes.func,
|
|
|
|
|
// onDeselect: PropTypes.func,
|
|
|
|
|
// onOpenChange: PropTypes.func,
|
|
|
|
|
// onDestroy: PropTypes.func,
|
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
|
openTransitionName: PropTypes.string,
|
|
|
|
|
openAnimation: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
|
|
|
openKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
|
|
|
|
visible: PropTypes.bool,
|
|
|
|
|
parentMenu: PropTypes.object,
|
|
|
|
|
eventKey: PropTypes.string,
|
|
|
|
|
store: PropTypes.object,
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
// adding in refactor
|
|
|
|
|
focusable: PropTypes.bool,
|
|
|
|
|
multiple: PropTypes.bool,
|
|
|
|
|
defaultActiveFirst: PropTypes.bool,
|
|
|
|
|
activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
|
|
|
selectedKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
|
|
|
|
defaultSelectedKeys: PropTypes.arrayOf(
|
|
|
|
|
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
|
|
|
),
|
|
|
|
|
defaultOpenKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
|
|
|
|
level: PropTypes.number,
|
|
|
|
|
mode: PropTypes.oneOf([
|
|
|
|
|
'horizontal',
|
|
|
|
|
'vertical',
|
|
|
|
|
'vertical-left',
|
|
|
|
|
'vertical-right',
|
|
|
|
|
'inline',
|
|
|
|
|
]),
|
|
|
|
|
triggerSubMenuAction: PropTypes.oneOf(['click', 'hover']),
|
|
|
|
|
inlineIndent: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
|
|
|
manualRef: PropTypes.func,
|
|
|
|
|
itemIcon: PropTypes.any,
|
|
|
|
|
expandIcon: PropTypes.any,
|
|
|
|
|
overflowedIndicator: PropTypes.any,
|
|
|
|
|
children: PropTypes.any.def([]),
|
|
|
|
|
__propsSymbol__: PropTypes.any, // mock componentWillReceiveProps
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
prefixCls: 'rc-menu',
|
|
|
|
|
mode: 'vertical',
|
|
|
|
|
level: 1,
|
|
|
|
|
inlineIndent: 24,
|
|
|
|
|
visible: true,
|
|
|
|
|
focusable: true,
|
|
|
|
|
manualRef: noop,
|
|
|
|
|
},
|
|
|
|
|
),
|
2017-12-08 06:31:53 +00:00
|
|
|
|
|
2018-09-05 13:28:54 +00:00
|
|
|
|
mixins: [BaseMixin],
|
2019-01-12 03:33:27 +00:00
|
|
|
|
created() {
|
|
|
|
|
const props = getOptionProps(this);
|
|
|
|
|
this.prevProps = { ...props };
|
2018-09-05 13:28:54 +00:00
|
|
|
|
props.store.setState({
|
|
|
|
|
activeKey: {
|
|
|
|
|
...props.store.getState().activeKey,
|
|
|
|
|
[props.eventKey]: getActiveKey(props, props.activeKey),
|
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
});
|
|
|
|
|
this.instanceArray = [];
|
2018-09-05 13:28:54 +00:00
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
mounted() {
|
2018-09-05 13:28:54 +00:00
|
|
|
|
// invoke customized ref to expose component to mixin
|
|
|
|
|
if (this.manualRef) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
this.manualRef(this);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
updated() {
|
|
|
|
|
const props = getOptionProps(this);
|
|
|
|
|
const prevProps = this.prevProps;
|
|
|
|
|
const originalActiveKey =
|
|
|
|
|
'activeKey' in props ? props.activeKey : props.store.getState().activeKey[getEventKey(props)];
|
|
|
|
|
const activeKey = getActiveKey(props, originalActiveKey);
|
2018-11-05 13:03:25 +00:00
|
|
|
|
if (activeKey !== originalActiveKey) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
updateActiveKey(props.store, getEventKey(props), activeKey);
|
2018-12-19 01:29:09 +00:00
|
|
|
|
} else if ('activeKey' in prevProps) {
|
|
|
|
|
// If prev activeKey is not same as current activeKey,
|
|
|
|
|
// we should set it.
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const prevActiveKey = getActiveKey(prevProps, prevProps.activeKey);
|
2018-12-19 01:29:09 +00:00
|
|
|
|
if (activeKey !== prevActiveKey) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
updateActiveKey(props.store, getEventKey(props), activeKey);
|
2018-12-19 01:29:09 +00:00
|
|
|
|
}
|
2018-11-05 13:03:25 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
this.prevProps = { ...props };
|
2018-09-05 13:28:54 +00:00
|
|
|
|
},
|
2018-01-03 10:30:12 +00:00
|
|
|
|
methods: {
|
2018-09-05 13:28:54 +00:00
|
|
|
|
// all keyboard events callbacks run from here at first
|
2019-01-12 03:33:27 +00:00
|
|
|
|
onKeyDown(e, callback) {
|
|
|
|
|
const keyCode = e.keyCode;
|
|
|
|
|
let handled;
|
|
|
|
|
this.getFlatInstanceArray().forEach(obj => {
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (obj && obj.active && obj.onKeyDown) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
handled = obj.onKeyDown(e);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (handled) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return 1;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
let activeItem = null;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (keyCode === KeyCode.UP || keyCode === KeyCode.DOWN) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
activeItem = this.step(keyCode === KeyCode.UP ? -1 : 1);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
if (activeItem) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
updateActiveKey(this.$props.store, getEventKey(this.$props), activeItem.eventKey);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
|
|
if (typeof callback === 'function') {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
callback(activeItem);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return 1;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2020-03-07 11:45:13 +00:00
|
|
|
|
return undefined;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
onItemHover(e) {
|
|
|
|
|
const { key, hover } = e;
|
|
|
|
|
updateActiveKey(this.$props.store, getEventKey(this.$props), hover ? key : null);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
onDeselect(selectInfo) {
|
|
|
|
|
this.__emit('deselect', selectInfo);
|
2018-01-03 10:30:12 +00:00
|
|
|
|
},
|
2017-12-08 06:31:53 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
onSelect(selectInfo) {
|
|
|
|
|
this.__emit('select', selectInfo);
|
2018-01-03 10:30:12 +00:00
|
|
|
|
},
|
2017-12-08 06:31:53 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
onClick(e) {
|
|
|
|
|
this.__emit('click', e);
|
2018-01-03 10:30:12 +00:00
|
|
|
|
},
|
2017-12-08 06:31:53 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
onOpenChange(e) {
|
|
|
|
|
this.__emit('openChange', e);
|
2018-01-03 10:30:12 +00:00
|
|
|
|
},
|
2017-12-08 06:31:53 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
onDestroy(key) {
|
|
|
|
|
this.__emit('destroy', key);
|
2018-01-03 10:30:12 +00:00
|
|
|
|
},
|
2017-12-08 06:31:53 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
getFlatInstanceArray() {
|
|
|
|
|
return this.instanceArray;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
getOpenTransitionName() {
|
|
|
|
|
return this.$props.openTransitionName;
|
2018-01-03 10:30:12 +00:00
|
|
|
|
},
|
2017-12-08 06:31:53 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
step(direction) {
|
|
|
|
|
let children = this.getFlatInstanceArray();
|
|
|
|
|
const activeKey = this.$props.store.getState().activeKey[getEventKey(this.$props)];
|
|
|
|
|
const len = children.length;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (!len) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return null;
|
2018-01-03 10:30:12 +00:00
|
|
|
|
}
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (direction < 0) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
children = children.concat().reverse();
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
// find current activeIndex
|
2019-01-12 03:33:27 +00:00
|
|
|
|
let activeIndex = -1;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
children.every((c, ci) => {
|
|
|
|
|
if (c && c.eventKey === activeKey) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
activeIndex = ci;
|
|
|
|
|
return false;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return true;
|
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (
|
2019-01-12 03:33:27 +00:00
|
|
|
|
!this.defaultActiveFirst &&
|
|
|
|
|
activeIndex !== -1 &&
|
2018-09-05 13:28:54 +00:00
|
|
|
|
allDisabled(children.slice(activeIndex, len - 1))
|
|
|
|
|
) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return undefined;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const start = (activeIndex + 1) % len;
|
|
|
|
|
let i = start;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
|
|
do {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const child = children[i];
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (!child || child.disabled) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
i = (i + 1) % len;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return child;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
} while (i !== start);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return null;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
getIcon(instance, name) {
|
2018-11-05 13:03:25 +00:00
|
|
|
|
if (instance.$createElement) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const temp = instance[name];
|
2018-11-05 13:03:25 +00:00
|
|
|
|
if (temp !== undefined) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return temp;
|
2018-11-05 13:03:25 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return instance.$slots[name] || instance.$scopedSlots[name];
|
2018-11-05 13:03:25 +00:00
|
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const temp = getPropsData(instance)[name];
|
2018-11-05 13:03:25 +00:00
|
|
|
|
if (temp !== undefined) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return temp;
|
2018-11-05 13:03:25 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const slotsProp = [];
|
2018-11-05 13:03:25 +00:00
|
|
|
|
const componentOptions = instance.componentOptions || {};
|
2019-01-12 03:33:27 +00:00
|
|
|
|
(componentOptions.children || []).forEach(child => {
|
2018-11-05 13:03:25 +00:00
|
|
|
|
if (child.data && child.data.slot === name) {
|
|
|
|
|
if (child.tag === 'template') {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
slotsProp.push(child.children);
|
2018-11-05 13:03:25 +00:00
|
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
slotsProp.push(child);
|
2018-11-05 13:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
});
|
|
|
|
|
return slotsProp.length ? slotsProp : undefined;
|
2018-11-05 13:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
renderCommonMenuItem(child, i, extraProps) {
|
|
|
|
|
if (child.tag === undefined) {
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
const state = this.$props.store.getState();
|
|
|
|
|
const props = this.$props;
|
|
|
|
|
const key = getKeyFromChildrenIndex(child, props.eventKey, i);
|
|
|
|
|
const childProps = child.componentOptions.propsData || {};
|
2018-11-06 02:05:23 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const isActive = key === state.activeKey[getEventKey(this.$props)];
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (!childProps.disabled) {
|
|
|
|
|
// manualRef的执行顺序不能保证,使用key映射ref在this.instanceArray中的位置
|
2019-01-12 03:33:27 +00:00
|
|
|
|
this.instanceArrayKeyIndexMap[key] = Object.keys(this.instanceArrayKeyIndexMap).length;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const childListeners = getEvents(child);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
const newChildProps = {
|
|
|
|
|
props: {
|
2018-11-05 13:03:25 +00:00
|
|
|
|
mode: childProps.mode || props.mode,
|
2018-09-05 13:28:54 +00:00
|
|
|
|
level: props.level,
|
|
|
|
|
inlineIndent: props.inlineIndent,
|
|
|
|
|
renderMenuItem: this.renderMenuItem,
|
|
|
|
|
rootPrefixCls: props.prefixCls,
|
|
|
|
|
index: i,
|
|
|
|
|
parentMenu: props.parentMenu,
|
|
|
|
|
// customized ref function, need to be invoked manually in child's componentDidMount
|
|
|
|
|
manualRef: childProps.disabled ? noop : saveRef.bind(this, key),
|
|
|
|
|
eventKey: key,
|
|
|
|
|
active: !childProps.disabled && isActive,
|
|
|
|
|
multiple: props.multiple,
|
|
|
|
|
openTransitionName: this.getOpenTransitionName(),
|
|
|
|
|
openAnimation: props.openAnimation,
|
|
|
|
|
subMenuOpenDelay: props.subMenuOpenDelay,
|
|
|
|
|
subMenuCloseDelay: props.subMenuCloseDelay,
|
|
|
|
|
forceSubMenuRender: props.forceSubMenuRender,
|
2018-11-05 13:03:25 +00:00
|
|
|
|
builtinPlacements: props.builtinPlacements,
|
|
|
|
|
itemIcon: this.getIcon(child, 'itemIcon') || this.getIcon(this, 'itemIcon'),
|
|
|
|
|
expandIcon: this.getIcon(child, 'expandIcon') || this.getIcon(this, 'expandIcon'),
|
2018-09-05 13:28:54 +00:00
|
|
|
|
...extraProps,
|
|
|
|
|
},
|
|
|
|
|
on: {
|
2019-11-28 09:32:46 +00:00
|
|
|
|
click: e => {
|
|
|
|
|
if ('keyPath' in e) {
|
|
|
|
|
(childListeners.click || noop)(e);
|
|
|
|
|
this.onClick(e);
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-09-05 13:28:54 +00:00
|
|
|
|
itemHover: this.onItemHover,
|
|
|
|
|
openChange: this.onOpenChange,
|
|
|
|
|
deselect: this.onDeselect,
|
|
|
|
|
// destroy: this.onDestroy,
|
|
|
|
|
select: this.onSelect,
|
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2019-01-08 15:03:13 +00:00
|
|
|
|
// ref: https://github.com/ant-design/ant-design/issues/13943
|
|
|
|
|
if (props.mode === 'inline' || isMobileDevice()) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
newChildProps.props.triggerSubMenuAction = 'click';
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return cloneElement(child, newChildProps);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
renderMenuItem(c, i, subMenuKey) {
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (!c) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return null;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const state = this.$props.store.getState();
|
2018-01-03 10:30:12 +00:00
|
|
|
|
const extraProps = {
|
2018-09-05 13:28:54 +00:00
|
|
|
|
openKeys: state.openKeys,
|
|
|
|
|
selectedKeys: state.selectedKeys,
|
|
|
|
|
triggerSubMenuAction: this.triggerSubMenuAction,
|
2018-01-03 10:30:12 +00:00
|
|
|
|
isRootMenu: false,
|
2018-09-05 13:28:54 +00:00
|
|
|
|
subMenuKey,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
|
|
|
|
return this.renderCommonMenuItem(c, i, extraProps);
|
2018-01-03 10:30:12 +00:00
|
|
|
|
},
|
2017-12-08 06:31:53 +00:00
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
render() {
|
|
|
|
|
const { ...props } = this.$props;
|
|
|
|
|
const { eventKey, prefixCls, visible, level, mode, theme } = props;
|
|
|
|
|
this.instanceArray = [];
|
|
|
|
|
this.instanceArrayKeyIndexMap = {};
|
|
|
|
|
const className = classNames(props.prefixCls, `${props.prefixCls}-${props.mode}`);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
const domWrapProps = {
|
|
|
|
|
props: {
|
|
|
|
|
tag: 'ul',
|
|
|
|
|
// hiddenClassName: `${prefixCls}-hidden`,
|
|
|
|
|
visible,
|
2018-11-06 03:59:01 +00:00
|
|
|
|
prefixCls,
|
|
|
|
|
level,
|
|
|
|
|
mode,
|
|
|
|
|
theme,
|
2018-11-05 13:03:25 +00:00
|
|
|
|
overflowedIndicator: getComponentFromProp(this, 'overflowedIndicator'),
|
2018-09-05 13:28:54 +00:00
|
|
|
|
},
|
|
|
|
|
attrs: {
|
|
|
|
|
role: props.role || 'menu',
|
|
|
|
|
},
|
|
|
|
|
class: className,
|
|
|
|
|
// Otherwise, the propagated click event will trigger another onClick
|
2020-01-19 08:58:38 +00:00
|
|
|
|
on: omit(getListeners(this), ['click']),
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-09-05 13:28:54 +00:00
|
|
|
|
// if (props.id) {
|
|
|
|
|
// domProps.id = props.id
|
|
|
|
|
// }
|
|
|
|
|
if (props.focusable) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
domWrapProps.attrs.tabIndex = '0';
|
|
|
|
|
domWrapProps.on.keydown = this.onKeyDown;
|
2018-01-19 10:18:17 +00:00
|
|
|
|
}
|
2018-09-05 13:28:54 +00:00
|
|
|
|
return (
|
|
|
|
|
// ESLint is not smart enough to know that the type of `children` was checked.
|
|
|
|
|
/* eslint-disable */
|
2019-01-12 03:33:27 +00:00
|
|
|
|
<DOMWrap {...domWrapProps}>
|
2018-09-05 13:28:54 +00:00
|
|
|
|
{props.children.map((c, i) => this.renderMenuItem(c, i, eventKey || '0-menu-'))}
|
|
|
|
|
</DOMWrap>
|
|
|
|
|
/*eslint -enable */
|
2019-01-12 03:33:27 +00:00
|
|
|
|
);
|
2017-12-08 06:31:53 +00:00
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-03-19 02:16:27 +00:00
|
|
|
|
|
2018-09-05 13:28:54 +00:00
|
|
|
|
export default connect()(SubPopupMenu);
|