ant-design/components/tooltip/index.jsx
afc163 62115e9034 just hide toottip overlay when there is no title
avoid rerender children when title is changed
2015-10-26 16:30:27 +08:00

46 lines
957 B
JavaScript

import React from 'react';
import Tooltip from 'rc-tooltip';
export default React.createClass({
getDefaultProps() {
return {
prefixCls: 'ant-tooltip',
placement: 'top',
mouseEnterDelay: 0.1,
mouseLeaveDelay: 0.1
};
},
getInitialState() {
return {
visible: false
};
},
onVisibleChange(visible) {
this.setState({ visible });
},
render() {
let transitionName = ({
top: 'zoom-down',
bottom: 'zoom-up',
left: 'zoom-right',
right: 'zoom-left'
})[this.props.placement];
// Hide tooltip when there is no title
let visible = this.state.visible;
if (!this.props.title) {
visible = false;
}
return (
<Tooltip transitionName={transitionName}
overlay={this.props.title}
visible={visible}
onVisibleChange={this.onVisibleChange}
{...this.props}>
{this.props.children}
</Tooltip>
);
}
});