fix: Tooltip support multi children, close: #3924 (#4105)

This commit is contained in:
Benjy Cui 2016-12-02 15:07:03 +08:00 committed by 偏右
parent f3ffae9e54
commit a939769069
3 changed files with 8 additions and 7 deletions

View File

@ -1,6 +1,6 @@
---
order: 0
title:
title:
zh-CN: 基本
en-US: Basic
---
@ -9,7 +9,7 @@ title:
最简单的用法。
## en-US
## en-US
The simplest usage.
@ -18,7 +18,7 @@ import { Tooltip } from 'antd';
ReactDOM.render(
<Tooltip title="prompt text">
<span>Text will show when mouse enter.</span>
<span>Tooltip will show when mouse enter.</span>
</Tooltip>
, mountNode);
````

View File

@ -124,8 +124,9 @@ export default class Tooltip extends React.Component<TooltipProps, any> {
visible = false;
}
const childrenProps = children.props;
const childrenCls = classNames(childrenProps.className, {
const child = React.isValidElement(children) ? children : <span>{children}</span>;
const childProps = child.props;
const childCls = classNames(childProps.className, {
[openClassName || `${prefixCls}-open`]: true,
});
@ -139,7 +140,7 @@ export default class Tooltip extends React.Component<TooltipProps, any> {
onVisibleChange={this.onVisibleChange}
onPopupAlign={this.onPopupAlign}
>
{visible ? cloneElement(children, { className: childrenCls }) : children}
{visible ? cloneElement(child, { className: childCls }) : child}
</RcTooltip>
);
}

View File

@ -19,7 +19,7 @@ exports[`test renders ./components/tooltip/demo/arrow-point-at-center.md correct
exports[`test renders ./components/tooltip/demo/basic.md correctly 1`] = `
<span>
Text will show when mouse enter.
Tooltip will show when mouse enter.
</span>
`;