feat: improve prop def for tooltip

This commit is contained in:
LaySent 2019-08-27 22:30:52 +08:00 committed by 偏右
parent 69b0cc1a10
commit b029e38705
2 changed files with 12 additions and 5 deletions

View File

@ -42,11 +42,12 @@ export default class MenuItem extends React.Component<MenuItemProps> {
return (
<MenuContext.Consumer>
{({ inlineCollapsed }: MenuContextProps) => {
const tooltipProps: TooltipProps = {};
const tooltipProps: TooltipProps = {
title: title || (level === 1 ? children : ''),
};
let titleNode = title || (level === 1 ? children : '');
if (!siderCollapsed && !inlineCollapsed) {
titleNode = null;
tooltipProps.title = null;
// Reset `visible` to fix control mode tooltip display not correct
// ref: https://github.com/ant-design/ant-design/issues/16742
tooltipProps.visible = false;
@ -55,7 +56,6 @@ export default class MenuItem extends React.Component<MenuItemProps> {
return (
<Tooltip
{...tooltipProps}
title={titleNode}
placement="right"
overlayClassName={`${rootPrefixCls}-inline-collapsed-tooltip`}
>

View File

@ -64,11 +64,18 @@ export interface AbstractTooltipProps {
export type RenderFunction = () => React.ReactNode;
export interface TooltipProps extends AbstractTooltipProps {
interface TooltipPropsWithOverlay extends AbstractTooltipProps {
title?: React.ReactNode | RenderFunction;
overlay: React.ReactNode | RenderFunction;
}
interface TooltipPropsWithTitle extends AbstractTooltipProps {
title: React.ReactNode | RenderFunction;
overlay?: React.ReactNode | RenderFunction;
}
export declare type TooltipProps = TooltipPropsWithTitle | TooltipPropsWithOverlay;
const splitObject = (obj: any, keys: string[]) => {
const picked: any = {};
const omitted: any = { ...obj };