2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2018-08-07 21:07:52 +08:00
|
|
|
import * as PropTypes from 'prop-types';
|
2017-11-11 00:07:03 +08:00
|
|
|
import { SubMenu as RcSubMenu } from 'rc-menu';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2019-04-05 16:15:01 +08:00
|
|
|
import { MenuContext, MenuContextProps } from './index';
|
|
|
|
|
2019-02-06 08:35:47 +08:00
|
|
|
interface TitleEventEntity {
|
2019-01-28 13:29:20 +08:00
|
|
|
key: string;
|
|
|
|
domEvent: Event;
|
|
|
|
}
|
|
|
|
|
2019-01-23 10:32:35 +08:00
|
|
|
export interface SubMenuProps {
|
|
|
|
rootPrefixCls?: string;
|
|
|
|
className?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
title?: React.ReactNode;
|
2019-01-30 16:26:32 +08:00
|
|
|
style?: React.CSSProperties;
|
2019-02-06 08:35:47 +08:00
|
|
|
onTitleClick?: (e: TitleEventEntity) => void;
|
|
|
|
onTitleMouseEnter?: (e: TitleEventEntity) => void;
|
|
|
|
onTitleMouseLeave?: (e: TitleEventEntity) => void;
|
2019-06-22 14:53:51 +08:00
|
|
|
popupOffset?: [number, number];
|
2019-01-23 10:32:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class SubMenu extends React.Component<SubMenuProps, any> {
|
2017-11-11 00:07:03 +08:00
|
|
|
static contextTypes = {
|
|
|
|
antdMenuTheme: PropTypes.string,
|
|
|
|
};
|
2018-06-01 18:09:11 +08:00
|
|
|
// fix issue:https://github.com/ant-design/ant-design/issues/8666
|
|
|
|
static isSubMenu = 1;
|
2017-11-16 16:08:30 +08:00
|
|
|
private subMenu: any;
|
2018-12-13 22:03:12 +08:00
|
|
|
|
2017-11-21 17:38:51 +08:00
|
|
|
onKeyDown = (e: React.MouseEvent<HTMLElement>) => {
|
2017-11-16 16:08:30 +08:00
|
|
|
this.subMenu.onKeyDown(e);
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2019-03-12 19:52:43 +08:00
|
|
|
|
2017-11-21 17:38:51 +08:00
|
|
|
saveSubMenu = (subMenu: any) => {
|
2017-11-16 16:08:30 +08:00
|
|
|
this.subMenu = subMenu;
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2019-03-12 19:52:43 +08:00
|
|
|
|
2017-11-11 00:07:03 +08:00
|
|
|
render() {
|
|
|
|
const { rootPrefixCls, className } = this.props;
|
|
|
|
return (
|
2019-04-05 16:15:01 +08:00
|
|
|
<MenuContext.Consumer>
|
|
|
|
{({ antdMenuTheme }: MenuContextProps) => (
|
|
|
|
<RcSubMenu
|
|
|
|
{...this.props}
|
|
|
|
ref={this.saveSubMenu}
|
|
|
|
popupClassName={classNames(`${rootPrefixCls}-${antdMenuTheme}`, className)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</MenuContext.Consumer>
|
2017-11-11 00:07:03 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SubMenu;
|