You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

import * as React from 'react';
import * as PropTypes from 'prop-types';
import { SubMenu as RcSubMenu } from 'rc-menu';
import classNames from 'classnames';
import { MenuContext, MenuContextProps } from './index';
interface TitleEventEntity {
6 years ago
key: string;
domEvent: Event;
}
export interface SubMenuProps {
rootPrefixCls?: string;
className?: string;
disabled?: boolean;
title?: React.ReactNode;
style?: React.CSSProperties;
onTitleClick?: (e: TitleEventEntity) => void;
onTitleMouseEnter?: (e: TitleEventEntity) => void;
onTitleMouseLeave?: (e: TitleEventEntity) => void;
}
class SubMenu extends React.Component<SubMenuProps, any> {
static contextTypes = {
antdMenuTheme: PropTypes.string,
};
// fix issue:https://github.com/ant-design/ant-design/issues/8666
static isSubMenu = 1;
private subMenu: any;
6 years ago
onKeyDown = (e: React.MouseEvent<HTMLElement>) => {
this.subMenu.onKeyDown(e);
};
6 years ago
saveSubMenu = (subMenu: any) => {
this.subMenu = subMenu;
};
6 years ago
render() {
const { rootPrefixCls, className } = this.props;
return (
<MenuContext.Consumer>
{({ antdMenuTheme }: MenuContextProps) => (
<RcSubMenu
{...this.props}
ref={this.saveSubMenu}
popupClassName={classNames(`${rootPrefixCls}-${antdMenuTheme}`, className)}
/>
)}
</MenuContext.Consumer>
);
}
}
export default SubMenu;