ant-design/components/menu/SubMenu.tsx

65 lines
1.5 KiB
TypeScript
Raw Normal View History

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