Skip to content

Commit

Permalink
fix: Tooltip support multi children, close: #3924 (#4105)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui authored and afc163 committed Dec 2, 2016
1 parent f3ffae9 commit a939769
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions components/tooltip/demo/basic.md
@@ -1,6 +1,6 @@
---
order: 0
title:
title:
zh-CN: 基本
en-US: Basic
---
Expand All @@ -9,7 +9,7 @@ title:

最简单的用法。

## en-US
## en-US

The simplest usage.

Expand All @@ -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);
````
7 changes: 4 additions & 3 deletions components/tooltip/index.tsx
Expand Up @@ -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,
});

Expand All @@ -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>
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/tooltip/__snapshots__/demo.test.js.snap
Expand Up @@ -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>
`;

Expand Down

0 comments on commit a939769

Please sign in to comment.