From 9b5311791e73270c7c16a602ac74dd59719a5f76 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 26 Oct 2015 16:30:27 +0800 Subject: [PATCH] just hide toottip overlay when there is no title avoid rerender children when title is changed --- components/tooltip/index.jsx | 21 +++++++++++++++++++-- style/components/tooltip.less | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/components/tooltip/index.jsx b/components/tooltip/index.jsx index bffdfe605a..4844271a0b 100644 --- a/components/tooltip/index.jsx +++ b/components/tooltip/index.jsx @@ -10,6 +10,14 @@ export default React.createClass({ mouseLeaveDelay: 0.1 }; }, + getInitialState() { + return { + visible: false + }; + }, + onVisibleChange(visible) { + this.setState({ visible }); + }, render() { let transitionName = ({ top: 'zoom-down', @@ -17,12 +25,21 @@ export default React.createClass({ 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 ( - this.props.title ? {this.props.children} - : this.props.children + ); } }); diff --git a/style/components/tooltip.less b/style/components/tooltip.less index f9fc3b6471..5609bc79e6 100644 --- a/style/components/tooltip.less +++ b/style/components/tooltip.less @@ -52,6 +52,7 @@ background-color: @tooltip-bg; border-radius: @border-radius-base; box-shadow: @overlay-shadow; + min-height: 34px; } // Arrows