2020-07-30 07:41:54 +00:00
|
|
|
|
import { Comment, inject } from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
|
|
|
|
import KeyCode from '../_util/KeyCode';
|
2020-08-31 08:53:19 +00:00
|
|
|
|
import classNames from '../_util/classNames';
|
2020-11-23 06:21:18 +00:00
|
|
|
|
import { getKeyFromChildrenIndex, noop, isMobileDevice, menuAllProps } from './util';
|
2019-01-12 03:33:27 +00:00
|
|
|
|
import DOMWrap from './DOMWrap';
|
2020-06-21 03:28:07 +00:00
|
|
|
|
import {
|
|
|
|
|
initDefaultProps,
|
|
|
|
|
getOptionProps,
|
|
|
|
|
getComponent,
|
|
|
|
|
splitAttrs,
|
2020-11-23 06:21:18 +00:00
|
|
|
|
getSlot,
|
2020-06-21 03:28:07 +00:00
|
|
|
|
} from '../_util/props-util';
|
2020-10-20 15:13:49 +00:00
|
|
|
|
import FunctionProvider from './FunctionProvider';
|
2020-11-23 06:21:18 +00:00
|
|
|
|
// import { getActiveKey } from '../vc-tabs/src/utils';
|
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) {
|
2020-11-23 06:21:18 +00:00
|
|
|
|
store.activeKey[menuId] = activeKey;
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-23 06:21:18 +00:00
|
|
|
|
// export function getActiveKey(props, originalActiveKey) {
|
|
|
|
|
// let activeKey = originalActiveKey;
|
|
|
|
|
// const { eventKey, defaultActiveFirst, children } = props;
|
|
|
|
|
// if (activeKey !== undefined && activeKey !== null) {
|
|
|
|
|
// let found;
|
|
|
|
|
// loopMenuItem(children, (c, i) => {
|
|
|
|
|
// const propsData = getPropsData(c);
|
|
|
|
|
// if (c && !propsData.disabled && activeKey === getKeyFromChildrenIndex(c, eventKey, i)) {
|
|
|
|
|
// found = true;
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// if (found) {
|
|
|
|
|
// return activeKey;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// activeKey = null;
|
|
|
|
|
// if (defaultActiveFirst) {
|
|
|
|
|
// loopMenuItem(children, (c, i) => {
|
|
|
|
|
// const propsData = getPropsData(c);
|
|
|
|
|
// const noActiveKey = activeKey === null || activeKey === undefined;
|
|
|
|
|
// if (noActiveKey && c && !propsData.disabled) {
|
|
|
|
|
// activeKey = getKeyFromChildrenIndex(c, eventKey, i);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// return activeKey;
|
|
|
|
|
// }
|
|
|
|
|
// return activeKey;
|
|
|
|
|
// }
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
|
|
const SubPopupMenu = {
|
2017-12-29 10:45:11 +00:00
|
|
|
|
name: 'SubPopupMenu',
|
2020-06-16 14:55:02 +00:00
|
|
|
|
inheritAttrs: false,
|
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])),
|
2020-10-10 10:16:28 +00:00
|
|
|
|
visible: PropTypes.looseBool,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
eventKey: PropTypes.string,
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
// adding in refactor
|
2020-10-10 10:16:28 +00:00
|
|
|
|
focusable: PropTypes.looseBool,
|
|
|
|
|
multiple: PropTypes.looseBool,
|
|
|
|
|
defaultActiveFirst: PropTypes.looseBool,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
activeKey: 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([]),
|
2020-12-03 08:10:13 +00:00
|
|
|
|
subMenuOpenDelay: PropTypes.number.def(0.1),
|
|
|
|
|
subMenuCloseDelay: PropTypes.number.def(0.1),
|
2020-11-23 06:21:18 +00:00
|
|
|
|
forceSubMenuRender: PropTypes.looseBool.def(false),
|
|
|
|
|
parentUniKeys: PropTypes.array.def(() => []),
|
|
|
|
|
parentUniKey: PropTypes.string,
|
2020-12-09 07:34:25 +00:00
|
|
|
|
theme: PropTypes.string,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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],
|
2020-07-30 07:41:54 +00:00
|
|
|
|
setup() {
|
2020-11-23 06:21:18 +00:00
|
|
|
|
const store = inject('menuStore', () => ({}));
|
|
|
|
|
return { store };
|
2020-07-30 07:41:54 +00:00
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
created() {
|
|
|
|
|
const props = getOptionProps(this);
|
|
|
|
|
this.prevProps = { ...props };
|
2020-11-23 06:21:18 +00:00
|
|
|
|
this.store.activeKey[props.eventKey] = this.store.getActiveKey(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 =
|
2020-11-23 06:21:18 +00:00
|
|
|
|
'activeKey' in props ? props.activeKey : this.store.activeKey[getEventKey(props)];
|
|
|
|
|
const activeKey = this.store.getActiveKey(originalActiveKey);
|
2018-11-05 13:03:25 +00:00
|
|
|
|
if (activeKey !== originalActiveKey) {
|
2020-11-23 06:21:18 +00:00
|
|
|
|
updateActiveKey(this.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.
|
2020-11-23 06:21:18 +00:00
|
|
|
|
const prevActiveKey = this.store.getActiveKey(prevProps.activeKey);
|
2018-12-19 01:29:09 +00:00
|
|
|
|
if (activeKey !== prevActiveKey) {
|
2020-11-23 06:21:18 +00:00
|
|
|
|
updateActiveKey(this.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();
|
2020-11-23 06:21:18 +00:00
|
|
|
|
updateActiveKey(this.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;
|
2020-11-23 06:21:18 +00:00
|
|
|
|
updateActiveKey(this.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();
|
2020-11-23 06:21:18 +00:00
|
|
|
|
const activeKey = this.store.activeKey[getEventKey(this.$props)];
|
2019-01-12 03:33:27 +00:00
|
|
|
|
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) {
|
2020-06-16 14:55:02 +00:00
|
|
|
|
return getComponent(instance, name);
|
2018-11-05 13:03:25 +00:00
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
renderCommonMenuItem(child, i, extraProps) {
|
2020-06-16 14:55:02 +00:00
|
|
|
|
if (child.type === Comment) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return child;
|
|
|
|
|
}
|
2020-11-23 06:21:18 +00:00
|
|
|
|
const state = this.store;
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const props = this.$props;
|
|
|
|
|
const key = getKeyFromChildrenIndex(child, props.eventKey, i);
|
2020-06-18 10:51:56 +00:00
|
|
|
|
const childProps = child.props || {}; // child.props 包含事件
|
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
|
|
|
|
}
|
|
|
|
|
const newChildProps = {
|
2020-06-16 14:55:02 +00:00
|
|
|
|
mode: childProps.mode || props.mode,
|
|
|
|
|
level: props.level,
|
|
|
|
|
inlineIndent: props.inlineIndent,
|
|
|
|
|
renderMenuItem: this.renderMenuItem,
|
|
|
|
|
rootPrefixCls: props.prefixCls,
|
|
|
|
|
index: i,
|
|
|
|
|
// 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,
|
|
|
|
|
builtinPlacements: props.builtinPlacements,
|
|
|
|
|
itemIcon: this.getIcon(child, 'itemIcon') || this.getIcon(this, 'itemIcon'),
|
|
|
|
|
expandIcon: this.getIcon(child, 'expandIcon') || this.getIcon(this, 'expandIcon'),
|
|
|
|
|
...extraProps,
|
|
|
|
|
onClick: e => {
|
|
|
|
|
(childProps.onClick || noop)(e);
|
|
|
|
|
this.onClick(e);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
},
|
2020-06-16 14:55:02 +00:00
|
|
|
|
onItemHover: this.onItemHover,
|
|
|
|
|
onOpenChange: this.onOpenChange,
|
|
|
|
|
onDeselect: this.onDeselect,
|
|
|
|
|
// destroy: this.onDestroy,
|
|
|
|
|
onSelect: this.onSelect,
|
2020-11-23 06:21:18 +00:00
|
|
|
|
parentUniKeys: this.parentUniKeys,
|
|
|
|
|
parentUniKey: this.parentUniKey,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2020-11-09 09:55:11 +00:00
|
|
|
|
if (props.forceSubMenuRender !== undefined) {
|
|
|
|
|
newChildProps.forceSubMenuRender = props.forceSubMenuRender;
|
|
|
|
|
}
|
2019-01-08 15:03:13 +00:00
|
|
|
|
// ref: https://github.com/ant-design/ant-design/issues/13943
|
|
|
|
|
if (props.mode === 'inline' || isMobileDevice()) {
|
2020-06-16 14:55:02 +00:00
|
|
|
|
newChildProps.triggerSubMenuAction = 'click';
|
2018-09-05 13:28:54 +00:00
|
|
|
|
}
|
2020-11-23 06:21:18 +00:00
|
|
|
|
return <FunctionProvider extraProps={newChildProps}>{child}</FunctionProvider>;
|
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
|
|
|
|
}
|
2020-11-23 06:21:18 +00:00
|
|
|
|
const state = this.store;
|
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() {
|
2020-06-16 14:55:02 +00:00
|
|
|
|
const props = { ...this.$props };
|
2020-06-17 16:19:14 +00:00
|
|
|
|
const { onEvents, extraAttrs } = splitAttrs(this.$attrs);
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const { eventKey, prefixCls, visible, level, mode, theme } = props;
|
|
|
|
|
this.instanceArray = [];
|
|
|
|
|
this.instanceArrayKeyIndexMap = {};
|
2020-06-17 16:19:14 +00:00
|
|
|
|
const className = classNames(
|
|
|
|
|
extraAttrs.class,
|
|
|
|
|
props.prefixCls,
|
|
|
|
|
`${props.prefixCls}-${props.mode}`,
|
|
|
|
|
);
|
2020-06-17 11:50:22 +00:00
|
|
|
|
menuAllProps.forEach(key => delete props[key]);
|
2020-06-16 14:55:02 +00:00
|
|
|
|
// Otherwise, the propagated click event will trigger another onClick
|
|
|
|
|
delete onEvents.onClick;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
const domWrapProps = {
|
2020-06-16 14:55:02 +00:00
|
|
|
|
...props,
|
|
|
|
|
tag: 'ul',
|
|
|
|
|
// hiddenClassName: `${prefixCls}-hidden`,
|
|
|
|
|
visible,
|
|
|
|
|
prefixCls,
|
|
|
|
|
level,
|
|
|
|
|
mode,
|
|
|
|
|
theme,
|
|
|
|
|
overflowedIndicator: getComponent(this, 'overflowedIndicator'),
|
|
|
|
|
role: props.role || 'menu',
|
2018-09-05 13:28:54 +00:00
|
|
|
|
class: className,
|
2020-06-17 16:19:14 +00:00
|
|
|
|
style: extraAttrs.style,
|
2020-06-16 14:55:02 +00:00
|
|
|
|
...onEvents,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2020-08-02 14:27:22 +00:00
|
|
|
|
if (extraAttrs.id !== undefined) {
|
|
|
|
|
domWrapProps.id = extraAttrs.id;
|
|
|
|
|
}
|
2018-09-05 13:28:54 +00:00
|
|
|
|
if (props.focusable) {
|
2020-07-17 09:13:30 +00:00
|
|
|
|
domWrapProps.tabindex = '0';
|
2020-06-16 14:55:02 +00:00
|
|
|
|
domWrapProps.onKeydown = this.onKeyDown;
|
2018-01-19 10:18:17 +00:00
|
|
|
|
}
|
2020-06-17 16:19:14 +00:00
|
|
|
|
delete domWrapProps.children;
|
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}>
|
2020-11-23 06:21:18 +00:00
|
|
|
|
{getSlot(this).map((c, i) => this.renderMenuItem(c, i, eventKey || '0-menu-'))}
|
2018-09-05 13:28:54 +00:00
|
|
|
|
</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
|
|
|
|
|
2020-11-23 06:21:18 +00:00
|
|
|
|
export default SubPopupMenu;
|