|
|
@ -15,6 +15,7 @@ export interface SubMenuProps { |
|
|
|
rootPrefixCls?: string; |
|
|
|
className?: string; |
|
|
|
disabled?: boolean; |
|
|
|
level?: number; |
|
|
|
title?: React.ReactNode; |
|
|
|
icon?: React.ReactNode; |
|
|
|
style?: React.CSSProperties; |
|
|
@ -43,10 +44,14 @@ class SubMenu extends React.Component<SubMenuProps, any> { |
|
|
|
this.subMenu = subMenu; |
|
|
|
}; |
|
|
|
|
|
|
|
renderTitle() { |
|
|
|
const { icon, title } = this.props; |
|
|
|
renderTitle(inlineCollapsed: boolean) { |
|
|
|
const { icon, title, level, rootPrefixCls } = this.props; |
|
|
|
if (!icon) { |
|
|
|
return title; |
|
|
|
return inlineCollapsed && level === 1 && title && typeof title === 'string' ? ( |
|
|
|
<div className={`${rootPrefixCls}-inline-collapsed-noicon`}>{title.charAt(0)}</div> |
|
|
|
) : ( |
|
|
|
title |
|
|
|
); |
|
|
|
} |
|
|
|
// inline-collapsed.md demo 依赖 span 来隐藏文字,有 icon 属性,则内部包裹一个 span
|
|
|
|
// ref: https://github.com/ant-design/ant-design/pull/23456
|
|
|
@ -63,10 +68,10 @@ class SubMenu extends React.Component<SubMenuProps, any> { |
|
|
|
const { rootPrefixCls, popupClassName } = this.props; |
|
|
|
return ( |
|
|
|
<MenuContext.Consumer> |
|
|
|
{({ antdMenuTheme }: MenuContextProps) => ( |
|
|
|
{({ inlineCollapsed, antdMenuTheme }: MenuContextProps) => ( |
|
|
|
<RcSubMenu |
|
|
|
{...omit(this.props, ['icon'])} |
|
|
|
title={this.renderTitle()} |
|
|
|
title={this.renderTitle(inlineCollapsed)} |
|
|
|
ref={this.saveSubMenu} |
|
|
|
popupClassName={classNames( |
|
|
|
rootPrefixCls, |
|
|
|