mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 13:09:40 +08:00
ced96b954c
* Update SubMenu.tsx * add popupClassName to api * fix typo
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
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 './MenuContext';
|
|
|
|
interface TitleEventEntity {
|
|
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;
|
|
popupOffset?: [number, number];
|
|
popupClassName?: string;
|
|
}
|
|
|
|
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;
|
|
|
|
onKeyDown = (e: React.MouseEvent<HTMLElement>) => {
|
|
this.subMenu.onKeyDown(e);
|
|
};
|
|
|
|
saveSubMenu = (subMenu: any) => {
|
|
this.subMenu = subMenu;
|
|
};
|
|
|
|
render() {
|
|
const { rootPrefixCls, popupClassName } = this.props;
|
|
return (
|
|
<MenuContext.Consumer>
|
|
{({ antdMenuTheme }: MenuContextProps) => (
|
|
<RcSubMenu
|
|
{...this.props}
|
|
ref={this.saveSubMenu}
|
|
popupClassName={classNames(`${rootPrefixCls}-${antdMenuTheme}`, popupClassName)}
|
|
/>
|
|
)}
|
|
</MenuContext.Consumer>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default SubMenu;
|